Starting point for objects.AddressObject searches - pandevice

Reply
L1 Bithead

Starting point for objects.AddressObject searches - pandevice

Hello all,

 

I am trying to take it slow in regard to automation with the initial task being the identification of address objects that need to removed when a server or workstation is decommissioned. Would like to leverage python and

the pandevice module. As a start, I am trying to connect to our panorama appliance as this is where 100% of this sort of configuration held. My initial instinct is to try and find a single address object but the error

message I receive leads me to believe that the script as written is searching in the wrong location. See the "/config/shared" location. No address objects should be located there. 

 

Error:  pandevice.errors.PanObjectMissing: Object doesn't exist: /config/shared/address/entry[@name='$interestingobject$']

 

Device group hierarchy>

 

 

?shared? -- I am assuming this where the searching is happening

|

|__>on-pano

       |

       |___> fw1

       |

       |___> fw2

 

I have not been able to find a means to point the correct device-group yet and most of the documentation involves creation. Any input would be appreciated.

 

# Import supporting stuff#

import pandevice

from pandevice import panorama

from pandevice import objects

 

#Declares some stuff#

pan = '1.2.3.4'

devicegroup = 'on-pano'

 

#Connect to panorama appliance#

pano = panorama.Panorama(device, "qadmin", "qadmin")

 

#Attempt to set the device group to use with the panorama connection#

panogrp = panorama.DeviceGroup(devicegroup)

pano.add(panogrp)

 

#Define what I want to look for, in this case an host object named interestingobject"#

look4 = pandevice.objects.AddressObject(name="interestingobject")

 

#Find it#

panogrp.find(look4)

 

Thanks all!

Tags (1)

Accepted Solutions
L4 Transporter

You're close.

 

After you create the panorama object and add the device group to the panorama, you want to do refreshall(), giving the device group as the base.  So like this:

 

 

from pandevice.panorama import Panorama, DeviceGroup
from pandevice.objects import AddressObject

pano = Panorama(....)
dg = DeviceGroup(devicegroup)

pano.add(dg)

# Now get all the address objects present.
listing = AddressObject.refreshall(dg)
for obj in listing:
    print("* {0}".format(obj.about()))

 

View solution in original post


All Replies
L1 Bithead

I think I have the location search issue resolved. The basic script works but the returned data needs some work. 

------------------------------------

print(look4.about())
{'value': None, 'type': 'ip-netmask', 'description': None, 'tag': None, 'name': 'interestingobject'}

------------------------------------

Just need to figure out why the 'address' field is not included. If anyone has any input, please reply.

 

Thanks everyone. 

L1 Bithead

Well, 

 

Maybe I got ahead of myself. 

 

No matter what object I search for; no errors are presented but the object has no value (or appears to have none) or blanks values. The name is know but that does not seem to matter much. Any input into what might be happening? Is the search bad or am I just looking at the returned info in the wrong?

 

print(look4._about_object())
{'value': None, 'type': 'ip-netmask', 'description': None, 'tag': None, 'name': 'interestingobject'}

 

Thank you all!

L4 Transporter

You're close.

 

After you create the panorama object and add the device group to the panorama, you want to do refreshall(), giving the device group as the base.  So like this:

 

 

from pandevice.panorama import Panorama, DeviceGroup
from pandevice.objects import AddressObject

pano = Panorama(....)
dg = DeviceGroup(devicegroup)

pano.add(dg)

# Now get all the address objects present.
listing = AddressObject.refreshall(dg)
for obj in listing:
    print("* {0}".format(obj.about()))

 

View solution in original post

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!