Arista CloudVision Portal REST API Client
cvprac is a Python client library designed to interact with the Arista CloudVision Portal (CVP) RESTful API. It simplifies API calls, handles session management, error retries, and abstracts CVP version-specific API changes, enabling easier automation and integration with CVP. The library is actively maintained, with a typical release cadence of several updates per year, and is currently at version 1.4.2.
Common errors
-
from pkg_resources import parse_version ModuleNotFoundError: No module named 'pkg_resources'
cause The `pkg_resources` module was removed from setuptools and is no longer the recommended way to parse versions. `cvprac` v1.4.0 migrated to `packaging`.fixEnsure `cvprac` version is 1.4.0 or newer. If you are using an older `cvprac` and cannot upgrade, you might need to ensure `setuptools` is installed in a version that still provides `pkg_resources` (though this is not recommended). Prefer upgrading `cvprac`. -
cvprac.cvp_client_errors.CvpLoginError: A CvpLoginError is raised if a connection could not be established to any of the nodes.
cause Incorrect CVP hostname/IP, wrong username/password/API token, protocol mismatch (e.g., trying HTTP on an HTTPS-only CVP), or network connectivity issues to the CVP instance.fixVerify CVP `nodes` list, `username`, `password`, `api_token`, and `protocol` parameters in `client.connect()`. Ensure CVP is reachable from the client machine and that API token has correct permissions. For CVaaS, confirm `is_cvaas=True` and use an API token. -
cvprac.cvp_client_errors.CvpRequestError: POST: https://.../api/v3/... : Request Error: Gateway Timeout - rpc error: code = DeadlineExceeded desc = failed to connect to service...
cause This often occurs during complex operations like Change Control execution on CVaaS, indicating network latency, CVP backend service issues, or insufficient permissions for the service account/user performing the action.fixCheck network connectivity and latency to the CVP API endpoint. Verify the assigned roles/permissions for the API token or user account being used, especially for executing tasks or change controls. For CVaaS, ensure any necessary firewall rules for egress traffic from the CVP instance are configured to reach target devices. -
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))cause A generic network connection error, often caused by CVP server instability, incorrect CVP URL, or a network device (firewall, load balancer) terminating the connection prematurely.fixDouble-check the CVP hostname/IP. Monitor CVP health. Increase connection `timeout` in `client.connect()`. `cvprac` has internal retry mechanisms, but persistent errors suggest a fundamental network or server issue.
Warnings
- breaking For CloudVision as-a-Service (CVaaS) deployments, username/password authentication was removed in `cvprac` v1.0.6/v1.2.0. Only API tokens are supported for CVaaS connections now.
- deprecated The `cvaas_token` parameter in `CvpClient.connect()` has been deprecated in favor of the more generic `api_token` parameter. While `cvaas_token` might still work for now, it will be removed in future versions.
- gotcha `cvprac` v1.4.0 explicitly updated `setup.py` to reference Python 3 only, and later versions list specific Python 3 classifiers. While it may have worked on Python 2 in very old versions, current versions are Python 3 exclusive.
- gotcha The library attempts to abstract CVP API changes across different CVP versions. However, specific API endpoints or behaviors can still change, requiring awareness of your CVP version. For example, exception handling for network provisioning APIs was added for CVP 2025.2.X+ in v1.4.2, implying older versions might not have robust error handling for these operations.
Install
-
pip install cvprac
Imports
- CvpClient
from cvprac.cvp_client import CvpClient
Quickstart
import os
from cvprac.cvp_client import CvpClient
# Environment variables for CVP connection
CVP_HOST = os.environ.get('CVP_HOST', 'your_cvp_ip_or_hostname')
CVP_API_TOKEN = os.environ.get('CVP_API_TOKEN', 'your_api_token') # For CVaaS or On-prem token-based auth
CVP_USERNAME = os.environ.get('CVP_USERNAME', '') # For On-prem username/password auth (deprecated for CVaaS)
CVP_PASSWORD = os.environ.get('CVP_PASSWORD', '') # For On-prem username/password auth (deprecated for CVaaS)
def main():
client = CvpClient()
try:
# Connect using API Token (recommended for CVaaS and newer on-prem)
if CVP_API_TOKEN and CVP_HOST != 'your_cvp_ip_or_hostname':
print(f"Attempting connection to {CVP_HOST} using API Token...")
client.connect(
nodes=[CVP_HOST],
username=CVP_USERNAME, # Can be empty if only using api_token
password=CVP_PASSWORD, # Can be empty if only using api_token
api_token=CVP_API_TOKEN,
is_cvaas=CVP_HOST.endswith('.arista.io') # Set based on hostname
)
# Fallback to username/password if no token provided (primarily for older on-prem)
elif CVP_USERNAME and CVP_PASSWORD and CVP_HOST != 'your_cvp_ip_or_hostname':
print(f"Attempting connection to {CVP_HOST} using username/password...")
client.connect(
nodes=[CVP_HOST],
username=CVP_USERNAME,
password=CVP_PASSWORD
)
else:
print("Please set CVP_HOST and either CVP_API_TOKEN or CVP_USERNAME/CVP_PASSWORD environment variables or replace placeholders.")
return
print("Successfully connected to CVP.")
cvp_info = client.api.get_cvp_info()
print(f"CVP Version: {cvp_info.get('version')}")
print(f"CVP Build: {cvp_info.get('build')}")
except Exception as e:
print(f"Error connecting or fetching info: {e}")
finally:
# It's good practice to logout to close the session
try:
if client and client.is_connected:
client.logout()
print("Logged out successfully.")
except Exception as e:
print(f"Error during logout: {e}")
if __name__ == '__main__':
main()