Debian Codegraph @

docs/labs/lab02-inventory-operations/get_running_configs.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 # Create connection to CloudVision
12 clnt = CvpClient()
13 clnt.connect(nodes=['cvp1'], username="username",password="password")
14
15 # Get the full inventory
16 inventory = clnt.api.get_inventory()
17
18 # Create a list of MAC addresses
19 device_macs = []
20 for i in inventory:
21 device_macs.append(i['systemMacAddress'])
22
23 # Create a dictionary with MAC to running-config mapping
24 running_configs = {}
25 for i in device_macs:
26 running_configs[i] = clnt.api.get_device_configuration(i)
27
28 # Write the running-configs of each device using the hostname as the filename
29 for i in inventory:
30 with open(i['fqdn']+'.cfg', 'w') as f:
31 f.write(running_configs[i['systemMacAddress']])