Panorama with pan-os-python API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

Panorama with pan-os-python API

L0 Member

Hi,

 

I have three firewalls added to a device group in Panorama. I am accessing Panorama via pan-os-python API and from there I want to fetch some device group "MyDG" and then delete one of the firewalls from panorama based on the hostname of the firewall. I can see the hostnames set/configured in Panorama > Managed Devices > Summary in the GUI but when I try to fetch the information for any of my firewall devices via Panorama object through the API I get this error about hostname. I have tried other methods for this "fw0" object too and it throws the same error. Probably I am missing something.

 

Can someone pls guide what am I doing wrong or is it some bug?

 

>>> pano
<Panorama 202.24.62.93 0x10adc3d30>
>>> devices = pano.refresh_devices(include_device_groups=False)
>>> devices
[<Firewall '007955000319973' 'vsys1' at 0x10ad29180>, <Firewall '007955000319994' 'vsys1' at 0x10ad2bca0>, <Firewall '007955000399952' 'vsys1' at 0x10a5af640>]
>>> fw0 = devices[0]
>>> fw0.serial
'007955000319973'
>>> fw0.refresh()
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/panos/firewall.py", line 253, in generate_xapi
    self.panorama()
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 1132, in panorama
    raise err.PanDeviceNotSet("No Panorama set for object tree")
panos.errors.PanDeviceNotSet: No Panorama set for object tree

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 901, in refresh
    xml = self._refresh_xml(running_config, exceptions, refresh_children)
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 1053, in _refresh_xml
    api_action = dev.xapi.show if running_config else dev.xapi.get
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 4000, in xapi
    self._xapi_private = self.generate_xapi()
  File "/usr/local/lib/python3.10/site-packages/panos/firewall.py", line 255, in generate_xapi
    return super(Firewall, self).generate_xapi()
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 4072, in generate_xapi
    "api_key": self.api_key,
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 3994, in api_key
    self._api_key = self._retrieve_api_key()
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 4151, in _retrieve_api_key
    xapi = PanDevice.XapiWrapper(
  File "/usr/local/lib/python3.10/site-packages/panos/base.py", line 3776, in __init__
    pan.xapi.PanXapi.__init__(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pan/xapi.py", line 178, in __init__
    raise PanXapiError('hostname argument required')
pan.xapi.PanXapiError: hostname argument required
>>>

 

1 REPLY 1

L1 Bithead

 

Have you tried adding the Firewall object to the Panorama object?

 

Order of operations here:

  1. create an object to represent our Panorama instance connection
  2. use this Panorama object to retrieve a list of our devices, storing them in a list
  3. select the correct index for your firewall within this list
  4. add the Firewall object to the Panorama object as a child
  5. execute your refresh method on the firewall object

You had all but the 4th step, as the error message presented:

panos.errors.PanDeviceNotSet: No Panorama set for object tree

 

Here is an example output:

exampleexample

Let me know if you're still running into an issue,

 

Calvin

 

  • 1761 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!