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 to do it...

We're going to modify the initialization code within the application to check for the presence of a password cache within a user-specific location. If the file is found, we read a JSON-structured dictionary of username, remote device, and password. If the file is not found, or is otherwise inaccessible, then we assume an interactive operation and read a password from the terminal.

  1. We can modify our Python rest.py app from the previous recipes to use this technique with the following code:
      args=cmdline.parse_args()      try:         passwordFile = os.path.expanduser("~")+"/.pwaccess"         if os.stat(passwordFile)[0]&63==0:            passwords = json.load(open(passwordFile))            password = passwords[args.u+"@"+args.target]      else: sys.stderr.write("Warning: ...

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