cisco_wifi_ctl.py: added no_logging_console and line_console_0 to suppress logging during script running

This commit is contained in:
Chuck SmileyRekiere
2020-10-26 09:03:50 -06:00
parent 8862ae0fe7
commit 16919ae7fe

View File

@@ -107,7 +107,7 @@ def main():
choices=["a", "b", "abgn"]) choices=["a", "b", "abgn"])
parser.add_argument("--action", type=str, help="perform action", parser.add_argument("--action", type=str, help="perform action",
choices=["config", "country", "ap_country", "enable", "disable", "summary", "advanced", choices=["config", "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",
"ap_channel", "channel", "show", "create_wlan", "enable_wlan", "disable_wlan", "wlan_qos", "ap_channel", "channel", "show", "create_wlan", "enable_wlan", "disable_wlan", "wlan_qos",
"disable_network_5ghz","disable_network_24ghz","enable_network_5ghz","enable_network_24ghz", "disable_network_5ghz","disable_network_24ghz","enable_network_5ghz","enable_network_24ghz",
@@ -193,11 +193,9 @@ def main():
sleep(0.4) sleep(0.4)
try: try:
i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets",pexpect.TIMEOUT],timeout=2) i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets",pexpect.TIMEOUT],timeout=2)
except pexpect.EOF as e: except Exception as e:
logg.info('connection failed. or refused Connection open by other process') logg.info('connection failed. or refused Connection open by other process')
exit(1) logging.exception(e)
except:
logg.info('unknown exception on initial pexpect after login')
exit(1) exit(1)
if i == 0: if i == 0:
@@ -539,11 +537,9 @@ def main():
sleep(0.4) sleep(0.4)
try: try:
i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets", PRESS_RETURN, CONFIG_I,pexpect.TIMEOUT],timeout=2) i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets", PRESS_RETURN, CONFIG_I,pexpect.TIMEOUT],timeout=2)
except pexpect.EOF as e: except Exception as e:
logg.info('connection failed. or refused Connection open by other process') logg.info('connection failed. or refused Connection open by other process')
exit(1) logg.exception(e)
except:
logg.info('unknown exception on initial pexpect after login')
exit(1) exit(1)
if i == 0: if i == 0:
@@ -1098,10 +1094,44 @@ def main():
if j == 0: if j == 0:
logg.info("command sent: {}".format(command)) logg.info("command sent: {}".format(command))
if j == 1: if j == 1:
logg.info("timmed out on command prompt (config-policy-tag)# for command {}".format(command)) logg.info("timed out on command prompt (config-policy-tag)# for command {}".format(command))
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 == "no_logging_console"):
logg.info("send no logging console")
egg.sendline("config t")
sleep(0.2)
i = egg.expect_exact(["(config)#",pexpect.TIMEOUT],timeout=2)
if i == 0:
egg.sendline("no logging console")
sleep(0.2)
j = egg.expect_exact(["(config)#", pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("command sent: no logging console")
if j == 1:
logg.info("timed out on command prompt (config)#")
if i == 1:
logg.info("did not get the (config)# prompt")
if (args.action == "line console 0"):
logg.info("send: line console 0")
egg.sendline("config t")
sleep(0.2)
i = egg.expect_exact(["(config)#",pexpect.TIMEOUT],timeout=2)
if i == 0:
egg.sendline("line console 0")
sleep(0.1)
j = egg.expect_exact(["(config-line)#","(config)#",pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("command sent: line console 0 received prompt (config-line)#")
if j == 1:
logg.info("command sent: line console 0 received prompt (config)#")
if j == 2:
logg.info("timed out on command prompt (config-line)#")
if i == 1:
logg.info("did not get the (config)# prompt")
if (args.action == "no_wlan" and (args.wlan is None)): if (args.action == "no_wlan" and (args.wlan is None)):
raise Exception("wlan is required") raise Exception("wlan is required")
if (args.action == "no_wlan"): if (args.action == "no_wlan"):
@@ -1227,7 +1257,7 @@ def main():
loop_count = 0 loop_count = 0
while logged_out_9800 == False and loop_count <= 6: while logged_out_9800 == False and loop_count <= 6:
loop_count += 1 loop_count += 1
i = egg.expect_exact(["WLC>","WLC#", "WLC(config)#","(config-wlan)#","(config-policy-tag)#",pexpect.TIMEOUT],timeout=5) i = egg.expect_exact(["WLC>","WLC#", "WLC(config)#","(config-wlan)#","(config-policy-tag)#","(config-line)#",pexpect.TIMEOUT],timeout=5)
print (egg.before.decode('utf-8', 'ignore')) print (egg.before.decode('utf-8', 'ignore'))
if i == 0: if i == 0:
logg.info("WLC> prompt received can send logout") logg.info("WLC> prompt received can send logout")
@@ -1270,6 +1300,14 @@ def main():
logg.info("9800 exception on exit") logg.info("9800 exception on exit")
sleep(0.1) sleep(0.1)
if i == 5: if i == 5:
logg.info("(config-line)# prompt received will send exit")
try:
egg.sendline("exit")
sleep(2)
except:
logg.info("9800 exception on exit")
sleep(0.1)
if i == 6:
logg.info("9800 expect timeout send exit") logg.info("9800 expect timeout send exit")
egg.sendline("exit") egg.sendline("exit")
break break