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 ...

Get JUNOS Automation Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.