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