File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -29,15 +29,26 @@ def get_customized_nftables() -> Nftables:
29
29
30
30
def execute_json_nft_commands (commands : list [dict ]) -> dict :
31
31
"""Executes a list of nftables commands and returns the json output"""
32
+ if not commands :
33
+ return {}
32
34
nft = get_customized_nftables ()
35
+
33
36
commands_dict = {"nftables" : commands }
34
37
try :
35
38
logger .debug ("Validating nftables rules" )
36
39
nft .json_validate (commands_dict )
37
40
except Exception as e :
38
41
logger .error (f"Failed to verify nftables rules: { e } " )
39
42
40
- logger .debug ("Inserting nftables rules" )
43
+ def _format_command_for_debug ():
44
+ l = []
45
+ for c in commands :
46
+ for command_name , entity in c .items ():
47
+ for entity_type , entity_args in entity .items ():
48
+ l .append (f"{ command_name } { entity_type } { entity_args .get ('name' , '' )} " )
49
+ return ", " .join (l )
50
+
51
+ logger .debug ("Nftables commands: %s" , _format_command_for_debug ())
41
52
return_code , output , error = nft .json_cmd (commands_dict )
42
53
if return_code != 0 :
43
54
logger .error ("Failed to add nftables rules: %s -- %s" , error , json .dumps (commands , indent = 4 ))
You can’t perform that action at this time.
0 commit comments