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

There’s more

If you’re not using SSH key-based authentication for whatever reason, there are a couple of options available for managing passwords. You can either default to using the executing user’s username and prompt interactively for a password:

#!/usr/bin/env pythonfrom pprint import pprintfrom jnpr.junos import Devicefrom getpass import getpassdev = Device(host='10.0.201.201', password=getpass()) dev.open()pprint(dev.facts)dev.close()

Or, you can use a strategy similar to that deployed in Chapter 3, Using Slax to Write Op Scripts when using the REST interface. Adopt a user-specific file cache of the stored credentials for the target hosts:

#!/usr/bin/env pythonimport sysimport getpassimport osimport jsonfrom pprint import pprintfrom ...

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