-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudgenix_commands.py
84 lines (64 loc) · 2.56 KB
/
cloudgenix_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
"""
Description:
Script to send commands to CloudGenix ION devices.
Caveats:
Netmiko has limited support for CloudGenix so you may notice undesired behavior.
Please refrain from using configuration commands until further testing has been performed.
Usage:
:param host: filter for a host
:param site: filter for a site
:param region: filter for a region
➜ docker run --rm -it -v $(pwd):/nornir nornir cloudgenix_commands.py --host usstecgs02
--------------------------------------------------------------------------------
Enter a command: dump device status
--------------------------------------------------------------------------------
Progress: 100%|██████████████████████████████████████████| 1/1 [00:05<00:00, 5.12s/it]
exec****************************************************************************
* usstecgs02 ** changed : False ************************************************
vvvv exec ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
---- Send exec commands. ** changed : False ------------------------------------ INFO
Uptime : 2873h21m39.34s
Device ID : 70-001580-7047
Registration State : Assigned
Registration Name : USSTECGS02
Description :
Element ID : 15532320979890243
Site ID : 15532325637320121
Role : SPOKE
Tenant ID : 98020
Site Mode : in-path
Site State : active
HA State : active
^^^^ END exec ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"""
from nornir import InitNornir
from nornir.plugins.tasks.networking import netmiko_send_command
from nornir.plugins.functions.text import print_result
from tqdm import tqdm
from nornir_utilities import get_creds, get_args
nr = InitNornir(config_file="config.yaml")
def exec(task, t, cmds):
get_creds(nr)
for cmd in cmds:
# Task to send exec commands.
task.run(
name=f"{cmd}", task=netmiko_send_command, command_string=cmd
)
t.update()
args = get_args()
if args.host:
hosts = nr.filter(hostname=args.host, platform="cloudgenix_ion")
elif args.site:
hosts = nr.filter(site=args.site, platform="cloudgenix_ion")
elif args.region:
hosts = nr.filter(region=args.region, platform="cloudgenix_ion")
else:
hosts = nr.filter(platform="cloudgenix_ion")
print("-" * 80)
commands = input("Enter command(s): ")
print("-" * 80)
cmds = commands.split(",")
with tqdm(total=len(hosts.inventory.hosts), desc="Progress") as t:
result = hosts.run(task=exec, t=t, cmds=cmds)
print_result(result)