Starting point for objects.AddressObject searches - pandevice

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Starting point for objects.AddressObject searches - pandevice

L1 Bithead

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!

1 accepted solution

Accepted Solutions

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

5 REPLIES 5

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. 

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!

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()))

 

The value(address) is None. It looks like the object is not found. I also have the same problem. I don't think it is searching "Shared" address object.   

The value(address) is None. It looks like the object is not found. I also have the same problem. I don't think it is searching "Shared" address object.   

  • 1 accepted solution
  • 6555 Views
  • 5 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!