Debian Codegraph @

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