-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
executable file
·163 lines (125 loc) · 4.76 KB
/
controller.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
#!/usr/bin/env python3
"""
NAME: controller.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 subprocess
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")
class controller:
def __init__(self,
controller_module=None
):
if controller_module is None:
raise ValueError('Controller module needs to be set')
else:
self.controller_module = controller_module
self.series_module = importlib.import_module(self.controller_module)
self.series_obj = None
# this will create the controller object
def create_series_obj(
scheme=None,
dest=None,
user=None,
passwd=None,
prompt=None,
series=None,
band=None,
ap=None,
port=None,
timeout=None
):
self.series_obj = self.series_module.create_controller_series_object(
scheme=scheme,
dest=dest,
user=user,
passwd=passwd,
prompt=prompt,
series=series,
ap=ap,
port=port,
band=band,
timeout=timeout)
# unit test for controller wrapper
def main():
# arguments
parser = argparse.ArgumentParser(
prog='controller.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
controller.py: wrapper for interface to a series of controllers
''',
description='''\
NAME: controller.py
PURPOSE:
wrapper class to provide common interface to a various series of 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
---------
''')
# ./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("--series_module", type=str, help="series module", required=True)
# These commands are just needed to interact it can be done in class methods.abs(
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)
parser.add_argument("--module", type=str, help="series module", required=True)
args = parser.parse_args()
# set up logger
logger_config = lf_logger_config.lf_logger_config()
# create controller object for specific series
series = importlib.import_module(args.module)
cc = series.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)
cc.show_ap_config_slots()
# cc.show_ap_summary()
# cc.no_logging_console()
# cc.line_console_0()
# cc.show_wlan_summary()
# cc.show_ap_dot11_5gz_summary()
if __name__ == "__main__":
main()