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 Python script, pyez-config-scan.py, in order to get the configuration of a JUNOS device and then sum up the totals of various configuration aspects. We’ll then output in a tabular form the totals for consideration by an operator. You can modify the patterns used to look for different configuration resources without much difficulty. The steps for the recipe are as follows:

  1. Start the Python script by defining the interpreter and importing the necessary modules:
      #!/usr/bin/env python      from jnpr.junos import Device      import sys      import getpass      import os      import json      import argparse
  1. Next, include a simple general purpose exception handler:
      def onError(exception_type, exception, traceback): print "%s: %s" % ...

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