-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathlf_modify_radio.py
More file actions
executable file
·279 lines (237 loc) · 11.6 KB
/
lf_modify_radio.py
File metadata and controls
executable file
·279 lines (237 loc) · 11.6 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
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
274
275
276
277
278
279
#!/usr/bin/env python3
"""
NAME: lf_modify_radio.py
PURPOSE: Set the spatial streams and channel of a radio
To Modify eth interface such as enabling/disabling dhcp
EXAMPLE:
$ ./lf_modify_radio.py --host 192.168.100.205 --radio "1.1.wiphy0" --channel 36 --antenna 7 --debug
to enable dhcp-ipv4 on eth interface :
./ python3 lf_modify_radio.py --mgr 192.168.200.105 --radio 1.1.eth2 --enable_dhcp True
to disable dhcp-ipv4 on eth interface and provide static ip from arguement parsers
./ python3 lf_modify_radio.py --mgr 192.168.200.105 --radio 1.1.eth2 --static True
NOTES:
TO DO NOTES:
"""
import os
import sys
import importlib
import argparse
import logging
if sys.version_info[0] != 3:
print("This script requires Python3")
exit()
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
lanforge_api = importlib.import_module("lanforge_client.lanforge_api")
from lanforge_client.lanforge_api import LFSession # noqa E402
from lanforge_client.lanforge_api import LFJsonCommand # noqa E402
from lanforge_client.lanforge_api import LFJsonQuery # noqa E402
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
logger = logging.getLogger(__name__)
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- #
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- #
# http://www.candelatech.com/lfcli_ug.php#set_wifi_radio
class lf_modify_radio():
def __init__(self,
lf_mgr=None,
lf_port=8080,
lf_user=None,
lf_passwd=None,
debug=False,
static_ip=None,
ip_mask=None,
gateway_ip=None,
session=None):
self.lf_mgr = lf_mgr
self.lf_port = lf_port
self.lf_user = lf_user
self.lf_passwd = lf_passwd
self.debug = debug
self.static_ip = static_ip
self.ip_mask = ip_mask
self.gateway_ip = gateway_ip
if not session:
self.session = LFSession(lfclient_url="http://%s:8080" % self.lf_mgr,
debug=debug,
connection_timeout_sec=4.0,
stream_errors=True,
stream_warnings=True,
require_session=True,
exit_on_error=True)
# type hinting
self.command: LFJsonCommand
self.command = self.session.get_command()
self.query: LFJsonQuery
self.query = self.session.get_query()
# TODO make a set wifi radio similiar to add_profile
def set_wifi_radio(self,
_resource=None,
_radio=None,
_shelf=None,
_antenna=None,
_channel=None,
_txpower=None,
_country_code=None,
_flags=None):
country_num = _country_code
if _country_code:
if isinstance(_country_code, str) and _country_code.isnumeric():
country_num = int(_country_code)
elif isinstance(country_num, str) and (country_num in LFUtils.COUNTRY_CODES_NUMBERS):
country_num = LFUtils.COUNTRY_CODES_NUMBERS[_country_code]
self.command.post_set_wifi_radio(resource=_resource,
radio=_radio,
shelf=_shelf,
antenna=_antenna,
channel=_channel,
txpower=_txpower,
country=_country_code,
flags=_flags,
debug=self.debug)
def enable_dhcp_eth(self, interface="1.1.eth2"):
port_ = interface.split(".")
self.command.post_set_port(shelf=port_[0],
resource=port_[1],
port=port_[2],
current_flags="2147483648",
interest="8552366080",
debug=self.debug)
def disable_dhcp_static(self, interface):
port_ = interface.split(".")
self.command.post_set_port(shelf=port_[0],
resource=port_[1],
port=port_[2],
ip_addr=self.static_ip,
netmask=self.ip_mask,
gateway=self.gateway_ip,
interest="8552366108",
debug=self.debug)
def main():
help_summary = '''\
This script is designed to modify/adjust the settings of the radio's standard configuration. It allows you to easily
modify basic settings like the Country code, Channel/Frequency, Antenna, TX Power, and more. Additionally, the script
can activate or deactivate various features such as Extra TxStatus and Extra RxStatus for the specified radio.
'''
parser = argparse.ArgumentParser(
prog=__file__,
formatter_class=argparse.RawTextHelpFormatter,
description='''
modifies radio configuration , antenna, radio, channel or txpower
lf_modify_radio.py --mgr 192.168.0.104 --radio 1.1.wiphy6 --txpower 17 --debug
''')
parser.add_argument("--host", "--mgr", dest='mgr',
help='specify the GUI to connect to')
parser.add_argument("--mgr_port",
help="specify the GUI to connect to, default 8080", default="8080")
parser.add_argument("--lf_user",
help="lanforge user name, default : lanforge", default="lanforge")
parser.add_argument("--lf_passwd",
help="lanforge password, default : lanforge", default="lanforge")
parser.add_argument("--radio",
help='name of the radio to modify: e.g. 1.1.wiphy0')
parser.add_argument("--antenna",
help='number of spatial streams: 0 Diversity (All), 1 Fixed-A (1x1), 4 AB (2x2), 7 ABC (3x3), 8 ABCD (4x4), 9 (8x8) default = -1',
default='-1')
parser.add_argument("--channel",
help='channel of the radio: e.g. 6 (2.4G) or 36 (5G) default: AUTO',
default='AUTO')
parser.add_argument("--txpower",
help='radio tx power default: AUTO system defaults',
default='AUTO')
country_code_list: list = list(LFUtils.COUNTRY_CODES_NUMBERS.keys())
country_code_list.extend([str(x) for x in LFUtils.COUNTRY_CODES_NUMBERS.values()])
parser.add_argument("--country", "--regdom", "--country_code",
choices=country_code_list,
help="Set the country code for the lanforge resource. "
"This needs to set all radios on the resource to the same country code. "
"Requires --radio (eg 1.1.wiphy0) for reference to determine resource.")
# Logging Configuration
parser.add_argument('--log_level', default=None,
help='Set logging level: debug | info | warning | error | critical')
parser.add_argument("--lf_logger_config_json",
help="--lf_logger_config_json <json file> , json configuration of logger")
parser.add_argument('--debug',
help='Legacy debug flag, turnn on legacy debug ',
action='store_true')
parser.add_argument("--enable_dhcp", default=False,
help="set to True if wanted to enbale DHCP-IPv4 on eth interface")
parser.add_argument("--static", default=False,
help="True if client will be created with static ip")
parser.add_argument("--static_ip", default="192.168.2.100",
help="if static option is True provide static ip to client")
parser.add_argument("--ip_mask", default="255.255.255.0",
help="if static is true provide ip mask to client")
parser.add_argument("--gateway_ip", default="192.168.2.50",
help="if static is true provide gateway ip")
parser.add_argument('--help_summary', help='Show summary of what this script does', default=None,
action="store_true")
args = parser.parse_args()
# help summary
if args.help_summary:
print(help_summary)
exit(0)
# set up logger
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to debug
if args.log_level:
logger_config.set_level(level=args.log_level)
# lf_logger_config_json will take presidence to changing debug levels
if args.lf_logger_config_json:
# logger_config.lf_logger_config_json = "lf_logger_config.json"
logger_config.lf_logger_config_json = args.lf_logger_config_json
logger_config.load_lf_logger_config()
if not args.radio:
print("No radio name provided")
exit(1)
modify_radio = lf_modify_radio(lf_mgr=args.mgr,
lf_port=args.mgr_port,
lf_user=args.lf_user,
lf_passwd=args.lf_passwd,
debug=args.debug,
static_ip=args.static_ip,
ip_mask=args.ip_mask,
gateway_ip=args.gateway_ip)
if args.enable_dhcp == "True":
modify_radio.enable_dhcp_eth(interface=args.radio)
elif args.static == "True":
modify_radio.disable_dhcp_static(interface=args.radio)
else:
shelf, resource, radio, *nil = LFUtils.name_to_eid(args.radio)
country_num = None
if args.country:
if args.country.isnumeric():
country_num = int(args.country)
elif args.country in LFUtils.COUNTRY_CODES_NUMBERS:
country_num = LFUtils.COUNTRY_CODES_NUMBERS[args.country]
else:
raise ValueError(f"Unknown country code: [{args.country}]")
modify_radio.set_wifi_radio(_resource=resource,
_radio=radio,
_shelf=shelf,
_antenna=args.antenna,
_channel=args.channel,
_txpower=args.txpower,
_country_code=country_num)
'''
session = LFSession(lfclient_url="http://%s:8080" % args.host,
debug=args.debug,
connection_timeout_sec=2.0,
stream_errors=True,
stream_warnings=True,
require_session=True,
exit_on_error=True)
command: LFJsonCommand
command = session.get_command()
query: LFJsonQuery
query = session.get_query()
shelf, resource, radio, *nil = LFUtils.name_to_eid(args.radio)
command.post_set_wifi_radio(resource=resource,
radio=radio,
shelf=shelf,
antenna=args.antenna,
channel=args.channel,
txpower=args.txpower,
debug=args.debug)
'''
if __name__ == "__main__":
main()