This commit is contained in:
@@ -63,6 +63,18 @@ class NftManager:
|
|||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
raise NftError(f"json decode error: {e}")
|
raise NftError(f"json decode error: {e}")
|
||||||
|
|
||||||
|
def list_rules_text(self) -> str:
|
||||||
|
"""
|
||||||
|
Obtain nft list ruleset in textual form. This is a fallback if JSON parsing fails.
|
||||||
|
Returns raw textual output on success, raises NftError on failure.
|
||||||
|
"""
|
||||||
|
self.nft.set_json_output(False) # best-effort attempt to disable JSON output
|
||||||
|
res = self.cmd("list ruleset")
|
||||||
|
self.nft.set_json_output(True) # restore JSON output preference
|
||||||
|
if res["rc"] != 0:
|
||||||
|
raise NftError(f"nft list ruleset failed: {res['stderr']}")
|
||||||
|
return res["stdout"] or ""
|
||||||
|
|
||||||
def list_chain_text(self, family: str, table: str, chain: str) -> str:
|
def list_chain_text(self, family: str, table: str, chain: str) -> str:
|
||||||
"""
|
"""
|
||||||
Return textual output of `nft list chain <family> <table> <chain>`.
|
Return textual output of `nft list chain <family> <table> <chain>`.
|
||||||
@@ -696,6 +708,8 @@ def list_rules():
|
|||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
nft_json = mgr.list_rules_json()
|
nft_json = mgr.list_rules_json()
|
||||||
|
nft_text = mgr.list_rules_text()
|
||||||
|
logger.error("Successfully obtained nft JSON ruleset, but also got textual output: %r", nft_text)
|
||||||
except NftError as e:
|
except NftError as e:
|
||||||
logger.debug("could not obtain nft JSON ruleset: %s", e)
|
logger.debug("could not obtain nft JSON ruleset: %s", e)
|
||||||
text = mgr.list_rules_json()
|
text = mgr.list_rules_json()
|
||||||
|
|||||||
Reference in New Issue
Block a user