Hi,

Following the post on installing PYEZ

https://r2079.wordpress.com/2016/06/28/pyez-first-impressions-installation/

Let us explore a very simple program which connects to the box and gets the version from the box

Step 1 – Configure the Device to accept Device – You do this by configuring NETCONF SSH under system services

1

Let’s look at how PYEZ Code looks. Am using a Ubuntu Linux which is on my Local LAN.

#########################################################################

from jnpr.junos import Device
import sys
from pprint import pprint
dev = Device(‘10.0.0.1′,user=’labroot’,password=’lab123′)
try:
dev.open()
except Exception as err:
print “Unable to connect to Device”, err
sys.exit(1)
print “\n#################################”
print “\n Successfully Connected to M120”
print “\n#################################”

print “\n \n show version | no-more”

print dev.cli(“show version | no-more”)

dev.close()

print “\n#############################################”
print “\nConnection with M120 Terminated Successfully”
print “\n#############################################”

print “\n \n END OF THE PROGRAM”

####################################################################

Let us try to execute the program.

2

You could improvise more on this by simply adding a RAW_INPUT function and then Program will ask for IP Address and will feed it to the system, than you feeding it manually. Below code will help you for the same.

####################################################################

from jnpr.junos import Device
import sys
from pprint import pprint
d = raw_input(“\n ENTER THE IP ADDRESS OF THE DEVICE: “) #Adding this would now make the program to request you for an IP address
dev = Device(d,user=’labroot’,password=’lab123′)
try:
dev.open()
except Exception as err:
print “Unable to connect to Device”, err
sys.exit(1)
print “\n \n show chassis hardware detail”

print dev.cli(“request support information | no-more”)
print dev.cli(“show log messages | no-more”)
print dev.cli(“show log chassisd | no-more”)

dev.close()
print “\n END OF THE PROGRAM”

####################################################################

We will see more of PYEZ and underlying functions in subsequent posts.

Regards
Rakesh M

Advertisements