Wrapping my hands up in Python
I am coding up a quick script to pull some stats from a CLI in JUNOSe. I used to write a lot of PERL, from standard regex parsing scripts, socket programming, and various network related applications. As of late I have found Python to be extremely powerful and easy to work with.
I have started using pexpect in place of using regular TCL expect.
Here is an example of a quick script to pull the queue statistics from a Juniper ERX:
#!/usr/bin/python
# quick JUNOSe Queue View
import pexpect
import getpass
mypassword = "juniper123"
interface_name ="fast 0/0"
host = raw_input('Hostname: ')
child = pexpect.spawn('telnet %s'%(host,))
child.expect ('(?i)assword')
child.sendline (mypassword)
child.expect ('>')
child.sendline ('show version')
child.expect ('>')
#print child.before
child.sendline ('enable')
child.expect ('#')
child.sendline ('term leng 0')
child.expect ('#')
child.sendline ('show ip interface fast 5/0 | begin queue 0')
child.expect ('#')
queue_out = child.before
print "The output of the queue is :"
print queue_out
Next step will be to parse the actual queue value and plot this value in time.
Originally published on trumanboyes.blogspot.com. See the archived copy.