O'Reilly logo

JUNOS Automation Cookbook by Adam Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

We’re going to write a new Python script, pyez-command-line.py, that will take an argument a Junos device name and a command line to execute on the device:

pyez-show-route.py [-h] [-p port] [-u username] target “command”

The following table gives the argument and description used with pyez-show-route.py:

Argument Description
-p TCP port to contact NETCONF-over-SSH
-u Username
  1. Start by defining the UNIX script interpreter in the first line of the file as usual and then import the Python standard library and PyEZ definitions required to do the job:
      #!/usr/bin/env python      import sys      import getpass      import os      import json      import argparse      from jnpr.junos import Device      from lxml import etree
  1. Define a general-purpose exception ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required