PaloAltoNetworks / pan-os-python

The PAN-OS SDK for Python is a package to help interact with Palo Alto Networks devices (including physical and virtualized Next-generation Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics the traditional interaction with the device via the GUI or CLI/API.
https://pan-os-python.readthedocs.io
ISC License
339 stars 166 forks source link

Use of TemplateVariable for 'Group ID' causes an error due to it being converted to an int() during parse_xml #523

Open rebelfish opened 10 months ago

rebelfish commented 10 months ago

Describe the bug

I attempt Template.refreshall(pano) which fails because a Template is making use of a 'Group ID' template value of '$groupID'. pan-os-python attempts to convert the value to int() during parse_xml.

Expected behavior

I would expect a condition of str(elm.text) if elm.text.startswith('$') else int(elm.text)

Current behavior

Traceback (most recent call last):
  File "<pyshell#157>", line 1, in <module>
    Template.refreshall(pano)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1338, in refreshall
    instances = class_instance.refreshall_from_xml(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1404, in refreshall_from_xml
    instance._refresh_children(xml=obj)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1038, in _refresh_children
    l = child.refreshall_from_xml(childroot)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 1389, in refreshall_from_xml
    instance.parse_xml(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 2789, in parse_xml
    var_path.parse_xml(xml, settings, possibilities)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 3223, in parse_xml
    self.parse_value_from_xml_last_tag(e, settings, attr)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/panos/base.py", line 3306, in parse_value_from_xml_last_tag
    settings[self.param] = int(elm.text)
ValueError: invalid literal for int() with base 10: '$groupID'

Possible solution

Use of a conditional statement such as settings[self.param] = str(elm.text) if elm.text.startswith('$') else int(elm.text)

Steps to reproduce

  1. Define a template variable for $groupID
  2. Assign the $groupID to Template>Device>High Availability>Setup>Group ID
  3. Template.refreshall(pano) from a pan-os-python script

Screenshots

Context

Your Environment