Debian Codegraph @

README.md

raw
1 # Arista Cloudvision® Portal RESTful API Client
2
3 [![pypi](https://img.shields.io/pypi/v/cvprac.svg)](https://pypi.python.org/pypi/cvprac)
4
5 ## Table of Contents
6
7 - [Arista Cloudvision® Portal RESTful API Client](#arista-cloudvision-portal-restful-api-client)
8 - [Table of Contents](#table-of-contents)
9 - [Overview](#overview)
10 - [Requirements](#requirements)
11 - [Installation](#installation)
12 - [Development: Run from Source](#development-run-from-source)
13 - [Step 1: Clone the cvprac Github repo](#step-1-clone-the-cvprac-github-repo)
14 - [Step 2: Check out the desired version or branch](#step-2-check-out-the-desired-version-or-branch)
15 - [Step 3: Install cvprac using Pip with -e switch](#step-3-install-cvprac-using-pip-with--e-switch)
16 - [Step 4: Install cvprac development requirements](#step-4-install-cvprac-development-requirements)
17 - [Getting Started](#getting-started)
18 - [Connecting](#connecting)
19 - [CVP On Premises](#cvp-on-premises)
20 - [CVaaS](#cvaas)
21 - [CVP Version Handling](#cvp-version-handling)
22 - [Examples](#examples)
23 - [Notes for API Class Usage](#notes-for-api-class-usage)
24 - [Containers](#containers)
25 - [Testing](#testing)
26 - [Contact or Questions](#contact-or-questions)
27 - [Contributing](#contributing)
28 - [Working With Git](#working-with-git)
29 - [Submitting Pull Requests](#submitting-pull-requests)
30 - [Pull Request Semantics](#pull-request-semantics)
31 - [License](#license)
32
33 ## Overview
34
35 This module provides a RESTful API client for Cloudvision® Portal (CVP)
36 which can be used for building applications that work with Arista CVP.
37
38 When the class is instantiated the logging is configured. Either syslog,
39 file logging, both, or none can be enabled. If neither syslog nor
40 filename is specified then no logging will be performed.
41
42 This class supports creating a connection to a CVP node and then issuing
43 subsequent GET and POST requests to CVP. A GET or POST request will be
44 automatically retried on the same node if the request receives a
45 requests.exceptions.Timeout or ReadTimeout error. A GET or POST request
46 will be automatically retried on the same node if the request receives a
47 CvpSessionLogOutError. For this case a login will be performed before
48 the request is retried. For either case, the maximum number of times a
49 request will be retried on the same node is specified by the class
50 attribute NUM\_RETRY\_REQUESTS.
51
52 If more than one CVP node is specified when creating a connection, and a
53 GET or POST request that receives a requests.exceptions.ConnectionError,
54 requests.exceptions.HTTPError, or a requests.exceptions.TooManyRedirects
55 will be retried on the next CVP node in the list. If a GET or POST
56 request that receives a requests.exceptions.Timeout or
57 CvpSessionLogOutError and the retries on the same node exceed
58 NUM\_RETRY\_REQUESTS, then the request will be retried on the next node
59 on the list.
60
61 If any of the errors persists across all nodes then the GET or POST
62 request will fail and the last error that occurred will be raised.
63
64 The class provides connect, get, and post methods that allow the user to
65 make RESTful API calls to CVP. See the example below using the get
66 method.
67
68 The class provides a wrapper function around the CVP RESTful API
69 operations. Each API method takes the RESTful API parameters as method
70 parameters to the operation method. The API class was added to the
71 client class because the API functions are required when using the CVP
72 RESTful API and placing them in this library avoids duplicating the
73 calls in every application that uses this class. See the examples below
74 using the API methods.
75
76 ### Requirements
77
78 - Python 3.7 or later
79 - Python logging module
80 - Python requests module with socks version 2.27.0 or later
81 - Python packaging module version 23.2 or later
82
83 ## Installation
84
85 The source code for cvprac is provided on Github at
86 <https://github.com/aristanetworks/cvprac>. All current development is
87 done in the develop branch. Stable released versions are tagged in the
88 master branch and uploaded to <https://pypi.python.org>.
89
90 If your platform has internet access you can use the Python Package
91 manager to install cvprac.
92
93 admin:~ admin$ sudo pip install cvprac
94
95 You can upgrade cvprac
96
97 admin:~ admin$ sudo pip install --upgrade cvprac
98
99 ### Development: Run from Source
100
101 We recommend running cvprac in a virtual environment. For more
102 information, read this:
103 <http://docs.python-guide.org/en/latest/dev/virtualenvs/>
104
105 These instructions will help you install and run cvprac from source.
106 This is useful if you plan on contributing or if you would always like
107 to see the latest code in the develop branch. Note that these steps
108 require the pip and git commands.
109
110 #### Step 1: Clone the cvprac Github repo
111
112 # Go to a directory where you'd like to keep the source
113 admin:~ admin$ cd ~/projects
114 admin:~ admin$ git clone https://github.com/aristanetworks/cvprac
115 admin:~ admin$ cd cvprac
116
117 #### Step 2: Check out the desired version or branch
118
119 # Go to a directory where you'd like to keep the source
120 admin:~ admin$ cd ~/projects/cvprac
121
122 # To see a list of available versions or branches
123 admin:~ admin$ git tag
124 admin:~ admin$ git branch
125
126 # Checkout the desired version of code
127 admin:~ admin$ git checkout v1.0.3
128
129 #### Step 3: Install cvprac using Pip with -e switch
130
131 # Go to a directory where you'd like to keep the source
132 admin:~ admin$ cd ~/projects/cvprac
133
134 # Install
135 admin:~ admin$ sudo pip install -e ~/projects/cvprac
136
137 #### Step 4: Install cvprac development requirements
138
139 # Go to a directory where you'd like to keep the source
140 admin:~ admin$ pip install -r dev-requirements.txt
141
142 ## Getting Started
143
144 Once the package has been installed you can run the following example to
145 verify that everything has been installed properly.
146
147 ### Connecting
148
149 Connecting to CVP will depend on your CVP setup. Several options are
150 outlined below.
151
152 ### CVP On Premises
153
154 CVP On Premises is for users with CVP running on a local server or
155 cluster of servers. This is the standard form of connection. Multiple
156 examples below demonstrate connecting to CVP On Premises setups.
157
158 ### CVaaS
159
160 CVaaS is CloudVision as a Service. Users with CVaaS must use a REST API
161 token (service account tokens) for accessing CVP with REST APIs.
162
163 - In the case where users authenticate with CVP (CVaaS) using Oauth a
164 - REST API token is required to be generated and used for running REST
165 - APIs. In this case no username/password login is necessary, but the
166 - API token (via api\_token parameter) must be provided to cvprac client
167 - with the is\_cvaas parameter. In the case that the api\_token is used
168 - for REST APIs the username and password will be ignored and the tenant
169 - parameter is not needed.
170
171 An example of a CVaaS connection is shown below.
172
173 Note that the token parameter was previously cvaas\_token but this has
174 been converted to api\_token because tokens are also available for usage
175 with On Prem CVP deployments. The api\_token parameter name is more
176 generic in this sense. If you are using the cvaas\_token parameter
177 please convert to api\_token because the cvaas\_token parameter will be
178 deprecated in the future.
179
180 Please note that the correct regional URL where the CVaaS tenant is deployed must be used. The following
181 are some examples of the cluster URLs used in production, a full list can be found on [helpcenter](https://www.arista.io/help/articles/b3ZlcnZpZXcuQWxsLmRlcGxveW1lbnQ=#Y3ZhYXNEZXBsb3ltZW50-region):
182
183 | Region | URL |
184 |--------|-----|
185 | United States 1a | [www.arista.io](https://www.arista.io) |
186 | United States 1c| [www.cv-prod-us-central1-c.arista.io](https://www.cv-prod-us-central1-c.arista.io)|
187 | Canada | [www.cv-prod-na-northeast1-b.arista.io](https://www.cv-prod-na-northeast1-b.arista.io)|
188 | Europe West 2| [www.cv-prod-euwest-2.arista.io](https://www.cv-prod-euwest-2.arista.io)|
189 | Japan| [www.cv-prod-apnortheast-1.arista.io](https://www.cv-prod-apnortheast-1.arista.io)|
190 | Australia | [www.cv-prod-ausoutheast-1.arista.io](https://www.cv-prod-ausoutheast-1.arista.io)|
191
192 !!! Warning
193
194 URLs without `www` are not supported.
195
196
197 ### CVP Version Handling
198
199 The CVP RESTful APIs often change between releases of CVP. Cvprac
200 attempts to mask these API changes from the user via making appropriate
201 API calls based on the CVP version while attempting to maintain return
202 data and not changing function names when possible. This helps maintain
203 backward compatibility for users when they upgrade CVP so that any
204 custom automation/scripts will continue to work. In some cases
205 maintaining return data requires additional API calls so there are cases
206 where this comes with the cost of a slight performance hit. Users are
207 free to access the clients get(), post() and delete() methods and make
208 API calls directly if they want to avoid the potential time delay of
209 some API functions. The current API version information handled by
210 cvprac is shown below.
211
212 - Current latest API version is 17.0 API version is set to latest (2025.3.X+)
213 - available version for CVaaS API version is set to 17.0 for 2025.3.X and
214 - beyond. API version is set to 3.0 for 2019.0.0 through 2020.1.0 API
215 - version is set to 2.0 for 2018.2.X API version is set to 1.0 for
216 - 2018.1.X and prior
217
218 #### CVP 2025.2.X+
219
220 As of CVP 2025.2.0 and beyond the network provisioning service is disabled by default for new
221 installations of CVP. If you have upgraded to CVP 2025.2.X+ from a previous version then the
222 network provisioning service should be running as usual.
223
224 If you have done a fresh install of CVP 2025.2.X+ and you want to continue to use provisioning APIs
225 you will have to enable and start the networkprovisioning service. Please contact TAC for
226 information on enabling networkprovisioning in CVP 2025.2.X+.
227
228 ### Examples
229
230 Example using CVP On Prem client get method directly:
231
232 >>> from cvprac.cvp_client import CvpClient
233 >>> clnt = CvpClient()
234 >>> clnt.connect(['cvp1', 'cvp2', 'cvp3'], 'cvp_user', 'cvp_word')
235 >>> result = clnt.get('/cvpInfo/getCvpInfo.do')
236 >>> print result
237 {u'version': u'2016.1.0'}
238 >>>
239
240 Same example as above using the API method:
241
242 >>> from cvprac.cvp_client import CvpClient
243 >>> clnt = CvpClient()
244 >>> clnt.connect(['cvp1', 'cvp2', 'cvp3'], 'cvp_user', 'cvp_word')
245 >>> result = clnt.api.get_cvp_info()
246 >>> print result
247 {u'version': u'2016.1.0'}
248 >>>
249
250 Example using CVP On Prem client cert login:
251
252 >>> from cvprac.cvp_client import CvpClient
253 >>> clnt = CvpClient()
254 >>> cert, key = "/cert/client.crt", "/cert/client.key" # cert_file_path, private_key_file_path
255 >>> clnt.connect(['cvp1', 'cvp2', 'cvp3'], 'cvp_user', 'cvp_word', cert_login=True, client_cert=(cert, key))
256 >>> result = clnt.get('/cvpInfo/getCvpInfo.do')
257 >>> print result
258 {u'version': u'2016.1.0'}
259 >>>
260
261 Same example as above but connecting to CVaaS with a token: Note that
262 the username and password parameters are required by the connect
263 function but will be ignored when using api\_token:
264
265 >>> from cvprac.cvp_client import CvpClient
266 >>> clnt = CvpClient()
267 >>> clnt.connect(nodes=['cvaas'], username='', password='', is_cvaas=True, api_token='user token')
268 >>> result = clnt.api.get_cvp_info()
269 >>> print result
270 {u'version': u'cvaas'}
271 >>>
272
273 Example using the API method to create a container, wait 5 seconds, then
274 delete the container. Before running this example manually create a
275 container named DC-1 on your CVP node.
276
277 >>> import time
278 >>> from cvprac.cvp_client import CvpClient
279 >>> clnt = CvpClient()
280 >>> clnt.connect(['cvp1'], 'cvp_user', 'cvp_word')
281 >>> parent = clnt.api.search_topology('DC-1')
282 >>> clnt.api.add_container('TORs', 'DC-1', parent['containerList'][0]['key'])
283 >>> child = clnt.api.search_topology('TORs')
284 >>> time.sleep(5)
285 >>> result = clnt.api.delete_container('TORs', child['containerList'][0]['key'], 'DC-1', parent['containerList'][0]['key'])
286 >>>
287
288 ## Notes for API Class Usage
289
290 ### Containers
291
292 With the API the containers are added for all cases. If you add the
293 container to the original root container 'Tenant' then you have to do a
294 refresh from the GUI to see the container after it is added or deleted.
295 If the root container has been renamed or the parent container is not
296 the root container then an add or delete will update the GUI without
297 requiring a manual refresh.
298
299 ## Testing
300
301 The cvprac module provides both unit tests and system tests.
302 To run the system tests, read the [detailed system test documentation](test/system/SYSTEM_TEST_CVP_SETUP.md) for more information on how to set up the environment.
303
304 To run the system tests:
305
306 - run `make tests` from the root of the cvprac source folder.
307
308 ## Contact or Questions
309
310 Cvprac is developed by Arista EOS+ CS and supported by the Arista EOS+
311 community. Support for the code is provided on a best effort basis by
312 the Arista EOS+ CS team and the community. You can contact the team that
313 develops these modules by sending an email to <[email protected]>.
314
315 For customers that are looking for a premium level of support, please
316 contact your local account team or email <[email protected]> for help.
317
318 ## Contributing
319
320 Contributing pull requests are gladly welcomed for this repository. Not only contributing to the code but also we encourage the users to contribute in the form of examples, docs, tutorials, and user guides.
321
322 Please note that all contributions that modify the library behavior
323 require corresponding test cases otherwise the pull request will be
324 rejected.
325
326 ### Working With Git
327
328 It is recommended to fork the project and then start development on the forked repository's **develop** branch. This can achieved with the below steps:
329
330 - [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the repo then clone your fork,
331 and configure the remotes:
332
333 # Clone your fork of the repo into the current directory
334 git clone https://github.com/<your-username>/cvprac
335
336 # Navigate to the newly cloned directory
337 cd cvprac
338
339 # Assign the original repo to a remote called "upstream"
340 git remote add upstream https://github.com/aristanetworks/cvprac.git
341
342 - If you cloned a while ago, get the latest changes from upstream:
343
344 # Work on the develop branch of the forked repo
345 git checkout develop
346
347 # Pull the latest changes from the develop branch of aristanetworks cvprac
348 git pull upstream develop
349
350 - Create a new topic branch (off the main project development branch) to
351 contain your feature, change, or fix:
352
353 git checkout -b <topic-branch-name>
354
355 - Commit your changes in logical chunks. Please adhere to these [git commit
356 message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
357 or your code is unlikely to be merged into the main project. Use Git's
358 [git rebase](https://docs.github.com/en/get-started/using-git/about-git-rebase)
359 feature to tidy up your commits before making them public.
360
361 - Locally merge (or rebase) the upstream development branch into your topic branch every time before pushing it to your fork:
362
363 # Here the <dev-branch> is develop
364 git pull [--rebase] upstream <dev-branch>
365
366 - Push your topic branch up to your fork:
367
368 git push origin <topic-branch-name>
369
370 - [Open a Pull Request](https://github.com/aristanetworks/cvprac/pulls)
371 with a clear title, description and explain how to test the feature.
372
373 ### Submitting Pull Requests
374
375 - It is recommended to open an issue before starting work on a pull request to make sure if the same issue is not reported previously and someone is already working on that. When suggesting a new feature, also make sure it won't conflict with any work that's already in progress.
376
377 - Once the issue is opened either self-assign the issue or ask the maintainer to assign it for you. This will make sure no others are working on the same issue.
378
379 - All new functionality must include relevant tests where applicable.
380
381 - When submitting a pull request, please be sure to work off of the **develop** branch and not from other branches. The **develop** branch is used for ongoing development, while the **master** will hold the last stable version.
382
383 - To automate release-notes creation and make filtering process easier, it is strongly recommended to use [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) syntax at least for Pull Request (PR) title.
384
385 - All code submissions must follow the below criteria:
386
387 - The issue/PR title should follow the semantic as described [here](#pull-request-semantics)
388 - All the tests are updated and are passed successfully
389 - Python syntax is valid
390
391 ### Pull Request Semantics
392
393 The Pull Request title should start with one of the below to easily segregate if its a feature add or a bug or something related documentation etc.
394
395 It is strongly recommended to use one from the below:
396
397 - ```Feat```: Create a capability e.g. feature, test, dependency
398 - ```Fix```: Fix an issue e.g. bug, typo, accident, misstatement
399 - ```Doc```: Refactor of documentation, e.g. help files
400 - ```Example```: Add a new example or modify an [existing one](docs/labs/)
401 - ```Test```: Add or refactor anything regarding test, e.g add a new testCases or missing testCases
402 - ```Refactor```: A code change that MUST be just a refactoring
403 - ```Bump```: Increase the version of something e.g. dependency
404 - ```Revert```: Change back to the previous commit
405 - ```Optimize```: Refactor of performance, e.g. speed up code
406 - ```CI```: Update CI components, e.g. molecule files or Github Actions
407 - ```Cut```: Remove a capability e.g. feature, test, dependency
408
409 For example:
410
411 - Feat: Add support for decommissioning APIs
412 - Test: Add missing test cases for change control
413 - Doc: Document new examples for change control
414
415 ## License
416
417 Copyright© 2020, Arista Networks, Inc. All rights reserved.
418
419 Redistribution and use in source and binary forms, with or without
420 modification, are permitted provided that the following conditions are
421 met:
422
423 - Redistributions of source code must retain the above copyright
424 notice, this list of conditions and the following disclaimer.
425 - Redistributions in binary form must reproduce the above copyright
426 notice, this list of conditions and the following disclaimer in the
427 documentation and/or other materials provided with the distribution.
428 - Neither the name of Arista Networks nor the names of its
429 contributors may be used to endorse or promote products derived from
430 this software without specific prior written permission.
431
432 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS
433 IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
434 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
435 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS BE
436 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
437 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
438 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
439 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
440 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
441 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
442 THE POSSIBILITY OF SUCH DAMAGE.