Reputation: 139
I am trying to parse a table from a switch. If the state is "up" continue running through the 1000 iterations else halt the test. Below is the table that I need to parse and is the output of the "crt.Screen.Send("show" + chr(13))" below in the code.
OS2(config-iap)# show
IAP Summary Table
IAP IAP TX/RX Channel(s) Channel WiFi Cell TX RX
Name State Type Chains Primary + Bonds Setting Mode Antenna Size Power Threshold Stations
----- ----- ------------- ------------------------------- ------- ------- -------- ------- ------ --------- --------
iap1 up .11abgnac 3x3 6 auto bgn int-omni max 20dBm -90dBm 0
iap2 up .11anac 3x3 153 auto anac int-omni max 20dBm -90dBm 0
========
Totals: 0
OS2(config-iap)#
Below is the entire Python code I am using to loop through a country-code toggle for 1000 iterations and check if the state of those IAP1/2 are in "up" or "down" state. If "up" I'd like the program to continue through it's iterations else (if "down") to halt or stop the test. The code below works without the for statement - However, I have to visually see when the state switches to down state and halt the test manually.
import time
output=""
def Main():
state="up"
crt.Screen.Send(chr(13))
crt.Screen.WaitForString("# ")
crt.Screen.Send("config" + chr(13))
crt.Screen.WaitForString("# ")
crt.Screen.Send("interface iap" + chr(13))
crt.Screen.WaitForString("# ")
virt = 0
while virt < 1000: #1024 being the max number of VLANs
virt += 1
crt.Screen.Send("!" + str(virt) + chr(13))
crt.Screen.WaitForString("# ")
crt.Screen.Send("country-code us" + chr(13))
crt.Screen.WaitForString("(config-iap)# ")
time.sleep(3)
crt.Screen.Send("show date-time" + chr(13))
crt.Screen.WaitForString("# ")
crt.Screen.Send("show" + chr(13))
output = crt.Screen.recv(2000)
output=state.decode('utf-8')
ll=state.split(chr(13))
for item in ll:
if "iap" in ll:
mm=item.split()
if mm[1]==state:
continue
else:
break
#crt.Screen.WaitForString("# ")
crt.Screen.Send("country-code-reset" + chr(13))
crt.Screen.WaitForString("(config-iap)# ")
crt.Screen.Send("show" + chr(13))
crt.Screen.WaitForString("# ")
time.sleep(5)
crt.Screen.Send("exit" + chr(13))
crt.Screen.WaitForString("# ")
#time.sleep(1)
Main()
This is the error I am getting:
AttributeError Error: 'SecureCRT.Screen' object has no attribute 'recv' File: /Users/Documents/SecureCRT_Scripts/country-code_1.py Line: 24 state = crt.Screen.recv(2000)
Upvotes: 0
Views: 70
Reputation: 91
I think there is a typo in your code,
if "iap" in ll:
should be,
if "iap" in item:
Upvotes: 1