-
Notifications
You must be signed in to change notification settings - Fork 25
/
cc_9800_3504.py
executable file
·273 lines (225 loc) · 9.71 KB
/
cc_9800_3504.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env python3
# flake8: noqa
"""
NAME: cc_9800_3504.py
PURPOSE:
wrapper class to provide common interface to a controller,
class methods will hold login information and common commands
SETUP:
None
EXAMPLE:
There is a unit test included to try sample command scenarios
COPYRIGHT:
Copyright 2021 Candela Technologies Inc
License: Free to distribute and modify. LANforge systems must be licensed.
INCLUDE_IN_README
"""
import sys
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit()
import argparse
import logging
import importlib
import os
import subprocess
from pprint import pformat
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../")))
logger = logging.getLogger(__name__)
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
# This name must be generic.
class create_controller_series_object:
def __init__(self,
scheme=None,
dest=None,
user=None,
passwd=None,
prompt=None,
series=None,
band=None,
ap=None,
port=None,
timeout=None
):
if scheme is None:
raise ValueError('Controller scheme must be set: serial, ssh or telnet')
else:
self.scheme = scheme
if dest is None:
raise ValueError('Controller dest must be set: and IP or localhost')
else:
self.dest = dest
if user is None:
raise ValueError('Controller user must be set')
else:
self.user = user
if passwd is None:
raise ValueError('Controller passwd must be set')
else:
self.passwd = passwd
if prompt is None:
raise ValueError('Controller prompt must be set: WLC1')
else:
self.prompt = prompt
if series is None:
raise ValueError('Controller series must be set: 9800 or 3504')
else:
self.series = series
if ap is None:
raise ValueError('Controller AP must be set')
else:
self.ap = ap
if band is None:
raise ValueError('Controller band must be set')
else:
self.band = band
if port is None:
raise ValueError('Controller port must be set')
else:
self.port = port
if timeout is None:
logger.info("timeout not set default to 10 sec")
self.timeout = '10'
else:
self.timeout = timeout
self.bandwidth = None
self.wlanSSID = None
self.wlanpw = None
self.tag_policy = None
self.policy_profile = None
self.tx_power = None
self.channel = None
self.bandwidth = None
self.action = None
self.value = None
self.command = []
self.info = "Cisco 9800 Controller Series"
# TODO update the wifi_ctl_9800_3504 to use 24g, 5g, 6g
def convert_band(self):
if self.band == '24g':
self.band = 'b'
elif self.band == '5g':
self.band = 'a'
elif self.band == '6g':
self.band = '6g'
elif self.band == 'a' or self.band == 'b':
pass
else:
logger.critical("band needs to be set 24g 5g or 6g")
raise ValueError("band needs to be set 24g 5g or 6g")
def send_command(self):
# for backward compatibility wifi_ctl_9800_3504 expects 'a' for 5g and 'b' for 24b
self.convert_band()
# Generate command
if self.action == 'cmd':
logger.debug("action {action}".format(action=self.action))
logger.info(("./wifi_ctl_9800_3504.py --scheme {scheme} --dest {dest} --user {user} --passwd {passwd} --ap {ap} --band {band}"
" --action {action} --value {value} --series {series} --port {port} --prompt {prompt}").format(
scheme=self.scheme, dest=self.dest, user=self.user, passwd=self.passwd, ap=self.ap, band=self.band,
action=self.action, value=self.value, series=self.series, port=self.port, prompt=self.prompt))
self.command = ["./wifi_ctl_9800_3504.py", "--scheme", self.scheme, "--dest", self.dest,
"--user", self.user, "--passwd", self.passwd, "--ap", self.ap, "--band", self.band,
"--action", self.action, "--value", self.value, "--series", self.series, "--port", self.port, "--prompt", self.prompt]
else:
logger.debug("action {action}".format(action=self.action))
logger.info(("./wifi_ctl_9800_3504.py --scheme {scheme} --dest {dest} --user {user} --passwd {passwd} --ap {ap} --band {band}"
" --action {action} --series {series} --port {port} --prompt {prompt}").format(
scheme=self.scheme, dest=self.dest, user=self.user, passwd=self.passwd, ap=self.ap, band=self.band,
action=self.action, series=self.series, port=self.port, prompt=self.prompt))
self.command = ["./wifi_ctl_9800_3504.py", "--scheme", self.scheme, "--dest", self.dest,
"--user", self.user, "--passwd", self.passwd, "--ap", self.ap, "--band", self.band,
"--action", self.action, "--series", self.series, "--port", self.port, "--prompt", self.prompt]
logger.info(self.command)
# for now do not capture all the output, have the logger to the work
advanced = subprocess.run(self.command, capture_output=False, check=True)
# advanced = subprocess.run(self.command, capture_output=True, check=True) if need to capture output and process
def show_ap_config_slots(self):
logger.info("show ap config slots")
self.action = "cmd"
self.value = "show ap config slots"
self.send_command()
def show_ap_summary(self):
logger.info("show ap summary")
self.action = "summary"
self.send_command()
# this command will disable debug logging to the terminal which causes issues with pexpect
def no_logging_console(self):
logger.info("no_logging_console")
self.action = "no_logging_console"
self.send_command()
# The use of "line console 0" command is to connect a switch/router through medium console.
# If there is only one console port, you can only choose "line console 0".
# However if you have more than the number goes as 1,2,3,4 ... You can set different or same password to all your console ports.
# Note: needed to be set for tx power script
def line_console_0(self):
logger.info("line_console_0")
self.action = "line_console_0"
self.send_command()
def show_wlan_summary(self):
logger.info("show_wlan_summary")
self.action = "show_wlan_summary"
self.send_command()
def show_ap_dot11_5gz_summary(self):
logger.info("show_ap_dot11_5gz_summary")
# TODO advanced was for legacy to 3504, refactor
self.action = "advanced"
self.send_command()
# unit test for 9800 3504 controller
def main():
# arguments
parser = argparse.ArgumentParser(
prog='cc_9800_3504.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
cc_9800_3504.py: wrapper for interface to a controller library
''',
description='''\
NAME: cc_9800_3504.py
PURPOSE:
wrapper class to provide common interface to a controller,
class methods will hold login information and common commands
SETUP:
None
EXAMPLE:
There is a unit test included to try sample command scenarios
COPYWRITE
Copyright 2021 Candela Technologies Inc
License: Free to distribute and modify. LANforge systems must be licensed.
INCLUDE_IN_README
---------
''')
# sample command
# ./wifi_ctl_9800_3504.py --scheme ssh --dest localhost --port 8887 --user admin --passwd Cisco123 --ap APA453.0E7B.CF9C --series 9800 --action cmd --value "show ap config slots" --prompt "WLC1" --timeout 10
# ./cc_9800_3504.py --scheme ssh --dest localhost --port 8887 --user admin --passwd Cisco123 --ap APA453.0E7B.CF9C --series 9800 --prompt "WLC1" --timeout 10
parser.add_argument("--dest", type=str, help="address of the cisco controller", required=True)
parser.add_argument("--port", type=str, help="control port on the controller", required=True)
parser.add_argument("--user", type=str, help="credential login/username", required=True)
parser.add_argument("--passwd", type=str, help="credential password", required=True)
parser.add_argument("--ap", type=str, help="ap name APA453.0E7B.CF9C", required=True)
parser.add_argument("--prompt", type=str, help="controller prompt", required=True)
parser.add_argument("--band", type=str, help="band to test 24g, 5g, 6g", required=True)
parser.add_argument("--series", type=str, help="controller series", choices=["9800","3504"], required=True)
parser.add_argument("--scheme", type=str, choices=["serial", "ssh", "telnet"], help="Connect via serial, ssh or telnet")
parser.add_argument("--timeout", type=str, help="timeout value", default=3)
args = parser.parse_args()
# set up logger
logger_config = lf_logger_config.lf_logger_config()
cs = create_controller_series_object(
scheme=args.scheme,
dest=args.dest,
user=args.user,
passwd=args.passwd,
prompt=args.prompt,
series=args.series,
ap=args.ap,
port=args.port,
band=args.band,
timeout=args.timeout)
# cs.show_ap_config_slots()
# cs.show_ap_summary()
# cs.no_logging_console()
# cs.line_console_0()
cs.show_wlan_summary()
cs.show_ap_dot11_5gz_summary()
if __name__ == "__main__":
main()