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
|
@ -0,0 +1,23 @@
|
|||
# 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")
|
||||
|
||||
configletName = 'cvprac_example2'
|
||||
|
||||
device_name = "tp-avd-leaf1"
|
||||
device = clnt.api.get_device_by_name(device_name)
|
||||
|
||||
configlet = clnt.api.get_configlet_by_name(configletName)
|
||||
|
||||
clnt.api.apply_configlets_to_device("", device, [configlet])
|
20
docs/labs/lab03-configlet-management/backup_configlets.py
Normal file
20
docs/labs/lab03-configlet-management/backup_configlets.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# 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.
|
||||
#
|
||||
# Get configlets and save them to individual files
|
||||
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(['cvp1'],'username', 'password')
|
||||
|
||||
configlets = clnt.api.get_configlets(start=0,end=0)
|
||||
|
||||
for configlet in configlets['data']:
|
||||
with open(configlet['name'],'w') as f:
|
||||
f.write(configlet['config'])
|
48
docs/labs/lab03-configlet-management/backup_configletsV2.py
Normal file
48
docs/labs/lab03-configlet-management/backup_configletsV2.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
# 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.
|
||||
#
|
||||
# Get configlets and save them to individual files using multi threading
|
||||
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()
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from functools import wraps
|
||||
|
||||
# Create connection to CloudVision
|
||||
clnt = CvpClient()
|
||||
clnt.connect(['cvp1'],'username', 'password')
|
||||
|
||||
total = clnt.api.get_configlets(start=0,end=1)['total']
|
||||
|
||||
def get_list_of_configlets():
|
||||
"""
|
||||
Create a thread pool and download specified urls
|
||||
"""
|
||||
|
||||
futures_list = []
|
||||
results = []
|
||||
|
||||
with ThreadPoolExecutor(max_workers=40) as executor:
|
||||
for i in range(0,total+1,10):
|
||||
futures = executor.submit(clnt.api.get_configlets, start=i,end=i+10)
|
||||
futures_list.append(futures)
|
||||
|
||||
for future in futures_list:
|
||||
try:
|
||||
result = future.result(timeout=60)
|
||||
results.append(result)
|
||||
except Exception:
|
||||
results.append(None)
|
||||
print(future.result())
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
results = get_list_of_configlets()
|
||||
for future in results:
|
||||
for configlet in future['data']:
|
||||
with open(configlet['name'],'w') as f:
|
||||
f.write(configlet['config'])
|
6
docs/labs/lab03-configlet-management/common.cfg
Normal file
6
docs/labs/lab03-configlet-management/common.cfg
Normal file
|
@ -0,0 +1,6 @@
|
|||
!
|
||||
ip name-server vrf management 1.1.1.1
|
||||
ip name-server vrf management 8.8.8.8
|
||||
!
|
||||
ntp server vrf management time.google.com
|
||||
!
|
54
docs/labs/lab03-configlet-management/config_search.py
Normal file
54
docs/labs/lab03-configlet-management/config_search.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# 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
|
||||
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")
|
||||
|
||||
def main():
|
||||
|
||||
print('Retrieving configlets ...')
|
||||
|
||||
inventory = clnt.api.get_inventory()
|
||||
data = clnt.api.get_configlets_and_mappers()['data']
|
||||
print(data)
|
||||
|
||||
print('Number of configlets:', len(data['configlets']))
|
||||
|
||||
searchAgain = True
|
||||
while searchAgain:
|
||||
try:
|
||||
search = input( "\nEnter Config Line: " )
|
||||
print(f"\n\n\'{search}\' has been found in following configlets:\n\n")
|
||||
print(f"{'Hostname':<30}{'Serial number':<50}{'MAC address':<30}{'Configlets':<40}")
|
||||
print("=" * 150)
|
||||
for i in inventory:
|
||||
device = i['hostname']
|
||||
device_sn = i['serialNumber']
|
||||
device_mac = i['systemMacAddress']
|
||||
configlet_list = []
|
||||
for c in data['configlets']:
|
||||
for g in data['generatedConfigletMappers']:
|
||||
if device_mac == g['netElementId'] and c['key'] == g['configletBuilderId'] and search in c['config']:
|
||||
configlet_list.append(c['name'])
|
||||
for k in data['configletMappers']:
|
||||
if device_mac == k['objectId'] and c['key'] == k['configletId'] and search in c['config']:
|
||||
configlet_list.append(c['name'])
|
||||
configlet_list_final = ",".join(configlet_list)
|
||||
if len(configlet_list) > 0:
|
||||
print(f"{device:<30}{device_sn:<50}{device_mac:<30}{configlet_list_final:<30}")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print('\nExiting... \n')
|
||||
return
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
6
docs/labs/lab03-configlet-management/configlet_list.txt
Normal file
6
docs/labs/lab03-configlet-management/configlet_list.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
tp-avd_tp-avd-leaf1
|
||||
tp-avd_tp-avd-leaf2
|
||||
tp-avd_tp-avd-leaf3
|
||||
tp-avd_tp-avd-leaf4
|
||||
tp-avd_tp-avd-spine1
|
||||
tp-avd_tp-avd-spine2
|
24
docs/labs/lab03-configlet-management/create_configlet.py
Normal file
24
docs/labs/lab03-configlet-management/create_configlet.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# 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")
|
||||
|
||||
configletName = "cvprac_example"
|
||||
|
||||
configlet = """!
|
||||
interface Ethernet10
|
||||
description test
|
||||
ip address 10.144.144.1/24
|
||||
!
|
||||
"""
|
||||
|
||||
clnt.api.add_configlet(configletName,configlet)
|
|
@ -0,0 +1,19 @@
|
|||
# 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")
|
||||
|
||||
configletName = "cvprac_example2"
|
||||
|
||||
with open("common.cfg") as file:
|
||||
configlet = file.read()
|
||||
clnt.api.add_configlet(configletName, configlet)
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2023 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 argparse
|
||||
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")
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Get the list of devices and containers a configlet is attached to')
|
||||
parser.add_argument('-c', '--configlet', required=True, help='The name of the configlet')
|
||||
args = parser.parse_args()
|
||||
|
||||
configlet_name = args.configlet
|
||||
devices = clnt.api.get_applied_devices(configlet_name)
|
||||
|
||||
containers = clnt.api.get_applied_containers(configlet_name)
|
||||
print(f"Total number of devices {configlet_name} is attached to: {devices['total']}\n")
|
||||
print(f"Total number of containers {configlet_name} is attached to: {containers['total']}\n")
|
||||
col1 = "Device FQDN/hostname"
|
||||
col2 = "IP Address"
|
||||
print(f"{col1:<40}{col2:<40}")
|
||||
print("="*80)
|
||||
for device in devices['data']:
|
||||
print(f"{device['hostName']:<40}{device['ipAddress']}")
|
||||
|
||||
print("\nList of containers:\n")
|
||||
for container in containers['data']:
|
||||
print(container['containerName'])
|
53
docs/labs/lab03-configlet-management/get_configlets.py
Normal file
53
docs/labs/lab03-configlet-management/get_configlets.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# 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.
|
||||
#
|
||||
# Get list of configlets in parallel
|
||||
|
||||
from cvprac.cvp_client import CvpClient
|
||||
import ssl
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
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")
|
||||
|
||||
import time
|
||||
from functools import wraps
|
||||
|
||||
def get_list_of_configlets(configlets):
|
||||
"""
|
||||
Create a thread pool and download specified urls
|
||||
"""
|
||||
|
||||
futures_list = []
|
||||
results = []
|
||||
|
||||
with ThreadPoolExecutor(max_workers=40) as executor:
|
||||
for configlet in configlets:
|
||||
futures = executor.submit(clnt.api.get_configlet_by_name, configlet)
|
||||
futures_list.append(futures)
|
||||
|
||||
for future in futures_list:
|
||||
try:
|
||||
result = future.result(timeout=60)
|
||||
results.append(result)
|
||||
except Exception:
|
||||
results.append(None)
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example with pre-defined list
|
||||
configlets = ["tp-avd_tp-avd-leaf1","tp-avd_tp-avd-leaf2","tp-avd_tp-avd-leaf3","tp-avd_tp-avd-leaf4"]
|
||||
|
||||
# Example with loading list of configlets from a file
|
||||
# with open("configlet_list.txt") as f:
|
||||
# configlets = f.read().splitlines()
|
||||
|
||||
results = get_list_of_configlets(configlets)
|
||||
for result in results:
|
||||
print(result)
|
|
@ -0,0 +1,26 @@
|
|||
# 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")
|
||||
|
||||
configletNames = ['tp-avd_tp-avd-leaf1','vlan144','api_models']
|
||||
|
||||
device_name = "tp-avd-leaf1"
|
||||
device = clnt.api.get_device_by_name(device_name)
|
||||
|
||||
configlets = []
|
||||
|
||||
for name in configletNames:
|
||||
configlets.append(clnt.api.get_configlet_by_name(name))
|
||||
|
||||
# Apply configlets in the order specified in the list
|
||||
clnt.api.apply_configlets_to_device("", device, configlets, reorder_configlets=True)
|
28
docs/labs/lab03-configlet-management/update_configlet.py
Normal file
28
docs/labs/lab03-configlet-management/update_configlet.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# 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")
|
||||
|
||||
# Modify existing configlet
|
||||
|
||||
configletName = "cvprac_example"
|
||||
|
||||
configlet = """!
|
||||
interface Ethernet10
|
||||
description DUB_R04
|
||||
ip address 10.144.144.2/24
|
||||
!
|
||||
"""
|
||||
|
||||
configletID = clnt.api.get_configlet_by_name(configletName)['key']
|
||||
|
||||
clnt.api.update_configlet( configlet, configletID, configletName)
|
Loading…
Add table
Add a link
Reference in a new issue