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 it works…

In step 1, we create a Python environment with the required modules imported into the namespace. In step 2, we define a simple exception handler to print a message and exit if and when things go wrong.

As we move to step 3, we set up the execution of our script by parsing the command line arguments in order to set the runtime options. We use the argparse module to do the work for us here, because it’s quick, convenient, and is included in the standard Python distribution. The only change from previous recipes using Python’s argparse compared to this is that we demote the target device to be specified by a –t switch rather than the main argument. This is because we want the main argument to be the destination to query.

In step ...

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