Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'tutorial': 0.03; 'output': 0.05; 'true,': 0.05; 'none,': 0.07; 'puts': 0.07; "'name':": 0.09; 'executes': 0.09; 'false,': 0.09; 'structure,': 0.09; 'subject:parsing': 0.09; 'teh': 0.09; 'tutorials,': 0.09; 'api': 0.11; 'subject:Help': 0.11; 'python': 0.11; '(palo': 0.16; ':-d': 0.16; 'dict': 0.16; 'dump': 0.16; 'list"': 0.16; 'nick': 0.16; 'palo': 0.16; 'skip:) 30': 0.16; 'stepping': 0.16; 'subject:API': 0.16; 'index': 0.16; ':-)': 0.16; 'looked': 0.18; "skip:' 30": 0.19; 'slightly': 0.19; 'seems': 0.21; 'command': 0.22; 'example': 0.22; 'print': 0.22; 'days,': 0.24; 'parse': 0.24; 'simpler': 0.24; 'question': 0.24; 'task': 0.26; 'tried': 0.27; 'correct': 0.29; 'rest': 0.29; '(this': 0.29; 'xml': 0.29; 'related': 0.29; 'list:': 0.30; 'reaches': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'easier': 0.31; "skip:' 10": 0.31; 'firewall': 0.31; "skip:' 40": 0.31; 'probably': 0.32; 'another': 0.32; 'skip:& 30': 0.33; 'maybe': 0.34; 'subject:from': 0.34; 'subject:with': 0.35; 'tool': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'easily': 0.37; 'skip:& 10': 0.38; 'manager': 0.38; 'displays': 0.38; 'skip:. 20': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'ability': 0.39; 'skip:& 20': 0.39; 'does': 0.39; 'structure': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'devices': 0.61; 'field.': 0.61; 'new': 0.61; 'simple': 0.61; 'information': 0.63; '8bit%:10': 0.64; 'central': 0.64; 'management': 0.65; 'world': 0.66; 'here': 0.66; '180': 0.84; 'a/v': 0.84; 'alto': 0.84; 'appreciative': 0.84; 'believe,': 0.84; 'dict.': 0.84; 'firewalls': 0.84; 'grabbing': 0.84; 'outsourced': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=zeIrOtMkkubDIjDlrM7XqXv/0XjXMGOJ5FYENbIJHPo=; b=HSMiePIZ2eUmLy/jG8bRNfrS+gIU4lreXa9KWIdeRGtauGKy28Ih5rRocN0fPzMpxc tMGwZHv8x0EDOXklqPcf5RcMBog1t1bunk+eB6VGxpMPbPhBEBCIPrvH485diHn2Gbz9 CmH2N+gWEY9CCvnYtgYktm6fO6pDAPuey0m3plBG0k4HqX3umfZSF5vDNZIzEbt2S7D5 vSNopdgxTD9Vgh9F86nG00BfIYFvmajqOkqdmsseqNrBiIaRHaj00I8U1ALTg2D40FEc TD7qiYti0BXxJwE0fQapU40lm7sOAW9Si65/3P+fx6uPWlOeah5ffZP4ANhN8IlDkP/T na4w== MIME-Version: 1.0 X-Received: by 10.180.74.7 with SMTP id p7mr7762438wiv.48.1413318074785; Tue, 14 Oct 2014 13:21:14 -0700 (PDT) Date: Tue, 14 Oct 2014 13:21:14 -0700 Subject: Help with parsing a dict from Vendor's API? From: Nick Ellson To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d043c81f0cd68ea050567c1a2 X-Mailman-Approved-At: Wed, 15 Oct 2014 10:17:54 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 139 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413361076 news.xs4all.nl 2949 [2001:888:2000:d::a6]:58530 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79142 --f46d043c81f0cd68ea050567c1a2 Content-Type: text/plain; charset=UTF-8 Hello! I have a very specific question related to the output of a Vendors API (Palo Alto Networks "pan.xapi" and how I might farm data from this output. I am new to python, doing well in the tutorials, but this is an automation task at work and I know the rest will be much easier once i get past the ability to read this dict. The code reaches in to the central Palo Alto firewall manager (Panorama) and executes a simple command to return all of the information for each of the managed firewalls in the field. It captured this output in XML I believe, but has the ability to return it in python dict format too, which looked like probably the best format to use. Here is the test I tried xapi.op(cmd='show devices connected', cmd_xml=True ) MyDict=xapi.xml_python() print (type(MyDict)) print (MyDict) and I get: (This displays only 2 firewalls of the 180, so you can see the structure, and that python does say it is a "dict") bertha bin # ./test.py {'response': {'result': {'devices': {'entry': [{'av-version': '1391-1863', 'unsupported-version': False, 'ip-address': '1.8.2.8', 'sw-version': '4.1.9', 'vsys': {'entry': [{'name': 'vsys1', 'shared-policy-md5sum': '8a8dcd146e24bd750ae571059bc09210', 'shared-policy-status': None, 'display-name': 'vsys1'}]}, 'uptime': '350 days, 14:29:49', 'threat-version': '460-2394', 'operational-mode': 'normal', 'multi-vsys': False, 'global-protect-client-package-version': '0.0.0', 'app-version': '460-2394', 'model': 'PA-200', 'connected': True, 'name': '001606000002', 'family': '200', 'url-filtering-version': '4390', 'vpn-disable-mode': False, 'logdb-version': '4.1.2', 'serial': '001606000002', 'hostname': 'bob-int-fw'}, {'av-version': '1391-1863', 'unsupported-version': False, 'ip-address': '1.9.8.8', 'sw-version': '4.1.9', 'vsys': {'entry': [{'name': 'vsys1', 'shared-policy-md5sum': '8a8dcd146e24bd750ae571059bc09210', 'shared-policy-status': None, 'display-name': 'vsys1'}]}, 'uptime': '358 days, 0:03:20', 'threat-version': '460-2394', 'operational-mode': 'normal', 'multi-vsys': False, 'global-protect-client-package-version': '0.0.0', 'app-version': '460-2394', 'model': 'PA-200', 'connected': True, 'name': '001606000009', 'family': '200', 'url-filtering-version': '4390', 'vpn-disable-mode': False, 'logdb-version': '4.1.2', 'serial': '001606008639', 'hostname': 'bib-int-fw'}, <****repeats for 180 firewalls****> ]}}, 'status': 'success'}} What I want is to parse through each firewall grabbing the "ip-address" value so that I can dump it to a list: For use in another network management tool so I don't rely on outsourced help to remember to place teh firewalls into the correct tools. But dang if every dict tutorial seems to deal with slightly simpler looking structures than what this puts out. I would be very appreciative with help stepping out of the 6 line "address book/grocery list" example world for a taste of something useful :-) Maybe to a Python coder, it maybe a simple even be able to randomly reference a firewall index number and teh value in this structure so one can easily just pluck any A/V pair at will.. just not for me yet :-D Nick --f46d043c81f0cd68ea050567c1a2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello!=C2=A0

I have a very specific que= stion related to the output of a Vendors API (Palo Alto Networks "pan.= xapi" and how I might farm data from this output. I am new to python, = doing well in the tutorials, but this is an automation task at work and I k= now the rest will be much easier once i get past the ability to read this d= ict.

The code reaches in to the central Palo Alto = firewall manager (Panorama) and executes a simple command to return all of = the information for each of the managed firewalls in the field. It captured= this output in XML I believe, but has the ability to return it in python d= ict format too, which looked like probably the best format to use. Here is = the test I tried

<snip>=C2=A0
xapi.op(cmd=3D'show devices connected', cmd_xml=3DTrue )
MyDict=3Dxapi.xml_python()
print (type(MyDict))
<= div>print (MyDict)
<snip>

and I ge= t: (This displays only 2 firewalls of the 180, so you can see the structure= , and that python does say it is a "dict")

bertha bin # ./test.py=C2=A0
<class 'dict'>=
{'response': {'result': {'devices': {= 9;entry': [{'av-version': '1391-1863', 'unsupported= -version': False, 'ip-address': '1.8.2.8', 'sw-vers= ion': '4.1.9', 'vsys': {'entry': [{'name= 9;: 'vsys1', 'shared-policy-md5sum': '8a8dcd146e24bd750= ae571059bc09210', 'shared-policy-status': None, 'display-na= me': 'vsys1'}]}, 'uptime': '350 days, 14:29:49'= , 'threat-version': '460-2394', 'operational-mode':= 'normal', 'multi-vsys': False, 'global-protect-client-= package-version': '0.0.0', 'app-version': '460-2394= ', 'model': 'PA-200', 'connected': True, 'n= ame': '001606000002', 'family': '200', 'url= -filtering-version': '4390', 'vpn-disable-mode': False,= 'logdb-version': '4.1.2', 'serial': '001606000= 002', 'hostname': 'bob-int-fw'}, {'av-version':= '1391-1863', 'unsupported-version': False, 'ip-address= ': '1.9.8.8', 'sw-version': '4.1.9', 'vsys&= #39;: {'entry': [{'name': 'vsys1', 'shared-poli= cy-md5sum': '8a8dcd146e24bd750ae571059bc09210', 'shared-pol= icy-status': None, 'display-name': 'vsys1'}]}, 'upt= ime': '358 days, 0:03:20', 'threat-version': '460-2= 394', 'operational-mode': 'normal', 'multi-vsys'= ;: False, 'global-protect-client-package-version': '0.0.0',= 'app-version': '460-2394', 'model': 'PA-200= 9;, 'connected': True, 'name': '001606000009', '= ;family': '200', 'url-filtering-version': '4390'= ;, 'vpn-disable-mode': False, 'logdb-version': '4.1.2&#= 39;, 'serial': '001606008639', 'hostname': 'bib= -int-fw'}, <****repeats for 180 firewalls****> ]}}, 'status&#= 39;: 'success'}}


What= I want is to parse through each firewall grabbing the "ip-address&quo= t; value so that I can dump it to a list:

<ip&g= t;
<ip>
<ip>

For u= se in another network management tool so I don't rely on outsourced hel= p to remember to place teh firewalls into the correct tools.
=
But dang if every dict tutorial seems to deal with slightly = simpler looking structures than what this puts out. I would be very appreci= ative with help stepping out of the 6 line "address book/grocery list&= quot; example world for a taste of something useful :-)

Maybe to a Python coder, it maybe a simple even be able to randomly r= eference a firewall index number and teh value in this structure so one can= easily just pluck any A/V pair at will.. just not for me yet :-D

Nick

--f46d043c81f0cd68ea050567c1a2--