Adding upstream version 1.3.1+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
455a3d9fdb
commit
d2e39936a0
95 changed files with 10747 additions and 0 deletions
57
docs/labs/lab02-inventory-operations/compliance_check.py
Normal file
57
docs/labs/lab02-inventory-operations/compliance_check.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# Copyright (c) 2021 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
### Compliance Code description
|
||||
compliance = {"0000":"Configuration is in sync",
|
||||
"0001": "Config is out of sync",
|
||||
"0002": "Image is out of sync",
|
||||
"0003": "Config & image out of sync",
|
||||
"0004": "Config, Image and Device time are in sync",
|
||||
"0005": "Device is not reachable",
|
||||
"0006": "The current EOS version on this device is not supported by CVP. Upgrade the device to manage.",
|
||||
"0007": "Extensions are out of sync",
|
||||
"0008": "Config, Image and Extensions are out of sync",
|
||||
"0009": "Config and Extensions are out of sync",
|
||||
"0010": "Image and Extensions are out of sync",
|
||||
"0011": "Unauthorized User",
|
||||
"0012": "Config, Image, Extension and Device time are out of sync",
|
||||
"0013": "Config, Image and Device time are out of sync",
|
||||
"0014": "Config, Extensions and Device time are out of sync",
|
||||
"0015": "Image, Extensions and Device time are out of sync",
|
||||
"0016": "Config and Device time are out of sync",
|
||||
"0017": "Image and Device time are out of sync",
|
||||
"0018": "Extensions and Device time are out of sync",
|
||||
"0019": "Device time is out of sync"
|
||||
}
|
||||
|
||||
# Create connection to CloudVision using Service account token
|
||||
with open("token.tok") as f:
|
||||
token = f.read().strip('\n')
|
||||
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username='',password='',api_token=token)
|
||||
|
||||
def check_devices_under_container(client, container):
|
||||
''' container is the container ID '''
|
||||
|
||||
nodeId = container['key']
|
||||
nodeName = container['name']
|
||||
api = '/ztp/getAllNetElementList.do?'
|
||||
queryParams = "nodeId={}&queryParam=&nodeName={}&startIndex=0&endIndex=0&contextQueryParam=&ignoreAdd=false&useCache=true".format(nodeId, nodeName)
|
||||
return client.get(api + queryParams)
|
||||
|
||||
|
||||
container = clnt.api.get_container_by_name('TP_LEAFS')
|
||||
|
||||
devices = (check_devices_under_container(clnt,container))
|
||||
|
||||
for device in devices['netElementList']:
|
||||
code = device['complianceCode']
|
||||
print(device['fqdn'], ' ', code,' ', compliance[code])
|
31
docs/labs/lab02-inventory-operations/get_running_configs.py
Normal file
31
docs/labs/lab02-inventory-operations/get_running_configs.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Copyright (c) 2021 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
# Create connection to CloudVision
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username="username",password="password")
|
||||
|
||||
# Get the full inventory
|
||||
inventory = clnt.api.get_inventory()
|
||||
|
||||
# Create a list of MAC addresses
|
||||
device_macs = []
|
||||
for i in inventory:
|
||||
device_macs.append(i['systemMacAddress'])
|
||||
|
||||
# Create a dictionary with MAC to running-config mapping
|
||||
running_configs = {}
|
||||
for i in device_macs:
|
||||
running_configs[i] = clnt.api.get_device_configuration(i)
|
||||
|
||||
# Write the running-configs of each device using the hostname as the filename
|
||||
for i in inventory:
|
||||
with open(i['fqdn']+'.cfg', 'w') as f:
|
||||
f.write(running_configs[i['systemMacAddress']])
|
|
@ -0,0 +1,34 @@
|
|||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username="username",password="password")
|
||||
|
||||
ts = "2021-11-19T15:04:05.0Z" # rfc3339 time
|
||||
uri = "/api/v3/services/compliancecheck.Compliance/GetConfig"
|
||||
|
||||
# Fetch the inventory
|
||||
inventory = clnt.api.get_inventory()
|
||||
|
||||
# Iterate through all devices and get the running-config at the specified time for each device
|
||||
for device in inventory:
|
||||
sn = device['serialNumber']
|
||||
data = {"request":{
|
||||
"device_id": sn,
|
||||
"timestamp": ts,
|
||||
"type":"RUNNING_CONFIG"
|
||||
}
|
||||
}
|
||||
try:
|
||||
resultRunningConfig = clnt.post(uri, data=data)
|
||||
for idx in resultRunningConfig:
|
||||
if 'config' in idx:
|
||||
result = idx['config']
|
||||
break
|
||||
with open(device['hostname']+'.cfg','w') as f:
|
||||
f.write(result)
|
||||
except Exception as e:
|
||||
print("Not able to get configuration for device {} - exception {}".format(device['fqdn'], e))
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2021 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
# Create connection to CloudVision
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username="username",password="password")
|
||||
|
||||
inventory = clnt.api.get_inventory()
|
||||
|
||||
devices = []
|
||||
for netelement in inventory:
|
||||
devices.append(netelement['systemMacAddress'])
|
||||
|
||||
# Remove devices from provisioning
|
||||
# This is a legacy API call that removes the devices from Network Provisioning
|
||||
# in CVP versions older than 2021.3.0, however it does not remove them from
|
||||
# the Device Inventory as that requires the streaming agent (TerminAttr) to be shutdown,
|
||||
# which this API does not support.
|
||||
# To fully decommission a device the device_decommissioning() API can be used, which is
|
||||
# supported from 2021.3.0+.
|
||||
# Note that using the delete_devices() function post CVP 2021.3.0 the device will be
|
||||
# automatically added back to the Undefined container.
|
||||
clnt.api.delete_devices(devices)
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2022 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
import uuid
|
||||
import time
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
# Create connection to CloudVision
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username="username", password="password")
|
||||
|
||||
device_id = input("Serial number of the device to be decommissioned: ")
|
||||
request_id = str(uuid.uuid4())
|
||||
clnt.api.device_decommissioning(device_id, request_id)
|
||||
|
||||
# This API call will fully decommission the device, ie remove it from both
|
||||
# Network Provisioning and Device Inventory (telemetry). It send an eAPI request
|
||||
# to EOS to shutdown the TerminAttr daemon, waits for streaming to stop and then removes
|
||||
# the device from provisioning and finally decommissions it. This operation can take a few minutes.
|
||||
# Supported from CVP 2021.3.0+ and CVaaS.
|
||||
decomm_status = "DECOMMISSIONING_STATUS_SUCCESS"
|
||||
decomm_result = ""
|
||||
while decomm_result != decomm_status:
|
||||
decomm_result = clnt.api.device_decommissioning_status_get_one(request_id)['value']['status']
|
||||
time.sleep(10)
|
||||
|
||||
print(decomm_result)
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2021 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
# Create connection to CloudVision
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username="username",password="password")
|
||||
|
||||
# Get devices in a specific container
|
||||
inventory = clnt.api.get_devices_in_container("Undefined")
|
||||
|
||||
# Create device list
|
||||
devices = []
|
||||
for netelement in inventory:
|
||||
devices.append(netelement['systemMacAddress'])
|
||||
|
||||
# Remove devices from provisioning
|
||||
# This is a legacy API call that removes the devices from Network Provisioning
|
||||
# in CVP versions older than 2021.3.0, however it does not remove them from
|
||||
# the Device Inventory as that requires the streaming agent (TerminAttr) to be shutdown,
|
||||
# which this API does not support.
|
||||
# To fully decommission a device the device_decommissioning() API can be used, which is
|
||||
# supported from 2021.3.0+.
|
||||
# Note that using the delete_devices() function post CVP 2021.3.0 the device will be
|
||||
# automatically added back to the Undefined container.
|
||||
clnt.api.delete_devices(devices)
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2021 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the COPYING file.
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
# Create connection to CloudVision using Service account token
|
||||
with open("token.tok") as f:
|
||||
token = f.read().strip('\n')
|
||||
|
||||
clnt = CvpClient()
|
||||
clnt.connect(nodes=['cvp1'], username='', password='', api_token=token)
|
||||
|
||||
devices = ["50:08:00:a7:ca:c3","50:08:00:b1:5b:0b","50:08:00:60:c6:76",
|
||||
"50:08:00:25:9d:36","50:08:00:8b:ee:b1","50:08:00:8c:22:49"]
|
||||
|
||||
# Remove devices from provisioning
|
||||
# This is a legacy API call that removes the devices from Network Provisioning
|
||||
# in CVP versions older than 2021.3.0, however it does not remove them from
|
||||
# the Device Inventory as that requires the streaming agent (TerminAttr) to be shutdown,
|
||||
# which this API does not support.
|
||||
# To fully decommission a device the device_decommissioning() API can be used, which is
|
||||
# supported from 2021.3.0+.
|
||||
# Note that using the delete_devices() function post CVP 2021.3.0 the device will be
|
||||
# automatically added back to the Undefined container.
|
||||
clnt.api.delete_devices(devices)
|
Loading…
Add table
Add a link
Reference in a new issue