I am getting info from an HP device and storing it in a variable named data.
Now, I want to extract only the values for Chassis: and Serial Number: from the output, an example of which is below (I obtain it by typing the command show module):
============================
coaza077-cor-01> show module
Status and Counters - Module Information
Chassis: 2900-24G J9049A Serial Number: SG748KI09F
Slot Module Description Serial Number
----- ---------------------------------------- --------------
coaza077-cor-01> exit
Do you want to log out [y/n]? y
=============================
The code below is my attempt to do this:
sList = os.linesep.join([s for s in data.splitlines() if s])
for i in range(0,len(sList)):
if (sList[i].lower()).find('Chassis') >= 0:
#DEVICE PROCESSOR
device_processor= _parse.getdata(sList[i].lower(), 'Chassis:', ' ')
if debugging == "_HP2900" or debugging == "ALL": print "_HP2900.py", "Processor", device_processor
if (sList[i].lower()).find('Serial Number') >= 0:
print 'Serial Number'
#DEVICE SERIAL NUMBER
device_serial= (_parse.serial_number(sList[i].lower()[len('Serial Number'):])).upper()
if debugging == "_HP2900" or debugging == "ALL": print "_HP2900.py", "Serial", device_serial
.. however I can’t seem to get only the two values that I need. I’m new to Python, and not sure that I’m even approaching the problem correctly.
How can I get just the fields that I need?
Update for comment: