Debian Codegraph @

docs/labs/lab07-aaa/create_terminattr_tokens.py

raw
1 # Copyright (c) 2021 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the COPYING file.
4 #
5 # Example script to generate the TerminAttr token via REST API from CVaaS and CV on-prem
6 # and save them to a file
7
8 from cvprac.cvp_client import CvpClient
9 from pprint import pprint as pp
10 import ssl
11 ssl._create_default_https_context = ssl._create_unverified_context
12 import requests.packages.urllib3
13 requests.packages.urllib3.disable_warnings()
14
15 # Reading the service account token from a file
16 with open("cvaas.tok") as f:
17 token = f.read().strip('\n')
18
19 clnt = CvpClient()
20 clnt.connect(nodes=['www.arista.io'], username='',password='',is_cvaas=True, api_token=token)
21
22 terminattr_token = clnt.api.create_enroll_token('720h')
23 with open('cv-onboarding-token', 'w') as f:
24 f.write(terminattr_token[0]['enrollmentToken']['token'])
25
26 primary = CvpClient()
27 primary.connect(nodes=['cvp1'], username='username',password='password')
28
29 terminattr_token = primary.api.create_enroll_token('720h')
30
31 with open('token', 'w') as f:
32 f.write(terminattr_token['data'])