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 PyEZ script, process-mplsvpn.py, to connect to one of our JUNOS OS routers, extract the BGP routing information for the VPN community of interest, and then output a compressed JSON representation of the resulting network graph.

  1. Start with the typical boilerplate in order to define the script interpreter, import the Python standard library modules. Define a general purpose error handler to print a polite message and exit.
      #!/usr/bin/env python      import sys      import getpass      import os      import json      import argparse      import struct      import socket      import io      from jnpr.JUNOS import Device      from lxml import etree            # Error handling      def onError(exception_type, exception, traceback): print "%s: %s" % (exception_type.__name__, ...

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