This commit is contained in:
@@ -62,6 +62,18 @@ class NftManager:
|
||||
return json.loads(out)
|
||||
except json.JSONDecodeError as 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:
|
||||
"""
|
||||
@@ -696,6 +708,8 @@ def list_rules():
|
||||
try:
|
||||
try:
|
||||
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:
|
||||
logger.debug("could not obtain nft JSON ruleset: %s", e)
|
||||
text = mgr.list_rules_json()
|
||||
|
||||
Reference in New Issue
Block a user