| 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 |
from cvprac.cvp_client import CvpClient |
| 12 |
import csv |
| 13 |
|
| 14 |
# Create connection to CloudVision using Service Account token |
| 15 |
with open("cvaas.tok") as f: |
| 16 |
token = f.read().strip('\n') |
| 17 |
|
| 18 |
clnt = CvpClient() |
| 19 |
clnt.connect(nodes=['www.arista.io'], username='', password='', is_cvaas=True, api_token=token) |
| 20 |
|
| 21 |
|
| 22 |
with open("aaa_users.csv") as csvfile: |
| 23 |
for i in csv.DictReader(csvfile): |
| 24 |
data = dict(i) |
| 25 |
try: |
| 26 |
clnt.api.add_user(data['username'], "", data['role'], data['status'], data['first_name'], data['last_name'], data['email'], data['user_type']) |
| 27 |
except CvpApiError as e: |
| 28 |
print(e) |
| 29 |
print ("Adding user {} to CVaaS".format(data['username'])) |