| 1 |
# Copyright (c) 2023 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 |
import argparse |
| 8 |
ssl._create_default_https_context = ssl._create_unverified_context |
| 9 |
import requests.packages.urllib3 |
| 10 |
requests.packages.urllib3.disable_warnings() |
| 11 |
|
| 12 |
# Create connection to CloudVision |
| 13 |
clnt = CvpClient() |
| 14 |
clnt.connect(nodes=['cvp1'], username="username", password="password") |
| 15 |
|
| 16 |
parser = argparse.ArgumentParser( |
| 17 |
description='Get the list of devices and containers a configlet is attached to') |
| 18 |
parser.add_argument('-c', '--configlet', required=True, help='The name of the configlet') |
| 19 |
args = parser.parse_args() |
| 20 |
|
| 21 |
configlet_name = args.configlet |
| 22 |
devices = clnt.api.get_applied_devices(configlet_name) |
| 23 |
|
| 24 |
containers = clnt.api.get_applied_containers(configlet_name) |
| 25 |
print(f"Total number of devices {configlet_name} is attached to: {devices['total']}\n") |
| 26 |
print(f"Total number of containers {configlet_name} is attached to: {containers['total']}\n") |
| 27 |
col1 = "Device FQDN/hostname" |
| 28 |
col2 = "IP Address" |
| 29 |
print(f"{col1:<40}{col2:<40}") |
| 30 |
print("="*80) |
| 31 |
for device in devices['data']: |
| 32 |
print(f"{device['hostName']:<40}{device['ipAddress']}") |
| 33 |
|
| 34 |
print("\nList of containers:\n") |
| 35 |
for container in containers['data']: |
| 36 |
print(container['containerName']) |