How to handle the element provided by operation command in python

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

How to handle the element provided by operation command in python

L2 Linker

Hi, 

 

I have this little script, the idea is show in the console all address that I have in the running config. 

image.png

 

But,  when I work with the xml element. the print  not show the addresses. 

 

This is the result or rest api. to operation command "show config running"

 

image.png

I need to extract from xml the name object and ip-netmask. 

1 accepted solution

Accepted Solutions

L5 Sessionator

Seems like you're using pandevice to do the op() call?  If so, this is better since there is an object for address objects:

 

 

from pandevice.objects import AddressObject

listing = AddressObject.refreshall(fw)

for obj in listing:
  if obj.type != 'ip-netmask':
    continue
  print('Name: {0}) | ip-netmask: {1}'.format(obj.name, obj.value))

 

 

If you really wanted to do "'show config running" to get the answer, your xpath search is wrong.  It should be ./result/config/devices/entry[@name='vsys1']/address/entry.  At that location, the name is an attribute, and ip-netmask may or may not be there, so using find() is ok.

 

View solution in original post

2 REPLIES 2

L5 Sessionator

Seems like you're using pandevice to do the op() call?  If so, this is better since there is an object for address objects:

 

 

from pandevice.objects import AddressObject

listing = AddressObject.refreshall(fw)

for obj in listing:
  if obj.type != 'ip-netmask':
    continue
  print('Name: {0}) | ip-netmask: {1}'.format(obj.name, obj.value))

 

 

If you really wanted to do "'show config running" to get the answer, your xpath search is wrong.  It should be ./result/config/devices/entry[@name='vsys1']/address/entry.  At that location, the name is an attribute, and ip-netmask may or may not be there, so using find() is ok.

 

Thank you so much!!!. I'm creating a script to get all object and compare to see the duplicates and take that info to perform a clean up in the firewall.

 

Again thanks a lot!!!

  • 1 accepted solution
  • 3476 Views
  • 2 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!