-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from aristanetworks/release-1.0.7
Release 1.0.7
- Loading branch information
Showing
46 changed files
with
1,393 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.6 | ||
1.0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# cvprac labs | ||
|
||
The following lab examples will walk through the most commonly used REST API calls using cvprac | ||
to help users interact with Arista CloudVision easily and automate the provisioning of network devices. | ||
|
||
## Authentication | ||
|
||
There are two ways to authenticate using the REST APIs: | ||
- user/password (on-prem only) | ||
- service account token (available on CVP 2020.3.0+ and CVaaS) | ||
|
||
### User/password authentication | ||
|
||
```python | ||
from cvprac.cvp_client import CvpClient | ||
clnt = CvpClient() | ||
clnt.connect(['10.83.13.33'],'cvpadmin', 'arastra') | ||
``` | ||
|
||
### Service account token authentication | ||
|
||
To access the CloudVision as-a-Service and send API requests, “Service Account Token” is needed. | ||
After obtaining the service account token, it can be used for authentication when sending API requests. | ||
|
||
Service accounts can be created from the Settings page where a service token can be generated as seen below: | ||
|
||
![serviceaccount1](./static/serviceaccount1.png) | ||
![serviceaccount2](./static/serviceaccount2.png) | ||
![serviceaccount3](./static/serviceaccount3.png) | ||
|
||
The token should be copied and saved to a file that can later be referred to. | ||
|
||
```python | ||
from cvprac.cvp_client import CvpClient | ||
clnt = CvpClient() | ||
with open("token.tok") as f: | ||
token = f.read().strip('\n') | ||
clnt.connect(nodes=['www.arista.io'], username='', password='', is_cvaas=True, api_token=token) | ||
``` | ||
|
||
>NOTE In case of CVaaS the `is_cvaas` parameters has to be set to `True` | ||
Service accounts are supported on CVP on-prem starting from `2020.3.0`. More details in the [TOI](https://eos.arista.com/toi/cvp-2020-3-0/service-accounts/) and the [CV config guide](https://www.arista.com/en/cg-cv/cv-service-accounts). | ||
|
||
```python | ||
from cvprac.cvp_client import CvpClient | ||
|
||
with open("token.tok") as f: | ||
token = f.read().strip('\n') | ||
|
||
clnt = CvpClient() | ||
clnt.connect(nodes=['10.83.13.33'], username='',password='',api_token=token) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2021 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the COPYING file. | ||
|
||
from cvprac.cvp_client import CvpClient | ||
import ssl | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
import requests.packages.urllib3 | ||
|
||
requests.packages.urllib3.disable_warnings() | ||
|
||
# Create connection to CloudVision | ||
clnt = CvpClient() | ||
clnt.connect(nodes=['cvp1'], username="username",password="password") | ||
|
||
result = clnt.api.get_cvp_info() | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (c) 2021 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the COPYING file. | ||
|
||
from cvprac.cvp_client import CvpClient | ||
import ssl | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
import requests.packages.urllib3 | ||
requests.packages.urllib3.disable_warnings() | ||
|
||
### Compliance Code description | ||
compliance = {"0000":"Configuration is in sync", | ||
"0001": "Config is out of sync", | ||
"0002": "Image is out of sync", | ||
"0003": "Config & image out of sync", | ||
"0004": "Config, Image and Device time are in sync", | ||
"0005": "Device is not reachable", | ||
"0006": "The current EOS version on this device is not supported by CVP. Upgrade the device to manage.", | ||
"0007": "Extensions are out of sync", | ||
"0008": "Config, Image and Extensions are out of sync", | ||
"0009": "Config and Extensions are out of sync", | ||
"0010": "Image and Extensions are out of sync", | ||
"0011": "Unauthorized User", | ||
"0012": "Config, Image, Extension and Device time are out of sync", | ||
"0013": "Config, Image and Device time are out of sync", | ||
"0014": "Config, Extensions and Device time are out of sync", | ||
"0015": "Image, Extensions and Device time are out of sync", | ||
"0016": "Config and Device time are out of sync", | ||
"0017": "Image and Device time are out of sync", | ||
"0018": "Extensions and Device time are out of sync", | ||
"0019": "Device time is out of sync" | ||
} | ||
|
||
# Create connection to CloudVision using Service account token | ||
with open("token.tok") as f: | ||
token = f.read().strip('\n') | ||
|
||
clnt = CvpClient() | ||
clnt.connect(nodes=['cvp1'], username='',password='',api_token=token) | ||
|
||
def check_devices_under_container(client, container): | ||
''' container is the container ID ''' | ||
|
||
nodeId = container['key'] | ||
nodeName = container['name'] | ||
api = '/ztp/getAllNetElementList.do?' | ||
queryParams = "nodeId={}&queryParam=&nodeName={}&startIndex=0&endIndex=0&contextQueryParam=&ignoreAdd=false&useCache=true".format(nodeId, nodeName) | ||
return client.get(api + queryParams) | ||
|
||
|
||
container = clnt.api.get_container_by_name('TP_LEAFS') | ||
|
||
devices = (check_devices_under_container(clnt,container)) | ||
|
||
for device in devices['netElementList']: | ||
code = device['complianceCode'] | ||
print(device['fqdn'], ' ', code,' ', compliance[code]) |
21 changes: 21 additions & 0 deletions
21
docs/labs/lab02-inventory-operations/remove_all_devices.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) 2021 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the COPYING file. | ||
|
||
from cvprac.cvp_client import CvpClient | ||
import ssl | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
import requests.packages.urllib3 | ||
requests.packages.urllib3.disable_warnings() | ||
|
||
# Create connection to CloudVision | ||
clnt = CvpClient() | ||
clnt.connect(nodes=['cvp1'], username="username",password="password") | ||
|
||
inventory = clnt.api.get_inventory() | ||
|
||
devices = [] | ||
for netelement in inventory: | ||
devices.append(netelement['systemMacAddress']) | ||
|
||
clnt.api.delete_devices(devices) |
Oops, something went wrong.