mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 19:28:00 +00:00
Create modify_vap.py file, and increase options available in create_vap.py so a user can change the flags on a VAP.
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
@@ -220,7 +220,7 @@ class VAPProfile(LFCliBase):
|
|||||||
for port in port_list:
|
for port in port_list:
|
||||||
for k, v in port.items():
|
for k, v in port.items():
|
||||||
if v['alias'] == self.vap_name:
|
if v['alias'] == self.vap_name:
|
||||||
self.local_realm.rm_port(k, check_exists=True)
|
self.local_realm.rm_port(v['port'], check_exists=True)
|
||||||
if use_ht160:
|
if use_ht160:
|
||||||
self.desired_add_vap_flags.append("enable_80211d")
|
self.desired_add_vap_flags.append("enable_80211d")
|
||||||
self.desired_add_vap_flags_mask.append("enable_80211d")
|
self.desired_add_vap_flags_mask.append("enable_80211d")
|
||||||
@@ -351,6 +351,28 @@ class VAPProfile(LFCliBase):
|
|||||||
if (self.up):
|
if (self.up):
|
||||||
self.admin_up(resource)
|
self.admin_up(resource)
|
||||||
|
|
||||||
|
def modify(self, resource, radio):
|
||||||
|
list_ports = self.local_realm.json_get("/port/1/%s" % resource,
|
||||||
|
debug_=self.debug)
|
||||||
|
for item in list_ports['interfaces']:
|
||||||
|
if self.vap_name == list(item.values())[0]['alias']:
|
||||||
|
url = (list(item.values())[0]['_links'])
|
||||||
|
|
||||||
|
self.add_vap_data["flags"] = self.add_named_flags(self.desired_add_vap_flags, add_vap.add_vap_flags)
|
||||||
|
self.add_vap_data["flags_mask"] = self.add_named_flags(self.desired_add_vap_flags_mask, add_vap.add_vap_flags)
|
||||||
|
self.add_vap_data["radio"] = radio
|
||||||
|
self.add_vap_data["ap_name"] = self.vap_name
|
||||||
|
self.add_vap_data["ssid"] = 'NA'
|
||||||
|
self.add_vap_data["key"] = 'NA'
|
||||||
|
self.add_vap_data['mac'] = 'NA'
|
||||||
|
|
||||||
|
add_vap_r = LFRequest.LFRequest(self.lfclient_url + "/cli-json/add_vap")
|
||||||
|
if self.debug:
|
||||||
|
print(self.add_vap_data)
|
||||||
|
add_vap_r.addPostData(self.add_vap_data)
|
||||||
|
json_response = add_vap_r.jsonPost(self.debug)
|
||||||
|
|
||||||
|
|
||||||
def cleanup(self, resource, delay=0.03):
|
def cleanup(self, resource, delay=0.03):
|
||||||
print("Cleaning up VAPs")
|
print("Cleaning up VAPs")
|
||||||
desired_ports = ["1.%s.%s" % (resource, self.vap_name), "1.%s.br0" % resource]
|
desired_ports = ["1.%s.%s" % (resource, self.vap_name), "1.%s.br0" % resource]
|
||||||
|
@@ -28,11 +28,14 @@ class CreateVAP(Realm):
|
|||||||
_ssid=None,
|
_ssid=None,
|
||||||
_security=None,
|
_security=None,
|
||||||
_password=None,
|
_password=None,
|
||||||
|
_mac=None,
|
||||||
_host=None,
|
_host=None,
|
||||||
_port=None,
|
_port=None,
|
||||||
_vap_list=None,
|
_vap_list=None,
|
||||||
|
_vap_flags=None,
|
||||||
_number_template="00000",
|
_number_template="00000",
|
||||||
_radio="wiphy0",
|
_radio=None,
|
||||||
|
_bridge=False,
|
||||||
_proxy_str=None,
|
_proxy_str=None,
|
||||||
_debug_on=False,
|
_debug_on=False,
|
||||||
_exit_on_error=False,
|
_exit_on_error=False,
|
||||||
@@ -46,23 +49,29 @@ class CreateVAP(Realm):
|
|||||||
self.security = _security
|
self.security = _security
|
||||||
self.password = _password
|
self.password = _password
|
||||||
self.vap_list = _vap_list
|
self.vap_list = _vap_list
|
||||||
|
if _vap_flags is None:
|
||||||
|
self.vap_flags = ["wpa2_enable", "80211u_enable", "create_admin_down"]
|
||||||
|
else:
|
||||||
|
self.vap_flags = _vap_flags
|
||||||
self.radio = _radio
|
self.radio = _radio
|
||||||
self.timeout = 120
|
self.timeout = 120
|
||||||
self.number_template = _number_template
|
self.number_template = _number_template
|
||||||
self.debug = _debug_on
|
self.debug = _debug_on
|
||||||
self.dhcp = _dhcp
|
self.dhcp = _dhcp
|
||||||
|
self.bridge = _bridge
|
||||||
self.vap_profile = self.new_vap_profile()
|
self.vap_profile = self.new_vap_profile()
|
||||||
self.vap_profile.vap_name = self.vap_list
|
self.vap_profile.vap_name = self.vap_list
|
||||||
self.vap_profile.ssid = self.ssid
|
self.vap_profile.ssid = self.ssid
|
||||||
self.vap_profile.security = self.security
|
self.vap_profile.security = self.security
|
||||||
self.vap_profile.ssid_pass = self.password
|
self.vap_profile.ssid_pass = self.password
|
||||||
self.vap_profile.dhcp = self.dhcp
|
self.vap_profile.dhcp = self.dhcp
|
||||||
|
self.vap_profile.desired_add_vap_flags = self.vap_flags + ["wpa2_enable", "80211u_enable", "create_admin_down"]
|
||||||
|
self.vap_profile.desired_add_vap_flags_mask = self.vap_flags + ["wpa2_enable", "80211u_enable", "create_admin_down"]
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print("----- VAP List ----- ----- ----- ----- ----- ----- \n")
|
print("----- VAP List ----- ----- ----- ----- ----- ----- \n")
|
||||||
pprint.pprint(self.vap_list)
|
pprint.pprint(self.vap_list)
|
||||||
print("---- ~VAP List ----- ----- ----- ----- ----- ----- \n")
|
print("---- ~VAP List ----- ----- ----- ----- ----- ----- \n")
|
||||||
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
# Build VAPs
|
# Build VAPs
|
||||||
self.vap_profile.use_security(self.security, self.ssid, passwd=self.password)
|
self.vap_profile.use_security(self.security, self.ssid, passwd=self.password)
|
||||||
@@ -73,14 +82,16 @@ class CreateVAP(Realm):
|
|||||||
channel = 36,
|
channel = 36,
|
||||||
up_ = True,
|
up_ = True,
|
||||||
debug = False,
|
debug = False,
|
||||||
|
use_ht40=True,
|
||||||
|
use_ht80=True,
|
||||||
|
use_ht160=False,
|
||||||
suppress_related_commands_ = True,
|
suppress_related_commands_ = True,
|
||||||
use_radius = True,
|
use_radius=False,
|
||||||
hs20_enable = False)
|
hs20_enable=False,
|
||||||
|
bridge=self.bridge)
|
||||||
self._pass("PASS: VAP build finished")
|
self._pass("PASS: VAP build finished")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = LFCliBase.create_basic_argparse(
|
parser = LFCliBase.create_basic_argparse(
|
||||||
prog='create_vap.py',
|
prog='create_vap.py',
|
||||||
@@ -102,11 +113,12 @@ Command example:
|
|||||||
--passwd BLANK
|
--passwd BLANK
|
||||||
--debug
|
--debug
|
||||||
''')
|
''')
|
||||||
required = parser.add_argument_group('required arguments')
|
|
||||||
#required.add_argument('--security', help='WiFi Security protocol: < open | wep | wpa | wpa2 | wpa3 >', required=True)
|
|
||||||
|
|
||||||
optional = parser.add_argument_group('optional arguments')
|
optional = parser.add_argument_group('optional arguments')
|
||||||
optional.add_argument('--num_vaps', help='Number of VAPs to Create', required=False)
|
optional.add_argument('--num_vaps', help='Number of VAPs to Create', required=False)
|
||||||
|
optional.add_argument('--vap_flag', help='VAP flags to add', required=False, default=None, action='append')
|
||||||
|
optional.add_argument('--bridge', help='Create a bridge connecting the VAP to a port', required=False, default=False)
|
||||||
|
optional.add_argument('--mac', help='Custom mac address', default="xx:xx:xx:xx:*:xx")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
#if args.debug:
|
#if args.debug:
|
||||||
# pprint.pprint(args)
|
# pprint.pprint(args)
|
||||||
@@ -114,7 +126,7 @@ Command example:
|
|||||||
if (args.radio is None):
|
if (args.radio is None):
|
||||||
raise ValueError("--radio required")
|
raise ValueError("--radio required")
|
||||||
|
|
||||||
num_vap = 2
|
num_vap = 1
|
||||||
if (args.num_vaps is not None) and (int(args.num_vaps) > 0):
|
if (args.num_vaps is not None) and (int(args.num_vaps) > 0):
|
||||||
num_vaps_converted = int(args.num_vaps)
|
num_vaps_converted = int(args.num_vaps)
|
||||||
num_vap = num_vaps_converted
|
num_vap = num_vaps_converted
|
||||||
@@ -134,8 +146,10 @@ Command example:
|
|||||||
_password=args.passwd,
|
_password=args.passwd,
|
||||||
_security=args.security,
|
_security=args.security,
|
||||||
_vap_list=vap,
|
_vap_list=vap,
|
||||||
|
_vap_flags=args.vap_flag,
|
||||||
_radio=args.radio,
|
_radio=args.radio,
|
||||||
_proxy_str=args.proxy,
|
_proxy_str=args.proxy,
|
||||||
|
_bridge=args.bridge,
|
||||||
_debug_on=args.debug)
|
_debug_on=args.debug)
|
||||||
|
|
||||||
create_vap.build()
|
create_vap.build()
|
||||||
|
125
py-scripts/modify_vap.py
Executable file
125
py-scripts/modify_vap.py
Executable file
@@ -0,0 +1,125 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Script for modifying VAPs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
if sys.version_info[0] != 3:
|
||||||
|
print("This script requires Python 3")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if 'py-json' not in sys.path:
|
||||||
|
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
|
||||||
|
import LANforge
|
||||||
|
from LANforge.lfcli_base import LFCliBase
|
||||||
|
from LANforge import LFUtils
|
||||||
|
import realm
|
||||||
|
from realm import Realm
|
||||||
|
import time
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
|
||||||
|
class ModifyVAP(Realm):
|
||||||
|
def __init__(self,
|
||||||
|
_ssid="NA",
|
||||||
|
_security="NA",
|
||||||
|
_password="NA",
|
||||||
|
_mac="NA",
|
||||||
|
_host=None,
|
||||||
|
_port=None,
|
||||||
|
_vap_list=None,
|
||||||
|
_enable_flags=None,
|
||||||
|
_disable_flags=None,
|
||||||
|
_number_template="00000",
|
||||||
|
_radio=None,
|
||||||
|
_proxy_str=None,
|
||||||
|
_debug_on=False,
|
||||||
|
_exit_on_error=False,
|
||||||
|
_exit_on_fail=False,
|
||||||
|
_dhcp=True):
|
||||||
|
super().__init__(_host,
|
||||||
|
_port)
|
||||||
|
self.host = _host
|
||||||
|
self.port = _port
|
||||||
|
self.ssid = _ssid
|
||||||
|
self.security = _security
|
||||||
|
self.password = _password
|
||||||
|
self.mac = _mac
|
||||||
|
self.vap_list = _vap_list
|
||||||
|
self.enable_flags = _enable_flags
|
||||||
|
self.disable_flags = _disable_flags
|
||||||
|
self.radio = _radio
|
||||||
|
self.timeout = 120
|
||||||
|
self.number_template = _number_template
|
||||||
|
self.debug = _debug_on
|
||||||
|
self.dhcp = _dhcp
|
||||||
|
self.vap_profile = self.new_vap_profile()
|
||||||
|
self.vap_profile.vap_name = self.vap_list
|
||||||
|
self.vap_profile.ssid = self.ssid
|
||||||
|
self.vap_profile.security = self.security
|
||||||
|
self.vap_profile.ssid_pass = self.password
|
||||||
|
self.vap_profile.mac = self.mac
|
||||||
|
self.vap_profile.dhcp = self.dhcp
|
||||||
|
self.vap_profile.debug = self.debug
|
||||||
|
self.vap_profile.desired_add_vap_flags = self.enable_flags
|
||||||
|
self.vap_profile.desired_add_vap_flags_mask = self.enable_flags + self.disable_flags
|
||||||
|
|
||||||
|
def set_vap(self):
|
||||||
|
return self.vap_profile.modify(resource=1,
|
||||||
|
radio=self.radio)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = LFCliBase.create_basic_argparse(
|
||||||
|
prog='modify_vap.py',
|
||||||
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
|
epilog='''\
|
||||||
|
Modify VAPs on a system. Use the enable_flag to create a flag on a VAP. Turn off a flag with \
|
||||||
|
the disable_flag option. A list of available flags are available in the add_vap.py file in \
|
||||||
|
py-json/LANforge.
|
||||||
|
''',
|
||||||
|
|
||||||
|
description='''\
|
||||||
|
modify_vap.py
|
||||||
|
--------------------
|
||||||
|
Command example:
|
||||||
|
./modify_vap.py
|
||||||
|
--radio wiphy0
|
||||||
|
--vap 1.1.vap0000
|
||||||
|
--security open
|
||||||
|
--ssid netgear
|
||||||
|
--passwd BLANK
|
||||||
|
--enable_flag osen_enable
|
||||||
|
--disable_flag ht160_enable
|
||||||
|
--debug
|
||||||
|
''')
|
||||||
|
|
||||||
|
optional = parser.add_argument_group('optional arguments')
|
||||||
|
optional.add_argument('--enable_flag', help='VAP flags to add', default=list(), action='append')
|
||||||
|
optional.add_argument('--disable_flag', help='VAP flags to disable', default=list(), action='append')
|
||||||
|
optional.add_argument('--vap', help='VAP to modify', required=True)
|
||||||
|
optional.add_argument('--mac', default="NA")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
modify_vap = ModifyVAP(_host=args.mgr,
|
||||||
|
_port=args.mgr_port,
|
||||||
|
_ssid=args.ssid,
|
||||||
|
_password=args.passwd,
|
||||||
|
_security=args.security,
|
||||||
|
_mac=args.mac,
|
||||||
|
_vap_list=args.vap,
|
||||||
|
_enable_flags=args.enable_flag,
|
||||||
|
_disable_flags=args.disable_flag,
|
||||||
|
_radio=args.radio,
|
||||||
|
_proxy_str=args.proxy,
|
||||||
|
_debug_on=args.debug)
|
||||||
|
modify_vap.set_vap()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Reference in New Issue
Block a user