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-isis.py, to connect to one of our JUNOS OS routers, extract the link-state database, and then output a compressed JSON representation of the network graph seen by ISIS.

  1. Include the standard boilerplate that we base all of our Python-based automation apps on. Define the interpreter, import the standard library modules, set a general purpose exception handler
      #!/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):          sys.stderr.write("%s: %s\n" % (exception_type.__name__,                           exception)) sys.excepthook ...

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