Skip to main content

aci communication helper class

Project description

aciClient

PyPi

A python wrapper to the Cisco ACI REST-API.

Python Version

We support Python 3.6 and up. Python 2 is not supported and there is no plan to add support for it.

Installation

pip install aciClient

Installation for Developing

git clone https://github.com/netcloud/aciclient.git
pip install -r requirements.txt
python setup.py develop

Usage

Initialisation

Username/password

import aciClient
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=False)
try:
    aciclient.login()
    
    aciclient.getJson(uri)
    aciclient.postJson(config)
    aciclient.deleteMo(dn)
    
    aciclient.logout()
except Exception as e:
    logger.exception("Stack Trace")

For automatic authentication token refresh you can set variable refresh to True

aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=True)    

Certificate/signature

import aciClient
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

aciclient = aciClient.ACICert(apic_hostname, path_to_privatekey_file, certificate_dn)

try:
    aciclient.getJson(uri)
    aciclient.postJson(config)
    aciclient.deleteMo(dn)
except Exception as e:
    logger.exception("Stack Trace")

Examples

get config

tenants = aciclient.getJson('class/fvTenant.json?order-by=fvTenant.dn|asc')

for mo in tenants:
    print(f'tenant DN: {mo["fvTenant"]["attributes"]["dn"]}')

post config

config = {
 "fvTenant": {
  "attributes": {
   "dn": "uni/tn-XYZ"
  }
 }
}

aciclient.postJson(config)

delete MOs

aciclient.deleteMo('uni/tn-XYZ')

create snapshot

You can specify a tenant in variable target_dn or not provide any to do a fabric-wide snapshot.

aci.snapshot(description='test', target_dn='/uni/tn-test')

Subscriptions

You can subscribe to an ACI object with websocket and get near-instant updates on-change.
To use the subscriptions you have to:

  • Login to ACI
  • Open websocket to ACI
  • Subscribe to an ACI object via aciClient.subscribe
  • Refresh subscription to an ACI object via aciClient.subscription_refresh
  • Handle messages sent from ACI through websocket

You can find example code here: examples/subscription.py

Testing

pip install -r requirements.txt
python -m pytest

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to this project.

Authors

  • Marcel Zehnder - Initial work
  • Andreas Graber - Migration to open source
  • Richard Strnad - Paginagtion for large requests, various small stuff
  • Dario Kaelin - Added snapshot creation

License

This project is licensed under MIT - see the LICENSE.md file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aciClient-1.6.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file aciClient-1.6.tar.gz.

File metadata

  • Download URL: aciClient-1.6.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.7

File hashes

Hashes for aciClient-1.6.tar.gz
Algorithm Hash digest
SHA256 7235e72a8863bb5be00953a851ef68a14f1cd46212dc9d78ba07b0b1139b76a3
MD5 d2886c135de512611ced9ec35a97992d
BLAKE2b-256 00fac16c1387062855f5b0bb1ed6d42a116f08ce1fff87b21c39286d5c25fd5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page