I am trying to understand network automation and I need to get the device model details from 2-3 different cisco devices.
I am using paramiko in python to run my command on the device and in return, I want to extract only the device model name from the console output.
Examples of output:
Device1-
PID: DEV1-123CE-D3T , VID: unimportant string , SN: 1
PID: DEV1-123CE-D3T , VID: unimportant string , SN: 1
Device2-
PID: , VID: unimportant string , SN: 1
PID: ABC2-123CE-D3T , VID: unimportant string , SN: 1
Device3-
PID: XYZ3-456DF-A1N , VID: unimportant string , SN: 1
PID: XYZ3-456DF-A1N , VID: unimportant string , SN: 1
I just need details of PID. If the PID is empty in the first line, then the code should search for the second PID in the output and post the match.
Relevant part of code I have so far which is only searching data in the first line and returning a 'None' value -
stdout = stdout.readlines()
lines = list(islice(stdout, 2))
for line in lines:
result = re.findall('PID:(.*)\t\t,', line)
print(result)
What changes do I need to make to my code to get the desired output?
Thanks in advance!