Juniper's Python is accessible from the shell.
user@QFX5100> start shell
root@QFX5100% python
Python 2.7.1 (r271:86832, Jan 21 2014, 12:38:40)
[GCC 4.2.1 (for JUNOS)] on junos
Type "help", "copyright", "credits" or "license" for more information.
However I don't know what modules bundled in the OS are used to actually access Junos API.
>>> help ('modules juniper')
Here is a list of matching modules. Enter any module name to get more help.
>>> help ('modules junos')
Here is a list of matching modules. Enter any module name to get more help.
>>> help ('modules jnpr')
Here is a list of matching modules. Enter any module name to get more help.
I did find that it does support telnetlib.
>>> help ('modules telnet')
Here is a list of matching modules. Enter any module name to get more help.
telnetlib
>>> exit()
Which means you can actually access the QFX via telnet. In the below script I telnet to the switch and send a broadcast message
root@QFX5100% python hello.py
Broadcast Message from jnpr@SW3a
(/dev/ttyp2) at 22:32 PDT...
hello world
----------
I'm not when the Junos API will be available or how to access it. I'm guessing there may be some restrictions for this as you wouldn't want have a hacker creating mischief with python scripts.
source code:
root@QFX5100% more hello.py
---------------------
import sys
import telnetlib
HOST = "192.168.1.1"
tn = telnetlib.Telnet(HOST)
user = "user"
password = "password"
tn.read_until("login:")
tn.write(user + "\n")
tn.read_until("Password:")
tn.write(password + "\n")
tn.read_until(">")
tn.write('request message all message "hello world" \n')
tn.read_until(">")
tn.write("exit\n")
tn.close
No comments:
Post a Comment