Debian Codegraph @

docs/labs/lab07-aaa/create_svc_account_token.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 from cvprac.cvp_client import CvpClient
6 from cvprac.cvp_client_errors import CvpApiError
7 import ssl
8 ssl._create_default_https_context = ssl._create_unverified_context
9 import requests.packages.urllib3
10 requests.packages.urllib3.disable_warnings()
11
12 # Create connection to CloudVision using user/password (on-prem only)
13 clnt = CvpClient()
14 clnt.connect(['cvp1'],'username', 'password')
15
16 username = "cvprac2"
17 duration = "31536000s" # 1 year validity
18 description = "test cvprac"
19 svc_token = clnt.api.svc_account_token_set(username, duration, description)
20
21 # Write the token to file in <username>.tok format
22 with open(svc_token[0]['value']['user'] + ".tok", "w") as f:
23 f.write(svc_token[0]['value']['token'])