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:
- 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
- Next, include a simple general purpose exception handler:
def onError(exception_type, exception, traceback): print "%s: %s" % ...