mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-20 20:14:57 +00:00
wifi_ctl_9800_3504.py : auto pep8 white space clean up
Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
committed by
shivam
parent
af490281a7
commit
3037eb9e24
@@ -67,6 +67,7 @@ FORMAT = '%(asctime)s %(name)s %(levelname)s: %(message)s'
|
|||||||
band = "a"
|
band = "a"
|
||||||
egg = None # think "eggpect" Need global scope for recovery
|
egg = None # think "eggpect" Need global scope for recovery
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print("$0 used connect to controller:")
|
print("$0 used connect to controller:")
|
||||||
print("-d|--dest: destination host")
|
print("-d|--dest: destination host")
|
||||||
@@ -86,14 +87,18 @@ def usage():
|
|||||||
print("-h|--help")
|
print("-h|--help")
|
||||||
|
|
||||||
# see https://stackoverflow.com/a/13306095/11014343
|
# see https://stackoverflow.com/a/13306095/11014343
|
||||||
|
|
||||||
|
|
||||||
class FileAdapter(object):
|
class FileAdapter(object):
|
||||||
def __init__(self, logger):
|
def __init__(self, logger):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
# NOTE: data can be a partial line, multiple lines
|
# NOTE: data can be a partial line, multiple lines
|
||||||
data = data.strip() # ignore leading/trailing whitespace
|
data = data.strip() # ignore leading/trailing whitespace
|
||||||
if data: # non-blank
|
if data: # non-blank
|
||||||
self.logger.info(data)
|
self.logger.info(data)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass # leave it to logging to flush properly
|
pass # leave it to logging to flush properly
|
||||||
|
|
||||||
@@ -121,7 +126,6 @@ def main():
|
|||||||
# parser.add_argument("--tag_policy", type=str, help="--tag_policy default-tag-policy", default="RM204-TB2")
|
# parser.add_argument("--tag_policy", type=str, help="--tag_policy default-tag-policy", default="RM204-TB2")
|
||||||
parser.add_argument("--policy_profile", type=str, help="--policy_profile default-policy-profile", default="default-policy-profile")
|
parser.add_argument("--policy_profile", type=str, help="--policy_profile default-policy-profile", default="default-policy-profile")
|
||||||
|
|
||||||
|
|
||||||
parser.add_argument("--action", type=str, help="perform action",
|
parser.add_argument("--action", type=str, help="perform action",
|
||||||
choices=["config", "debug_disable_all", "no_logging_console", "line_console_0", "country", "ap_country", "enable", "disable", "summary", "advanced",
|
choices=["config", "debug_disable_all", "no_logging_console", "line_console_0", "country", "ap_country", "enable", "disable", "summary", "advanced",
|
||||||
"cmd", "txPower", "bandwidth", "manual", "auto", "no_wlan", "show_wlan_summary",
|
"cmd", "txPower", "bandwidth", "manual", "auto", "no_wlan", "show_wlan_summary",
|
||||||
@@ -140,7 +144,7 @@ def main():
|
|||||||
user = args.user
|
user = args.user
|
||||||
passwd = args.passwd
|
passwd = args.passwd
|
||||||
logfile = args.log
|
logfile = args.log
|
||||||
if (args.band != None):
|
if (args.band is not None):
|
||||||
band = args.band
|
band = args.band
|
||||||
if (band == "abgn"):
|
if (band == "abgn"):
|
||||||
band = "-abgn"
|
band = "-abgn"
|
||||||
@@ -197,14 +201,13 @@ def main():
|
|||||||
print("CCP_POLICY_TAG {}".format(CCP_POLICY_TAG))
|
print("CCP_POLICY_TAG {}".format(CCP_POLICY_TAG))
|
||||||
print("CCP_CONFIG_LINE {}".format(CCP_CONFIG_LINE))'''
|
print("CCP_CONFIG_LINE {}".format(CCP_CONFIG_LINE))'''
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if (scheme == "serial"):
|
if (scheme == "serial"):
|
||||||
# eggspect = pexpect.fdpexpect.fdspan(telcon, logfile=sys.stdout.buffer)
|
# eggspect = pexpect.fdpexpect.fdspan(telcon, logfile=sys.stdout.buffer)
|
||||||
import serial
|
import serial
|
||||||
from pexpect_serial import SerialSpawn
|
from pexpect_serial import SerialSpawn
|
||||||
with serial.Serial('/dev/ttyUSB0', 115200, timeout=5) as ser:
|
with serial.Serial('/dev/ttyUSB0', 115200, timeout=5) as ser:
|
||||||
egg = SerialSpawn(ser);
|
egg = SerialSpawn(ser)
|
||||||
egg.logfile = FileAdapter(logg)
|
egg.logfile = FileAdapter(logg)
|
||||||
print("logg {}".format(logg))
|
print("logg {}".format(logg))
|
||||||
egg.sendline(NL)
|
egg.sendline(NL)
|
||||||
@@ -375,7 +378,9 @@ def main():
|
|||||||
found_escape = False
|
found_escape = False
|
||||||
|
|
||||||
if j == 5:
|
if j == 5:
|
||||||
logg.info("9800 timed out looking for CCP :{},CCP_EN: {},CCP_CONFIG: {} loop_count {} i {} j {} before {} after {}".format(CCP,CCP_EN,CCP_CONFIG,loop_count,i,j,egg.before,egg.after))
|
logg.info(
|
||||||
|
"9800 timed out looking for CCP :{},CCP_EN: {},CCP_CONFIG: {} loop_count {} i {} j {} before {} after {}".format(
|
||||||
|
CCP, CCP_EN, CCP_CONFIG, loop_count, i, j, egg.before, egg.after))
|
||||||
logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count, i, j))
|
logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count, i, j))
|
||||||
egg.close(force=True)
|
egg.close(force=True)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@@ -547,7 +552,6 @@ def main():
|
|||||||
egg.close(force=True)
|
egg.close(force=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
# 3504 series
|
# 3504 series
|
||||||
else:
|
else:
|
||||||
i = egg.expect(["ssword:", "continue connecting (yes/no)?"], timeout=timeout)
|
i = egg.expect(["ssword:", "continue connecting (yes/no)?"], timeout=timeout)
|
||||||
@@ -735,7 +739,6 @@ def main():
|
|||||||
logged_in_9800 = False
|
logged_in_9800 = False
|
||||||
found_escape = False
|
found_escape = False
|
||||||
|
|
||||||
|
|
||||||
if i == 1:
|
if i == 1:
|
||||||
logg.info("9800 found {} will elevate loging i:{} before {} after {}".format(CCP, i, egg.before, egg.after))
|
logg.info("9800 found {} will elevate loging i:{} before {} after {}".format(CCP, i, egg.before, egg.after))
|
||||||
egg.sendline("en")
|
egg.sendline("en")
|
||||||
@@ -871,7 +874,12 @@ def main():
|
|||||||
egg.sentline(CR)
|
egg.sentline(CR)
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
if i == 9:
|
if i == 9:
|
||||||
logg.info("9800 Timed out waiting for initial prompt, Log message from controller interfering with expected prompts loop_count: {} i: {} before {} after {}".format(loop_count, i, egg.before,egg.after))
|
logg.info(
|
||||||
|
"9800 Timed out waiting for initial prompt, Log message from controller interfering with expected prompts loop_count: {} i: {} before {} after {}".format(
|
||||||
|
loop_count,
|
||||||
|
i,
|
||||||
|
egg.before,
|
||||||
|
egg.after))
|
||||||
logg.info("9800 Closing the connection and try to re-establish, ")
|
logg.info("9800 Closing the connection and try to re-establish, ")
|
||||||
egg.close(force=True)
|
egg.close(force=True)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@@ -912,9 +920,9 @@ def main():
|
|||||||
# 3504 series
|
# 3504 series
|
||||||
else:
|
else:
|
||||||
egg.sendline(' ')
|
egg.sendline(' ')
|
||||||
egg.expect('User\:',timeout=3)
|
egg.expect('User\\:', timeout=3)
|
||||||
egg.sendline(user)
|
egg.sendline(user)
|
||||||
egg.expect('Password\:',timeout=3)
|
egg.expect('Password\\:', timeout=3)
|
||||||
egg.sendline(passwd)
|
egg.sendline(passwd)
|
||||||
# if args.prompt in CCP_EN or args.prompt in CCP:
|
# if args.prompt in CCP_EN or args.prompt in CCP:
|
||||||
# egg.sendline("enable")
|
# egg.sendline("enable")
|
||||||
@@ -936,7 +944,6 @@ def main():
|
|||||||
command = None
|
command = None
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if args.series == "9800":
|
if args.series == "9800":
|
||||||
pass
|
pass
|
||||||
@@ -1176,7 +1183,6 @@ def main():
|
|||||||
if i == 1:
|
if i == 1:
|
||||||
logg.info("did not get the (config)# prompt")
|
logg.info("did not get the (config)# prompt")
|
||||||
|
|
||||||
|
|
||||||
if (args.action == "wireless_tag_policy"):
|
if (args.action == "wireless_tag_policy"):
|
||||||
logg.info("send wireless tag policy")
|
logg.info("send wireless tag policy")
|
||||||
egg.sendline("config t")
|
egg.sendline("config t")
|
||||||
@@ -1370,7 +1376,6 @@ def main():
|
|||||||
logg.info("send: config wlan disable {}".format(args.wlan))
|
logg.info("send: config wlan disable {}".format(args.wlan))
|
||||||
command = "config wlan disable %s" % (args.wlan)
|
command = "config wlan disable %s" % (args.wlan)
|
||||||
|
|
||||||
|
|
||||||
if (args.action == "wlan_qos" and (args.wlan is None)):
|
if (args.action == "wlan_qos" and (args.wlan is None)):
|
||||||
raise Exception("wlan ID is required")
|
raise Exception("wlan ID is required")
|
||||||
if (args.action == "wlan_qos"):
|
if (args.action == "wlan_qos"):
|
||||||
@@ -1405,7 +1410,7 @@ def main():
|
|||||||
egg.sendline("logout")
|
egg.sendline("logout")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
logged_out_9800 = True
|
logged_out_9800 = True
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("9800 exception on logout")
|
logg.info("9800 exception on logout")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
break
|
break
|
||||||
@@ -1415,7 +1420,7 @@ def main():
|
|||||||
egg.sendline("exit")
|
egg.sendline("exit")
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
logged_out_9800 = True
|
logged_out_9800 = True
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("9800 exception on end")
|
logg.info("9800 exception on end")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if i == 3:
|
if i == 3:
|
||||||
@@ -1423,7 +1428,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
egg.sendline("end")
|
egg.sendline("end")
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("9800 exception on end")
|
logg.info("9800 exception on end")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if i == 4:
|
if i == 4:
|
||||||
@@ -1431,7 +1436,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
egg.sendline("end")
|
egg.sendline("end")
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("9800 exception on end")
|
logg.info("9800 exception on end")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if i == 5:
|
if i == 5:
|
||||||
@@ -1439,7 +1444,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
egg.sendline("end")
|
egg.sendline("end")
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("9800 exception on end")
|
logg.info("9800 exception on end")
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if i == 6:
|
if i == 6:
|
||||||
@@ -1474,7 +1479,6 @@ def main():
|
|||||||
egg.expect([pexpect.TIMEOUT], timeout=1)
|
egg.expect([pexpect.TIMEOUT], timeout=1)
|
||||||
print(egg.before.decode('utf-8', 'ignore'))
|
print(egg.before.decode('utf-8', 'ignore'))
|
||||||
|
|
||||||
|
|
||||||
command_sent = False
|
command_sent = False
|
||||||
loop_count = 0
|
loop_count = 0
|
||||||
while command_sent == False and loop_count <= 3:
|
while command_sent == False and loop_count <= 3:
|
||||||
@@ -1503,7 +1507,7 @@ def main():
|
|||||||
logg.info(" Check to see if logging to console is disabled")
|
logg.info(" Check to see if logging to console is disabled")
|
||||||
command_sent = True
|
command_sent = True
|
||||||
|
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("closing connection logout loop {}".format(CCPROMPT))
|
logg.info("closing connection logout loop {}".format(CCPROMPT))
|
||||||
try:
|
try:
|
||||||
egg.sendline("logout")
|
egg.sendline("logout")
|
||||||
@@ -1511,11 +1515,10 @@ def main():
|
|||||||
logg.info("send close to the egg child process")
|
logg.info("send close to the egg child process")
|
||||||
egg.close(force=True)
|
egg.close(force=True)
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
except:
|
except BaseException:
|
||||||
logg.info("closing connection on logout")
|
logg.info("closing connection on logout")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user