Skip to main content

Junos and Python – Junos PyEZ – Part 1

Feel like automating some configurations, monitoring and troubleshooting on Junos? Step in Python and Junos PyEZ framework ( Junos PyEZ is a framework for Python which allows “quite easy” approach for performing automation and configuration tasks on Junos-platform devices. It is also easy to understand for non-programmers so you really don’t have to have deep Python understanding for basic tasks. On protocol level it uses Netconf over SSH for connecting to the device.

The requirements are Python 2.7 and Junos PyEZ framework. I have my test platform running on CentOS 6.6. CentOS 6.6 comes by default with Python 2.6 so it needs updating or new Python 2.7 version installed on the side. You can check the quick guide I wrote for installing Python 2.7 on CentOS 6.6 here:

Test devices that I’m using are Juniper SRX100H and Juniper Firefly Perimeter (virtual SRX). The only prerequisites for Junos PyEZ to work is that you enable Netconf support on the device.

Verify that Netconf is working. Notice that Netconf over SSH is using tcp/830 and NOT tcp/22

Install Junos PyEZ (you must already have Python 2.7 and PIP installed, check my previous post on how to do this for CentOS 6.x).

That’s it! Now you’re ready to do some Python – Junos programming! Let’s see some quick and dirty examples. Find below, in the code blocks, commands and comments on what is happening with each command.


Connect to Junos device and get basic facts


Query Ethernet ports


Query routing table


In the following posts I will show how to make configuration changes and use the more advanced abilities of Junos PyEZ.

2 thoughts to “Junos and Python – Junos PyEZ – Part 1”

  1. >>> while x < len(eth_ports):
    … print "Interface: " + eth_ports.keys()[x]
    … print eth_ports[x].items()
    … x += 1

    Traceback (most recent call last):
    File "”, line 1, in
    NameError: name ‘x’ is not defined

    ansible@vagrant-ubuntu-trusty-64:~/magda$ ansible-galaxy –version
    config file = /etc/ansible/ansible.cfg
    configured module search path = [u’/home/ansible/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
    ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
    executable location = /usr/local/bin/ansible-galaxy
    python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.