A Python API Client for Nvidia Cumulus
Project description
py-nvidia-cumulus
Unofficial Python API client for Nvidia Cumulus Linux.
Installation
To install the package, run the following command:
pip install py-nvidia-cumulus
Quick Start
To start using the client, instantiate the Cumulus class with the host and authentication details
from cumulus import Cumulus
nv = Cumulus(
url="https://127.0.0.1:8765",
auth=("cumulus", "password")
)
# nv.http_session = requests.Session() # set your own session if necessary
nv.http_session.verify = False # disable SSL verification if necessary
The client aims to provide a thin wrapper over the Cumulus OpenAPI specification.
Therefore, it abstracts endpoints in pythonic fashion.
Examples
- Get the IP address of an interface relative to the OpenAPI endpoint
# Instantiate the Cumulus class first
loopback = nv.interface.get('lo/ip/address')
print(loopback) # {'127.0.0.1/8': {}, '::1/128': {}}
- Update interface configuration relative to the OpenAPI endpoint:
# Instantiate the Cumulus class first
nv.revision.create() # create a revision
# patch an interface by provisiong the created revision ID, new data, and path to the object
nv.interface.patch(rev=nv.revision.rev,
data={"10.255.255.2/32": {}},
target_path="lo/ip/address")
nv.revision.apply() # apply the changes
nv.revision.is_applied() # watch the switch to make sure the changes were applied successfully
- Here is a more complex example on how to deploy the entire switch configuration using the
rootendpoint. We will also see how to get the diff between the current revision and the one we are applying.
from cumulus import Cumulus
configuration = {"key": "value"}
nv = Cumulus(
url="https://127.0.0.1:8765",
auth=("cumulus", "password")
)
nv.http_session.verify = False # by default the switch uses self-signed certificate
nv.revision.create()
# remove previous configuration completely.
# Otherwise, only new keys will be applied and old ones won't be removed
nv.root.delete(nv.revision.rev)
nv.root.patch(rev=nv.revision.rev, data=configuration)
# see the changes between the current and pending revisions
print(nv.root.diff(nv.revision.rev))
nv.revision.apply()
# check switch status for 3 minutes
nv.revision.is_applied(retries=180)
# update revision to get the success/error message
nv.revision.refresh()
print(nv.revision.config)
- Due to the very dynamic nature of Nvidia Cumulus API, there may not always be a model to cover the endpoint you want to use. Adding your own model is very simple.
from cumulus import Cumulus
from cumulus.models import BaseModel
nv = Cumulus(
url="https://127.0.0.1:8765",
auth=("cumulus", "password")
)
programming = BaseModel(client=nv, endpoint="system/forwarding/programming")
print(programming.get(endpoint_params={"rev": "applied"}))
Tests
To execute a set of unit tests, run the following command in the root of the project
make test
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_nvidia_cumulus-0.0.3.tar.gz.
File metadata
- Download URL: py_nvidia_cumulus-0.0.3.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3619ea738fd60769ff4d97ddacfc5f1893487c3d62a5f69acadcb22d59645107
|
|
| MD5 |
921dd3fa0e43605b0394f6a31fcc995b
|
|
| BLAKE2b-256 |
eb4ce28da110cd99b6d5737d7a5260ee9f7cc888babf35b76ae768bce55abfd6
|
File details
Details for the file py_nvidia_cumulus-0.0.3-py3-none-any.whl.
File metadata
- Download URL: py_nvidia_cumulus-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2871bdb3459be8df74c0e6f84365fbfca9004fab62dbb7a935a91ae84be6eeba
|
|
| MD5 |
6ecda2e688edc2e93161044417adabab
|
|
| BLAKE2b-256 |
059f7980ba76d793e0555ba2de404e85a92f07c2df489fbb18f11bb1b8ba6fc3
|