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-hardware.pyez, that will take an argument a JUNOS device name, and will respond with a list of hardware components within.

pyez-table-hardware.py [-h] [-p port] [-u username] target

Argument

Description

-p

TCP port to contact NETCONF-over-SSH

-u

Username

 

We’re going to do this using a pre-defined Table/View combination that ships with the PyEZ framework. The steps for the recipe are as follows:

  1. First of all, start by including the usual Python preamble of script interpreter and Python modules. Include the jnpr.junos.op.inventory.ModuleTable definition:
      #!/usr/bin/env python      import sys      import getpass      import os      import json      import argparse from jnpr.junos ...

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