How to handle the element provided by operation command in python

Reply
L2 Linker

How to handle the element provided by operation command in python

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. 


Accepted Solutions
Highlighted
L4 Transporter

Re: How to handle the element provided by operation command in python

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


All Replies
Highlighted
L4 Transporter

Re: How to handle the element provided by operation command in python

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

Highlighted
L2 Linker

Re: How to handle the element provided by operation command in python

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!!!

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 Live Community as a whole!

The Live Community thanks you for your participation!