Skip to content

Commit

Permalink
feat: Add hit count support for Panorama / device group rulebases (#429)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony BALITRAND <anthony.balitrand@airbus.com>

Remove NAME attribute usage on PreRulebase and PostRulebase + black reformat 

Fixes #388
  • Loading branch information
AnthoBalitrand committed Mar 29, 2022
1 parent 37ed2ca commit 057822a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions panos/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,28 @@ def refresh(self, style, rules=None, all_rules=False):

cmd = ET.Element("show")
sub = ET.SubElement(cmd, "rule-hit-count")
sub = ET.SubElement(sub, "vsys")
sub = ET.SubElement(sub, "vsys-name")
sub = ET.SubElement(sub, "entry", {"name": dev.vsys or "vsys1"})
sub = ET.SubElement(sub, "rule-base")
res_path = "./result/rule-hit-count"
rb_type_path_map = {PreRulebase: "pre-rulebase", PostRulebase: "post-rulebase"}

if dev.__class__.__name__ == "Panorama":
if self.obj.parent.__class__.__name__ == "Panorama":
sub = ET.SubElement(sub, "shared")
res_path += "/shared"
elif self.obj.parent.__class__.__name__ == "DeviceGroup":
sub = ET.SubElement(sub, "device-group")
sub = ET.SubElement(sub, "entry", {"name": self.obj.parent.name})
res_path += "/device-group/entry"
sub = ET.SubElement(sub, rb_type_path_map.get(type(self.obj)))
else:
sub = ET.SubElement(sub, "vsys")
sub = ET.SubElement(sub, "vsys-name")
sub = ET.SubElement(sub, "entry", {"name": dev.vsys or "vsys1"})
sub = ET.SubElement(sub, "rule-base")
res_path += "/vsys/entry"

sub = ET.SubElement(sub, "entry", {"name": style})
sub = ET.SubElement(sub, "rules")
res_path += "/rule-base/entry/rules/entry"

if all_rules:
ET.SubElement(sub, "all")
Expand All @@ -132,11 +148,9 @@ def refresh(self, style, rules=None, all_rules=False):
ET.SubElement(sub, "member").text = x

res = dev.op(ET.tostring(cmd, encoding="utf-8"), cmd_xml=False)

ans = {}
for elm in res.findall(
"./result/rule-hit-count/vsys/entry/rule-base/entry/rules/entry"
):

for elm in res.findall(res_path):
name = elm.attrib["name"]
for x in kids:
if x.uid == name:
Expand Down

0 comments on commit 057822a

Please sign in to comment.