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

Step 1 imports all of the Python modules that we're going to use. Most are within the standard library distribution, but in this recipe we also make use of Juniper's jxmlease module which makes parsing XML into Python data structures a bit easier.

Step 2 defines the sequence of RPCs that we will execute in order to make the configuration change. In this case, we are using a sequence of four RPCs: lock, edit-config, commit, unlock. We will encode an XML document defining these four RPCs in an HTTPS POST request and submit it to the REST server.

Step 3 defines a function to implement a cached credential in the user's home directory, falling back to an interactive prompt otherwise, as developed in the previous recipe.

Step 4 ...

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