datacenter / pyaci Goto Github PK
View Code? Open in Web Editor NEWPython Bindings for Cisco ACI REST API
License: Apache License 2.0
Python Bindings for Cisco ACI REST API
License: Apache License 2.0
Hello,
scripts/metagen.py:
"from insieme.pymit.pyaccess import PyClassDirectory"
Is this something Cisco-internal? I can't find that package anywhere. Is it possible to add it to the repo?
Sebastian
method.GET(autoPage=True) #, **opt)
File "lib64/python3.6/site-packages/pyaci/core.py", line 1101, in GET
newKwargs = dict(pageOptions.items() + kwargs.items())
TypeError: unsupported operand type(s) for +: 'dict_items' and ‘dict_items’
I have attempted to use all the solutions provided above for getting packets, and my query is returning an empty list.
result = apic.methods.ResolveClass('acllogPermitL3Pkt').GET() result2 = apic.mit.polUni().fvTenant(tenant).GET(**options.subtreeClass('acllogPermitL3Pkt')) result3 = apic.methods.ResolveClass('acllogPermitL3Pkt').GET(**options.filter( filters.Wcard('acllogDropL3Pkt.dn', f"ndbgs/acllog/tn-{tenant}") & filters.Wcard('acllogDropL3Pkt.srcIp', "10.71.0.164"))) test = apic.mit.polUni().fvTenant(tenant).GET()
Originally posted by @the-modern-leo in #44 (comment)
APIC responds with an API link to check the post status as PD needs more time to validate
pol.POST()
File "/python3.6/site-packages/pyaci/core.py", line 92, in POST
'POST', format=format, needData=True, **kwargs)
File "//python3.6/site-packages/pyaci/core.py", line 154, in _performRequest
raise RestError(response.text)
Request in progress, please check state using URL: /api/checkRequestState.xml?id=9570149234507776
I am trying to get the lldp neighbours on an interface.
Initially I tried to do this:
lldp_neighbours = apic.methods.ResolveClass('lldpIf').GET(**options.filter(filters.Eq('lldpIf.portDesc',path.tDn)) & options.subtreeClass('lldpAdjEp') )
But this does not work and I am not getting anything back no lldpIf
nor lldpAdjEp
.
As a work around I did:
lldp_neighbours = apic.methods.ResolveClass('lldpIf').GET(**options.filter(filters.Eq('lldpIf.portDesc',path.tDn)) & options.rspSubtreeChildren )
This works fine and I can then just access the ldp_neighbour.lldpAdjEp
instance but can't understand why the first option does not work. In this case is not a big issue as there aren't that many child of lldpIf but I would like to understand how you should this be done.
PyACI doesn't distribute ACI model metadata. It instead comes with a minimal metadata for it's unit tests. User must generate full metadata by connecting to a running APIC of desired version. This is not very obvious as per some users' feedback. When PyACI is started with the minimal metadata, provide hint on how to generate the full metadata.
If I do multiple GET requests, one after another, pyaci gives errors as below. If I do either GET request by itself, it works fine. Am I doing something wrong or is this a bug?
Code:
sbm = apic.mit.polUni().fvTenant('sbm')
y = sbm.GET(**options.subtreeClass('fvAEPg'))
x = sbm.GET(**options.subtreeClass('fvSubnet'))
Error:
File "C:\Users\user\scripts\user_interaction_ipam.py", line 313, in <module>
x= sbm.GET(**options.subtreeClass('fvSubnet'))
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 579, in GET
subscriptionIds=subscriptionIds)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 544, in ParseXmlResponse
mo = self.FromDn(element.attrib['dn'])
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 392, in FromDn
return reduce(reductionF, splitIntoRns(dn), self)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 390, in reductionF
return acc._spawnChildFromRn(className, rn)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 693, in _spawnChildFromRn
return moIter(*identifierArgs)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 345, in __call__
.format(self._parentApi.Dn, rn))
pyaci.errors.MoError: Mo with DN uni/tn-sbm/ap-Ec/epg-Ec_uat_app does not contain a child with RN subnet-[10.48.11.97/28]
If I reverse the GET requests, the following happens:
File "C:\Users\user\scripts\user_interaction_ipam.py", line 306, in <module>
y = sbm.GET(**options.subtreeClass('fvAEPg'))
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 579, in GET
subscriptionIds=subscriptionIds)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 544, in ParseXmlResponse
mo = self.FromDn(element.attrib['dn'])
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 392, in FromDn
return reduce(reductionF, splitIntoRns(dn), self)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 390, in reductionF
return acc._spawnChildFromRn(className, rn)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 693, in _spawnChildFromRn
return moIter(*identifierArgs)
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\pyaci\core.py", line 345, in __call__
.format(self._parentApi.Dn, rn))
pyaci.errors.MoError: Mo with DN uni/tn-sbm does not contain a child with RN ap-legacy
The following traceback is seen if the .aci-meta directory does not exist. It would be nice if it was automatically created instead.
APIC is running version 2.2(1.79a)
Copying metagen.py to APIC
Invoking metagen.py on APIC
Copying generated meta from APIC to /Users/michsmit/.aci-meta/aci-meta.2.2(1.79a).json
Traceback (most recent call last):
File "/usr/local/bin/rmetagen.py", line 86, in <module>
main()
File "/usr/local/bin/rmetagen.py", line 66, in main
scp.get('aci-meta.json', destination)
File "/Library/Python/2.7/site-packages/scp.py", line 198, in get
self._recv_all()
File "/Library/Python/2.7/site-packages/scp.py", line 346, in _recv_all
command[code](msg[1:])
File "/Library/Python/2.7/site-packages/scp.py", line 385, in _recv_file
file_hdl = open(path, 'wb')
IOError: [Errno 2] No such file or directory: '/Users/michsmit/.aci-meta/aci-meta.2.2(1.79a).json'
APIC sessions do timeout. The timeout is indicated in the response to the login request. Track the timeout, and issue auto refresh at say about 60% of the indicated timeout.
>>> from pyaci import Node
>>> apic = Node('https://fra01-apic03.webex.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/xiaosyu/pyACI_tset/env/lib/python3.10/site-packages/pyaci/core.py", line 196, in __init__
raise MetaError('ACI meta was not specified !')
pyaci.errors.MetaError: ACI meta was not specified !
Hello,
In the file options.py, the inplementation of the method and in the class ApiOptions generates an exception in Python3. The reason for this exception is that dict_items can not be added in Py3. The alternative implementation for this method, which is Python 2 and 3 compliant (tested locally) is provided below:
class ApiOptions(dict):
def __and__(self, other):
d = self.copy()
d.update(other)
return ApiOptions(d)
Could you please apply this fix to the official code repo?
Thanks,
Sven.
How do i get an object with a direct call, and than add it's childern after?
Should look something like this:
#get a direct epg
epg_request = apic.mit.polUni().fvTenant(tenant_name).fvAp(app_name).fvAEPg(epg_name).GET()[0]
#add the childern of that EPG
epg_request.GET(**options.subtree)
Looking to get information about how to perform these queries with Pyaci. There are some information in the article below at the end of the page titled "Viewing ACL Permit and Deny Logs Using the REST API"
Here
When running something like this:
result = apic.mit.polUni().fvTenant('Enterprise').GET(**options.subtreeClass('acllogPermitL3Pkt'))
I get an empty list.
To perform the same thing in Cobra ACI would be:
result = self.cobramd.lookupByClass('acllogPermitL3Pkt')
How would i perform this action in Pyaci?
Also how would i pass in an and filters?
Something like this:
result = apic.mit.GET(**options.subtreeClass('acllogPermitL3Pkt') & options.filter(filters.Wcard('acllogDropL3Pkt.dn', f"ndbgs/acllog/tn-{tenant}" filters.Wcard('acllogDropL3Pkt.destination') & filters.Wcard('acllogDropL3Pkt.srcIp','10.71.0.164')))
WebSocket subscriptions apparently are valid for only 60 seconds. Provide a mechanism to automatically refresh subscriptions.
I may be missing something obvious in how to import this module, but it seems like it is designed to only work from the command line. I would like to import it into my application to automate the generation of the meta. Something like this:
from Scripts import rmetagen
# If an existing session wasn't supplied, make a new session
if not isinstance(apic, Node):
try:
apic = Node(config['ACI APIC']['url'])
except MetaError:
# This implies that the meta hasn't been downloaded yet
rmetagen.generateMeta(host, username, password)
Setup a proper release process, and publish PyACI to PyPI.
Currently unit tests are failing on Python 3. Most of them seem to be some kind of keys ordering assumption that was made by the test. Consult the last circleci build for more information.
In the current design, there is one version of ACI metadata loaded when the module is imported. All Node
instantiations share this global metadata. However, there have been asks from various people the ability to talk to multiple versions of ACI from the same process. This can be supported by still having a global metadata, and providing an option in the Node
to override the version.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.