Improve cisco ctrl script and let lf_portmod.pl work from CWD

This commit is contained in:
Ben Greear
2019-12-14 15:14:06 -08:00
parent 00d0e50351
commit e7a228bc52
2 changed files with 33 additions and 13 deletions

View File

@@ -75,8 +75,8 @@ def main():
#parser.add_argument("-r", "--radio", type=str, help="select radio") #parser.add_argument("-r", "--radio", type=str, help="select radio")
parser.add_argument("-a", "--ap", type=str, help="select AP") parser.add_argument("-a", "--ap", type=str, help="select AP")
parser.add_argument("--action", type=str, help="perform action", parser.add_argument("--action", type=str, help="perform action",
choices=["config", "country", "enable", "disable", "summary", "advanced", choices=["config", "country", "ap_country", "enable", "disable", "summary", "advanced",
"cmd", "txPower", "show" ]) "cmd", "txPower", "bandwidth", "show" ])
parser.add_argument("--value", type=str, help="set value") parser.add_argument("--value", type=str, help="set value")
args = None args = None
@@ -164,6 +164,8 @@ def main():
time.sleep(0.1) time.sleep(0.1)
CCPROMPT = '\(Cisco Controller\) >' CCPROMPT = '\(Cisco Controller\) >'
EXITPROMPT = "Would you like to save them now\? \(y/N\)" EXITPROMPT = "Would you like to save them now\? \(y/N\)"
AREYOUSURE = "Are you sure you want to continue\? \(y/n\)"
CLOSEDBYREMOTE = "closed by remote host."
egg.expect(CCPROMPT) egg.expect(CCPROMPT)
logg.info("Ap[%s] Action[%s] Value[%s] "%(args.ap, args.action, args.value)) logg.info("Ap[%s] Action[%s] Value[%s] "%(args.ap, args.action, args.value))
@@ -175,18 +177,29 @@ def main():
print ("HI") print ("HI")
command = "show "+args.value command = "show "+args.value
if (args.action == "cmd"):
if (args.value is None):
raise Exception("cmd requires value to be set.")
command = "%s"%(args.value)
if (args.action == "summary"): if (args.action == "summary"):
command = "show ap summary" command = "show ap summary"
if (args.action == "advanced"): if (args.action == "advanced"):
command = "show advanced 802.11a summary" command = "show advanced 802.11a summary"
if ((args.action == "set_country") and ((args.value is None) or (args.ap is None))): if ((args.action == "ap_country") and ((args.value is None) or (args.ap is None))):
raise Exception("set_country requires country and AP name") raise Exception("ap_country requires country and AP name")
if (args.action == "set_country"): if (args.action == "ap_country"):
command = "config ap country %s %s"%(args.value, args.ap) command = "config ap country %s %s"%(args.value, args.ap)
if ((args.action == "country") and ((args.value is None))):
raise Exception("country requires country value")
if (args.action == "country"):
command = "config country %s"%(args.value)
if (args.action in ["enable", "disable" ] and (args.ap is None)): if (args.action in ["enable", "disable" ] and (args.ap is None)):
raise Exception("action requires AP name") raise Exception("action requires AP name")
if (args.action == "enable"): if (args.action == "enable"):
@@ -199,18 +212,25 @@ def main():
if (args.action == "txPower"): if (args.action == "txPower"):
command = "config 802.11a txPower ap %s %s"%(args.ap, args.value) command = "config 802.11a txPower ap %s %s"%(args.ap, args.value)
if (args.action == "bandwidth" and ((args.ap is None) or (args.value is None))):
raise Exception("bandwidth requires ap and value (20, 40, 80, 160)")
if (args.action == "bandwidth"):
command = "config 802.11a chan_width %s %s"%(args.ap, args.value)
if (command is None): if (command is None):
logg.info("Going to log out.") logg.info("No command specified, going to log out.")
else: else:
logg.info("Command[%s]"%command) logg.info("Command[%s]"%command)
egg.sendline(command); egg.sendline(command);
egg.expect(CCPROMPT) i = egg.expect([CCPROMPT, AREYOUSURE])
if i == 1:
egg.sendline("y")
egg.sendline("logout") egg.sendline("logout")
egg.expect(EXITPROMPT) i = egg.expect([EXITPROMPT, CLOSEDBYREMOTE])
egg.sendline("y") if i == 0:
egg.sendline("y")

View File

@@ -32,11 +32,11 @@ use Cwd qw(getcwd);
my $cwd = getcwd(); my $cwd = getcwd();
# this is pedantic necessity for the following use statements # this is pedantic necessity for the following use statements
if ( $cwd =~ q(.*LANforge-Server\scripts$)) { if ( -f "LANforge/Endpoint.pm" ) {
use lib '/home/lanforge/scripts' use lib "./";
} }
elsif ( -f "LANforge/Endpoint.pm" ) { elsif ( $cwd =~ q(.*LANforge-Server\scripts$)) {
use lib "./LANforge"; use lib '/home/lanforge/scripts'
} }
else { else {
use lib '/home/lanforge/scripts'; use lib '/home/lanforge/scripts';