Debian Codegraph @

docs/labs/lab02-inventory-operations/remove_all_devices_legacy.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 inventory = clnt.api.get_inventory()
16
17 devices = []
18 for netelement in inventory:
19 devices.append(netelement['systemMacAddress'])
20
21 # Remove devices from provisioning
22 # This is a legacy API call that removes the devices from Network Provisioning
23 # in CVP versions older than 2021.3.0, however it does not remove them from
24 # the Device Inventory as that requires the streaming agent (TerminAttr) to be shutdown,
25 # which this API does not support.
26 # To fully decommission a device the device_decommissioning() API can be used, which is
27 # supported from 2021.3.0+.
28 # Note that using the delete_devices() function post CVP 2021.3.0 the device will be
29 # automatically added back to the Undefined container.
30 clnt.api.delete_devices(devices)