kevinsteves / pan-python

Multi-tool set for Palo Alto Networks PAN-OS, Panorama, WildFire and AutoFocus
Other
267 stars 102 forks source link

Show and Get only show None #30

Closed netexgb closed 5 years ago

netexgb commented 5 years ago

I have used the script as follows, using the Python interpreter:

from pan.xapi import PanXapi

The virtual router is already configured, the aim is to add a static route to it

xpath = "/config/devices/entry[@name='localhost.localdomain']/network/virtual-router/entry[@name='VR-Route']/routing-table/ip/static-route/entry[@name='8.8.8.8n32']" element = "8.8.8.8/32ethernet1/210.0.4.1"

.panrc was configured previously so admin user credentials reside in the directory

where I aim to run this program

xapi = PanXapi(tag=None, use_get=True) xapi.set(xpath=xpath,element=element) print(xapi.status) 'success'

Even though I have verified the configuration being configured, it only shows the following:

print(xapi.get(xpath=xpath)) None xapi.commit(cmd="", sync=True, interval=1, timeout=0) xapi.status 'success' print(xapi.show(xpath=xpath)) None

Then I delete the configuration and try to show or get and get an error (which I should get, so this part works)

xapi.delete(xpath=xpath) print(xapi.status) success xapi.commit(cmd="", sync=True, interval=1, timeout=0) print(xapi.show(xpath=xpath)) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.7/site-packages/pan/xapi.py", line 721, in show self.type_config('show', query, extra_qs) File "/usr/lib/python3.7/site-packages/pan/xapi.py", line 805, in type_config raise PanXapiError(self.status_detail) pan.xapi.PanXapiError: No such node

There is some if that return None all the time even if the element has been configured. I have verified the configuration using panxapi.py right after commiting the changes:

  1. when setting the static route: PS C:\Users\GBloise\Repositories\SINet Cloud Infrastructure\libraries> python panxapi.py -js $xpath show: success { "response": { "result": { "entry": [ { "destination": "8.8.8.8/32", "interface": "ethernet1/2", "name": "8.8.8.8n32", "nexthop": { "ip-address": "10.0.4.1" } } ] }, "status": "success" } }
  2. When deleting the static route: PS C:\Users\GBloise\Repositories\SINet Cloud Infrastructure\libraries> python panxapi.py -js $xpath show: error: "No such node" { "response": { "msg": { "line": "No such node" }, "status": "error" }
kevinsteves commented 5 years ago

You should do:

xapi.get(xpath=xpath) print(xapi.xml_result())

for example. The get() and show() methods do not return anything, resulting in the None.