Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79142
| 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 | <nickolas.ellson@gmail.com> |
| 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 <nickolas.ellson@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14876.1413361076.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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
<snip>
xapi.op(cmd='show devices connected', cmd_xml=True )
MyDict=xapi.xml_python()
print (type(MyDict))
print (MyDict)
<snip>
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
<class 'dict'>
{'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:
<ip>
<ip>
<ip>
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Help with parsing a dict from Vendor's API? Nick Ellson <nickolas.ellson@gmail.com> - 2014-10-14 13:21 -0700
csiph-web