Tuesday, July 12, 2016

My Second Step towards Automation: Install the PyEZ Library and Connect Your Remote Device

Junos PyEZ micro framework has been built and tested tested with Python 2.6 and 2.7. So before moving ahead you must install Python 2.6 or 2.7.

Use:- “pip install junos-eznc” on your ubuntu or linux laptop to install PyEZ library or simply clone it from GIT hub “pip install git+https://github.com/Juniper/py-junos-eznc.git”

. You can install GIT on windows and start playing with it also. This library can be easily installed on your working laptop and you can connect any of your physical or virtual juniper device. Verify Your Installation
In your root directory make sure you have correct folders under python directory as below listed:-
1. C:\Python27\Lib\site-packages\junos_eznc
2. C:\Python27\Lib\site-packages\jnpr\junos

You can work with python in interactive mode or simple by creating a python files and run it from the python shell directly. Interactive shell is real time and generates the output immediately. First PyEZ Program from intractive shell to capture the facts of the device.
1. from jnpr.junos import Device
2. dev = Device(host='', user='lab', passwd='lab')
Above command is Creating the device instance and provide the hostname, any parameters required for authentication, and any optional parameters.
3. Dev.open()
Above Command is Connecting to the device by calling the open() method.
4. print dev.facts
Above command is Printing the device facts, which are automatically retrieved when the connection and NETCONF session are established.
5. dev.close()
Above command is used to close the NETCONF session

If you are looking for to extract the particular information from the facts. In that case you can change the dev.facts to dev.facts['serialnumber']. By executing this command you will get the serial number of chassis.

People who read this post also read :

No comments: