| 1 |
# cvprac labs |
| 2 |
|
| 3 |
The following lab examples will walk through the most commonly used REST API calls using cvprac |
| 4 |
to help users interact with Arista CloudVision easily and automate the provisioning of network devices. |
| 5 |
|
| 6 |
## Table of Contents |
| 7 |
|
| 8 |
- [cvprac labs](#cvprac-labs) |
| 9 |
- [Table of Contents](#table-of-contents) |
| 10 |
- [Authentication](#authentication) |
| 11 |
- [Password Authentication](#password-authentication) |
| 12 |
- [Service Account Token Authentication](#service-account-token-authentication) |
| 13 |
- [Known Limitations](#known-limitations) |
| 14 |
|
| 15 |
## Authentication |
| 16 |
|
| 17 |
There are two ways to authenticate using the REST APIs: |
| 18 |
|
| 19 |
- user/password (on-prem only) |
| 20 |
- service account token (available on CVP 2020.3.0+ and CVaaS) |
| 21 |
|
| 22 |
### Password Authentication |
| 23 |
|
| 24 |
```python |
| 25 |
from cvprac.cvp_client import CvpClient |
| 26 |
clnt = CvpClient() |
| 27 |
clnt.connect(['10.83.13.33'],'cvpadmin', 'arastra') |
| 28 |
``` |
| 29 |
|
| 30 |
### Service Account Token Authentication |
| 31 |
|
| 32 |
To access the CloudVision as-a-Service and send API requests, "Service Account Token" is needed. |
| 33 |
After obtaining the service account token, it can be used for authentication when sending API requests. |
| 34 |
|
| 35 |
Service accounts can be created from the Settings page where a service token can be generated as seen below: |
| 36 |
|
| 37 |
 |
| 38 |
 |
| 39 |
 |
| 40 |
|
| 41 |
The token should be copied and saved to a file that can later be referred to. |
| 42 |
|
| 43 |
```python |
| 44 |
from cvprac.cvp_client import CvpClient |
| 45 |
clnt = CvpClient() |
| 46 |
with open("token.tok") as f: |
| 47 |
token = f.read().strip('\n') |
| 48 |
clnt.connect(nodes=['www.arista.io'], username='', password='', is_cvaas=True, api_token=token) |
| 49 |
``` |
| 50 |
|
| 51 |
>NOTE In case of CVaaS the `is_cvaas` parameters has to be set to `True` |
| 52 |
|
| 53 |
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). |
| 54 |
|
| 55 |
```python |
| 56 |
from cvprac.cvp_client import CvpClient |
| 57 |
|
| 58 |
with open("token.tok") as f: |
| 59 |
token = f.read().strip('\n') |
| 60 |
|
| 61 |
clnt = CvpClient() |
| 62 |
clnt.connect(nodes=['10.83.13.33'], username='',password='',api_token=token) |
| 63 |
``` |
| 64 |
|
| 65 |
> Note that for CVaaS the correct regional URL must be used including `www.`. Please refer to the main page's [README.md](../../README.md#cvaas) |
| 66 |
|
| 67 |
## Known Limitations |
| 68 |
|
| 69 |
- for any APIs that interact with EOS devices, the service account name must match the name of the username |
| 70 |
configured on EOS and CVP |
| 71 |
- Support for REST API bindings for the Resource APIs (Lab 8) was added in CVP 2021.1.0 |