mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-03 20:27:54 +00:00 
			
		
		
		
	lf_ap_power.py: LCS-45 Read AP for Power values
Updated login to help with multiple logins lf_cisco_power.py: comments update
This commit is contained in:
		@@ -20,12 +20,12 @@ if sys.version_info[0] != 3:
 | 
				
			|||||||
    print("This script requires Python 3")
 | 
					    print("This script requires Python 3")
 | 
				
			||||||
    exit()
 | 
					    exit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import re
 | 
					#import re
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from time import sleep
 | 
					from time import sleep
 | 
				
			||||||
import pprint
 | 
					#import pprint
 | 
				
			||||||
import telnetlib
 | 
					#import telnetlib
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import pexpect
 | 
					import pexpect
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -95,10 +95,8 @@ def main():
 | 
				
			|||||||
        scheme = args.scheme
 | 
					        scheme = args.scheme
 | 
				
			||||||
        port = (default_ports[scheme], args.port)[args.port != None]
 | 
					        port = (default_ports[scheme], args.port)[args.port != None]
 | 
				
			||||||
        user = args.user
 | 
					        user = args.user
 | 
				
			||||||
        passwd = args.passwd
 | 
					 | 
				
			||||||
        if (args.log != None):
 | 
					        if (args.log != None):
 | 
				
			||||||
            logfile = args.log
 | 
					            logfile = args.log
 | 
				
			||||||
        filehandler = None
 | 
					 | 
				
			||||||
    except Exception as e:
 | 
					    except Exception as e:
 | 
				
			||||||
        logging.exception(e)
 | 
					        logging.exception(e)
 | 
				
			||||||
        usage()
 | 
					        usage()
 | 
				
			||||||
@@ -159,31 +157,60 @@ def main():
 | 
				
			|||||||
    except Exception as e:
 | 
					    except Exception as e:
 | 
				
			||||||
        logging.exception(e)
 | 
					        logging.exception(e)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    ap_prompt = "{}>".format(args.prompt)
 | 
					    AP_PROMPT       = "{}>".format(args.prompt)
 | 
				
			||||||
    ap_hash = "{}#".format(args.prompt)
 | 
					    AP_HASH         = "{}#".format(args.prompt)
 | 
				
			||||||
    egg.sendline()
 | 
					    AP_ESCAPE       = "Escape character is '^]'."
 | 
				
			||||||
 | 
					    AP_USERNAME     = "Username:"
 | 
				
			||||||
    egg.sendline()
 | 
					    AP_PASSWORD     = "Password:"
 | 
				
			||||||
    time.sleep(0.1)
 | 
					    AP_EN           = "en"
 | 
				
			||||||
    egg.expect('Username:', timeout=3)
 | 
					    AP_MORE         = "--More--"
 | 
				
			||||||
 | 
					    AP_EXIT         = "exit"
 | 
				
			||||||
 | 
					    CR = "\r\n"
 | 
				
			||||||
    time.sleep(0.1)
 | 
					    time.sleep(0.1)
 | 
				
			||||||
 | 
					    logged_in  = False
 | 
				
			||||||
 | 
					    loop_count = 0
 | 
				
			||||||
 | 
					    while (loop_count <= 8 and logged_in == False):
 | 
				
			||||||
 | 
					        loop_count += 1
 | 
				
			||||||
 | 
					        i = egg.expect_exact([AP_ESCAPE,AP_PROMPT,AP_HASH,AP_USERNAME,AP_PASSWORD,pexpect.TIMEOUT],timeout=5)
 | 
				
			||||||
 | 
					        if i == 0:
 | 
				
			||||||
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format(AP_ESCAPE,i,egg.before,egg.after))
 | 
				
			||||||
 | 
					            egg.sendline(CR) # Needed after Escape or should just do timeout and then a CR?
 | 
				
			||||||
 | 
					            sleep(0.2)
 | 
				
			||||||
 | 
					        if i == 1:
 | 
				
			||||||
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format(AP_PROMPT,i,egg.before,egg.after))
 | 
				
			||||||
 | 
					            egg.sendline(AP_EN) 
 | 
				
			||||||
 | 
					            sleep(0.2)
 | 
				
			||||||
 | 
					        if i == 2:
 | 
				
			||||||
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format(AP_HASH,i,egg.before,egg.after))
 | 
				
			||||||
 | 
					            logged_in = True 
 | 
				
			||||||
 | 
					            sleep(0.2)
 | 
				
			||||||
 | 
					        if i == 3:
 | 
				
			||||||
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format(AP_USERNAME,i,egg.before,egg.after))
 | 
				
			||||||
            egg.sendline(args.user) 
 | 
					            egg.sendline(args.user) 
 | 
				
			||||||
    time.sleep(0.1)
 | 
					            sleep(0.2)
 | 
				
			||||||
    egg.expect('Password:')
 | 
					        if i == 4:
 | 
				
			||||||
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format(AP_PASSWORD,i,egg.before,egg.after))
 | 
				
			||||||
            egg.sendline(args.passwd) 
 | 
					            egg.sendline(args.passwd) 
 | 
				
			||||||
    egg.expect(ap_prompt)
 | 
					            sleep(0.2)
 | 
				
			||||||
    egg.sendline("en")
 | 
					        if i == 5:
 | 
				
			||||||
    egg.expect("Password:")
 | 
					            logg.info("Expect: {} i: {} before: {} after: {}".format("Timeout",i,egg.before,egg.after))
 | 
				
			||||||
    egg.sendline(args.passwd)
 | 
					            egg.sendline(CR) 
 | 
				
			||||||
    egg.expect("#")
 | 
					            sleep(0.2)
 | 
				
			||||||
    egg.sendline('show controllers dot11Radio 1 powercfg | g T1')
 | 
					 | 
				
			||||||
    egg.expect("--More--")
 | 
					 | 
				
			||||||
    egg.sendcontrol('c')
 | 
					 | 
				
			||||||
    egg.expect("#",timeout=5)
 | 
					 | 
				
			||||||
    egg.sendline("exit")
 | 
					 | 
				
			||||||
    egg.expect(">",timeout=5)
 | 
					 | 
				
			||||||
    egg.sendline("exit")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (args.action == "powercfg"):
 | 
				
			||||||
 | 
					        egg.sendline('show controllers dot11Radio 1 powercfg | g T1')
 | 
				
			||||||
 | 
					        egg.expect_exact(AP_MORE,timeout=5)
 | 
				
			||||||
 | 
					        egg.sendcontrol('c')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    else: # no other command at this time so send the same power command
 | 
				
			||||||
 | 
					        egg.sendline('show controllers dot11Radio 1 powercfg | g T1')
 | 
				
			||||||
 | 
					        egg.expect_exact(AP_MORE,timeout=5)
 | 
				
			||||||
 | 
					        egg.sendcontrol('c')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    egg.expect_exact(AP_HASH,timeout=5)
 | 
				
			||||||
 | 
					    egg.sendline(AP_EXIT)
 | 
				
			||||||
 | 
					    egg.expect_exact(AP_PROMPT,timeout=5)
 | 
				
			||||||
 | 
					    egg.sendline(AP_EXIT)
 | 
				
			||||||
    #             ctlr.execute(cn_cmd)
 | 
					    #             ctlr.execute(cn_cmd)
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    main()
 | 
					    main()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1599,7 +1599,7 @@ def main():
 | 
				
			|||||||
                               logg.info("####################################################################################################") 
 | 
					                               logg.info("####################################################################################################") 
 | 
				
			||||||
                      
 | 
					                      
 | 
				
			||||||
                               logg.info("####################################################################################################") 
 | 
					                               logg.info("####################################################################################################") 
 | 
				
			||||||
                               logg.info("# Unable to commicate to AP or unable to communicate to controller error code: {} output {}".format(process_error.returncode, process_error.output)) 
 | 
					                               logg.info("# Unable to commicate to AP  error code: {} output {}".format(process_error.returncode, process_error.output)) 
 | 
				
			||||||
                               logg.info("####################################################################################################") 
 | 
					                               logg.info("####################################################################################################") 
 | 
				
			||||||
                               #exit_test(workbook)
 | 
					                               #exit_test(workbook)
 | 
				
			||||||
                               exit(1)
 | 
					                               exit(1)
 | 
				
			||||||
@@ -1626,9 +1626,6 @@ def main():
 | 
				
			|||||||
                                else:
 | 
					                                else:
 | 
				
			||||||
                                    logg.info("AP Check regular expression!!!")
 | 
					                                    logg.info("AP Check regular expression!!!")
 | 
				
			||||||
                                    exit(1)
 | 
					                                    exit(1)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                       #
 | 
					                       #
 | 
				
			||||||
                       #  The controller may adjust the number of spatial streams to allow for the 
 | 
					                       #  The controller may adjust the number of spatial streams to allow for the 
 | 
				
			||||||
                       #  best power values
 | 
					                       #  best power values
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user