You could do something along the lines of
# Constants
netowrk_id = "xxxx"
TargetComment = "Google DNS"
# Get Rules for network
FirewallRules = dashboard.appliance.getNetworkApplianceFirewallL3FirewallRules(network_id)
# Determine idx where rule should be updated
target_idx = next((idx for idx, item in enumerate(FirewallRules['rules']) if item['comment'] == TargetComment), None)
# Update rule
FirewallRules['rules'][target_idx].update({
"comment": TargetComment
"policy": "deny",
"protocol": "any",
"destPort": "any",
"destCidr": "192.200.1.0/24",
"srcPort": "Any",
"srcCidr": "Any",
"syslogEnabled": false
})
# Remove Default Rule entry
FirewallRules['rules'].pop(-1)
# Update Rules
NewSetOfRules = dashboard.appliance.updateNetworkApplianceFirewallL3FirewallRules(
networkId=network_id,
rules=FirewallRules['rules']
)
What happens is, that I search through all the elements in FirewallRules for the index of the element with the comment, of the rule I wan't to update.
With the index in hand, I can either update the rule, or use the index to inject a new rule. In the above example I use it to update a specific rule.
Modify it to suit your implementation.
LinkedIn :::
https://blog.rhbirkelund.dk/Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution
🙂All code examples are provided as is. Responsibility for Code execution lies solely your own.