I am still fairly new to python but ive done quite a bit dealing with pexpect and grabbing cli output from a network device. However, Im trying to make it a bit more user friendly by letting the user see a list of options to choose from.
I have a network device that would need to have a mac-swap loop put on it. I am using argparse to let the user specify the interface and IP of the device to use however, in certain cases, the user may not know which interface to use. I would like to parse through an output and present the user with a list that they could then choose from which would allow the code to use that chosen interface as the variable.
Currently, the output from the device would look like this:
user@hostname> show interface
interface table:
interface admin operation user-label
1/1/bits is normal --
1/1/bits/pdh -- -- --
1/1/dcn1 is out --
1/1/dcn1/eth is out --
1/1/dcn2 oos ua --
1/1/dcn2/eth oos ua --
1/1/p1 is out UNI
1/1/p1/eth is out --
1/1/p1/fp-1 is out --
1/1/p5 is normal UPLINK
1/1/p5/eth is normal --
1/1/p5/fp-1 is normal --
1/1/p5/mgmt-1 is normal untagmgmt
1/1/p9 oos ua --
1/1/p9/eth oos ua --
1/1/p10 oos ua --
1/1/p10/eth oos ua --
1/1/ppstod is normal --
1/1/ppstod/ppstod -- -- --
[node 1]
I would like to parse through this list, im assuming using pandas (which I havent used before) or some other means to present the user with a list like this:
interface admin operation user-label
1. 1/1/bits is normal --
2. 1/1/bits/pdh -- -- --
3. 1/1/dcn1 is out --
4. 1/1/dcn1/eth is out --
5. 1/1/dcn2 oos ua --
6. 1/1/dcn2/eth oos ua --
7. 1/1/p1 is out UNI
8. 1/1/p1/eth is out --
9. 1/1/p1/fp-1 is out --
10. 1/1/p5 is normal UPLINK
11. 1/1/p5/eth is normal --
12. 1/1/p5/fp-1 is normal --
13. 1/1/p5/mgmt-1 is normal untagmgmt
14. 1/1/p9 oos ua --
15. 1/1/p9/eth oos ua --
16. 1/1/p10 oos ua --
17. 1/1/p10/eth oos ua --
18. 1/1/ppstod is normal --
19. 1/1/ppstod/ppstod -- -- --
Which interface would you like to use?