{"id":8918,"library":"cvprac","title":"Arista CloudVision Portal REST API Client","description":"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.","status":"active","version":"1.4.2","language":"en","source_language":"en","source_url":"https://github.com/aristanetworks/cvprac","tags":["networking","arista","cloudvision","cvp","rest-api","automation"],"install":[{"cmd":"pip install cvprac","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for making HTTP requests to the CVP API.","package":"requests","optional":false},{"reason":"Used internally for parsing and comparing version numbers, particularly for CVP version handling.","package":"packaging","optional":false}],"imports":[{"symbol":"CvpClient","correct":"from cvprac.cvp_client import CvpClient"}],"quickstart":{"code":"import os\nfrom cvprac.cvp_client import CvpClient\n\n# Environment variables for CVP connection\nCVP_HOST = os.environ.get('CVP_HOST', 'your_cvp_ip_or_hostname')\nCVP_API_TOKEN = os.environ.get('CVP_API_TOKEN', 'your_api_token') # For CVaaS or On-prem token-based auth\nCVP_USERNAME = os.environ.get('CVP_USERNAME', '') # For On-prem username/password auth (deprecated for CVaaS)\nCVP_PASSWORD = os.environ.get('CVP_PASSWORD', '') # For On-prem username/password auth (deprecated for CVaaS)\n\ndef main():\n    client = CvpClient()\n    try:\n        # Connect using API Token (recommended for CVaaS and newer on-prem)\n        if CVP_API_TOKEN and CVP_HOST != 'your_cvp_ip_or_hostname':\n            print(f\"Attempting connection to {CVP_HOST} using API Token...\")\n            client.connect(\n                nodes=[CVP_HOST],\n                username=CVP_USERNAME, # Can be empty if only using api_token\n                password=CVP_PASSWORD, # Can be empty if only using api_token\n                api_token=CVP_API_TOKEN,\n                is_cvaas=CVP_HOST.endswith('.arista.io') # Set based on hostname\n            )\n        # Fallback to username/password if no token provided (primarily for older on-prem)\n        elif CVP_USERNAME and CVP_PASSWORD and CVP_HOST != 'your_cvp_ip_or_hostname':\n            print(f\"Attempting connection to {CVP_HOST} using username/password...\")\n            client.connect(\n                nodes=[CVP_HOST],\n                username=CVP_USERNAME,\n                password=CVP_PASSWORD\n            )\n        else:\n            print(\"Please set CVP_HOST and either CVP_API_TOKEN or CVP_USERNAME/CVP_PASSWORD environment variables or replace placeholders.\")\n            return\n\n        print(\"Successfully connected to CVP.\")\n        cvp_info = client.api.get_cvp_info()\n        print(f\"CVP Version: {cvp_info.get('version')}\")\n        print(f\"CVP Build: {cvp_info.get('build')}\")\n\n    except Exception as e:\n        print(f\"Error connecting or fetching info: {e}\")\n    finally:\n        # It's good practice to logout to close the session\n        try:\n            if client and client.is_connected:\n                client.logout()\n                print(\"Logged out successfully.\")\n        except Exception as e:\n            print(f\"Error during logout: {e}\")\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates how to establish a connection to an Arista CloudVision Portal (CVP) instance using `cvprac.CvpClient`. It prioritizes API token authentication, suitable for both CloudVision as-a-Service (CVaaS) and on-prem deployments, falling back to username/password for older on-prem setups. It then fetches and prints basic CVP information. Ensure `CVP_HOST` and either `CVP_API_TOKEN` or `CVP_USERNAME`/`CVP_PASSWORD` environment variables are set."},"warnings":[{"fix":"Migrate to API token-based authentication. Ensure `api_token` parameter is used with `client.connect()`.","message":"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.","severity":"breaking","affected_versions":">=1.0.6"},{"fix":"Update all calls to `client.connect()` to use `api_token` instead of `cvaas_token`.","message":"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.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Ensure your environment is running Python 3.7 or newer. Old Python 2 scripts will likely fail.","message":"`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.","severity":"gotcha","affected_versions":">=1.4.0"},{"fix":"Always refer to the Arista CVP API documentation for your specific CVP version. Test automation against CVP upgrades. Consult `cvprac` release notes for CVP version validations.","message":"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.","severity":"gotcha","affected_versions":"All versions, specific CVP versions affect behavior."}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `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`.","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`.","error":"from pkg_resources import parse_version ModuleNotFoundError: No module named 'pkg_resources'"},{"fix":"Verify 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.","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.","error":"cvprac.cvp_client_errors.CvpLoginError: A CvpLoginError is raised if a connection could not be established to any of the nodes."},{"fix":"Check 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.","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.","error":"cvprac.cvp_client_errors.CvpRequestError: POST: https://.../api/v3/... : Request Error: Gateway Timeout - rpc error: code = DeadlineExceeded desc = failed to connect to service..."},{"fix":"Double-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.","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.","error":"requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"}]}