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

  1. Start with the typical boilerplate to start a Python script. Define the script interpreter. Import the required standard library modules. Define a general error 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 = onError
  1. Use ...

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