Debian Codegraph @

docs/labs/lab02-inventory-operations/compliance_check.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 import ssl
7 ssl._create_default_https_context = ssl._create_unverified_context
8 import requests.packages.urllib3
9 requests.packages.urllib3.disable_warnings()
10
11 ### Compliance Code description
12 compliance = {"0000":"Configuration is in sync",
13 "0001": "Config is out of sync",
14 "0002": "Image is out of sync",
15 "0003": "Config & image out of sync",
16 "0004": "Config, Image and Device time are in sync",
17 "0005": "Device is not reachable",
18 "0006": "The current EOS version on this device is not supported by CVP. Upgrade the device to manage.",
19 "0007": "Extensions are out of sync",
20 "0008": "Config, Image and Extensions are out of sync",
21 "0009": "Config and Extensions are out of sync",
22 "0010": "Image and Extensions are out of sync",
23 "0011": "Unauthorized User",
24 "0012": "Config, Image, Extension and Device time are out of sync",
25 "0013": "Config, Image and Device time are out of sync",
26 "0014": "Config, Extensions and Device time are out of sync",
27 "0015": "Image, Extensions and Device time are out of sync",
28 "0016": "Config and Device time are out of sync",
29 "0017": "Image and Device time are out of sync",
30 "0018": "Extensions and Device time are out of sync",
31 "0019": "Device time is out of sync"
32 }
33
34 # Create connection to CloudVision using Service account token
35 with open("token.tok") as f:
36 token = f.read().strip('\n')
37
38 clnt = CvpClient()
39 clnt.connect(nodes=['cvp1'], username='',password='',api_token=token)
40
41 def check_devices_under_container(client, container):
42 ''' container is the container ID '''
43
44 nodeId = container['key']
45 nodeName = container['name']
46 api = '/ztp/getAllNetElementList.do?'
47 queryParams = "nodeId={}&queryParam=&nodeName={}&startIndex=0&endIndex=0&contextQueryParam=&ignoreAdd=false&useCache=true".format(nodeId, nodeName)
48 return client.get(api + queryParams)
49
50
51 container = clnt.api.get_container_by_name('TP_LEAFS')
52
53 devices = (check_devices_under_container(clnt,container))
54
55 for device in devices['netElementList']:
56 code = device['complianceCode']
57 print(device['fqdn'], ' ', code,' ', compliance[code])