-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaci-shell.py
More file actions
executable file
·170 lines (150 loc) · 5.81 KB
/
aci-shell.py
File metadata and controls
executable file
·170 lines (150 loc) · 5.81 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
import argparse
import cmd2
import app.util
import app.aci
session = None
class ACIshell(cmd2.Cmd):
def __init__(self):
super().__init__()
self.intro = (
"Welcome to the ACI shell \nPlease login" + ' with "connect -u [username]"'
)
self.prompt = ">>> "
# -------------------------------------------------------------------------
# Section for connection commands
connect_parser = argparse.ArgumentParser()
connect_parser.add_argument(
"-u", "--username", dest="username", help="User for APIC login"
)
connect_args = connect_parser.parse_args()
@cmd2.with_argparser(connect_parser)
def do_connect(self, args):
""" Connect to APIC """
global session
if args.username is not None:
user = args.username
session = app.aci.apic_login(user)
else:
print(
"Error: Username arguement is required." 'Example: "connect -u admin"'
)
disconnect_parser = argparse.ArgumentParser()
disconnect_args = disconnect_parser.parse_args()
@cmd2.with_argparser(disconnect_parser)
def do_disconnect(self, args):
""" Disconnect from APIC """
global session
app.util.check_session(session)
app.aci.apic_logout(session)
# -------------------------------------------------------------------------
# Section for show commands
# show epg all
show_epg_all_parser = argparse.ArgumentParser()
show_epg_all_parser.add_argument(
"-e", "--export", dest="filename", help="export report to file"
)
show_epg_all_args = show_epg_all_parser.parse_args()
@cmd2.with_argparser(show_epg_all_parser)
def do_show_epg_all(self, args):
""" Show all EPGs from all tenants"""
global session
app.util.check_session(session)
if args.filename is not None:
report_dir = app.util.read_config(section="common", setting="report_dir")
filename = report_dir + args.filename
app.aci.show_epg_all(session=session, filename=filename)
else:
app.aci.show_epg_all(session=session, filename="")
# show interface status
show_interface_status_parser = argparse.ArgumentParser()
show_interface_status_parser.add_argument(
"-e", "--export", dest="filename", help="export report to file"
)
show_interface_status_parser.add_argument(
"-p", "--pod-id", dest="pod_id", help="POD-ID"
)
show_interface_status_parser.add_argument(
"-n", "--node-id", dest="node_id", help="Node-ID"
)
show_interface_status_args = show_interface_status_parser.parse_args()
@cmd2.with_argparser(show_interface_status_parser)
def do_show_interface_status(self, args):
""" Show interface status for fabric node """
global session
app.util.check_session(session)
if args.pod_id or args.node_id is not None:
pod_id = args.pod_id
node_id = args.node_id
if args.filename is not None:
report_dir = app.util.read_config(
section="common", setting="report_dir"
)
filename = report_dir + args.filename
app.aci.show_interface_status(
session=session, pod_id=pod_id, node_id=node_id, filename=filename
)
else:
app.aci.show_interface_status(
session=session, pod_id=pod_id, node_id=node_id, filename=""
)
else:
print(
"Error: pod-id and node-id arguements are required \n"
'Example: "show_interface_status -p 1 -n 101"'
)
# show interface epg
show_interface_epg_parser = argparse.ArgumentParser()
show_interface_epg_parser.add_argument(
"-e", "--export", dest="filename", help="export report to file"
)
show_interface_epg_parser.add_argument(
"-p", "--pod-id", dest="pod_id", help="POD-ID"
)
show_interface_epg_parser.add_argument(
"-n", "--node-id", dest="node_id", help="Node-ID"
)
show_interface_epg_parser.add_argument(
"-i", "--interface", dest="interface", help="Interface"
)
show_interface_epg_args = show_interface_epg_parser.parse_args()
@cmd2.with_argparser(show_interface_epg_parser)
def do_show_interface_epg(self, args):
""" Show deployed EPGs on a specific fabric node interface """
global session
app.util.check_session(session)
if args.pod_id or args.node_id or args.interface is not None:
pod_id = args.pod_id
node_id = args.node_id
interface = args.interface
if args.filename is not None:
report_dir = app.util.read_config(
section="common", setting="report_dir"
)
filename = report_dir + args.filename
app.aci.show_interface_deployed_epg(
session=session,
pod_id=pod_id,
node_id=node_id,
interface=interface,
filename=filename,
)
else:
app.aci.show_interface_deployed_epg(
session=session,
pod_id=pod_id,
node_id=node_id,
interface=interface,
filename="",
)
else:
print(
"Error: pod-id, node-id and interface arguements are"
"required"
'Example: "show_interface_epg -p 1 -n 201 - i eth1/17"'
)
if __name__ == "__main__":
application = ACIshell()
application.default_to_shell = True
application.precmd(app.aci.set_apic_url())
application.cmdloop()