Automation
Automation

Scripting How-To: Automate Junos using Python scripts

by Juniper Employee on ‎04-22-2016 12:57 PM - edited on ‎08-23-2017 11:34 AM by Administrator Administrator
04.22.16   |   12:57 PM

Using Python Scripts to Automate Junos

 

You can use Python scripts to automate Junos. Click demo scripts to access the repository in GitHub.

The script repository contains three sections or phases:

 

  • Build phase - provides offline configuration by using a template and YAML to create a baseline configuration with specific data per device.
  • Run phase - provides the latest script for demo purposes.
  • Audit phase - shows how to use the Python monitor and verify complete network information.

 

Environment Setup

 

To set up your environment, you must:

 

  1. Download the latest version of Python 2.7 available from the Python.org website:
    https://www.python.org/downloads/windows/
  2. Correctly set up your environment and verify that all dependencies are installed. For more details, see the Setup Guide.
  3. Create the LAB description. All scripts use the same dictionary file to list devices that are part of this LAB. This file is located under script directory and is named scripts/lab-poc.yml. Below is an example of the content that you should modify according your own environment setup:

---
  - 172.30.108.228
  - 172.30.108.229
  - 172.30.108.230
  - 172.30.108.232
  - 172.30.108.233
  - 172.30.108.234
  - 172.30.108.236

 

Script Usage

 

All scripts use an option that enables you to change this name (check option -l for each script).

 

All scripts use parameters to ensure they can match your environment. They have at least the following parameters:

 

  • --username | -u: set the username used to open a connection on devices
  • --password | -p: set the password used to open a connection on devices

To list all options available for each script, you can use --help or -h trigger to display help.

 

Conclusion

 

  • Fork it using GitHub.
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new pull request
'
Comments
01.17.17
jsilverman@juniper.net

Remember that if you enter a password on the command line in bash, then it will be recorded in the ~/.bash_history file.  That's okay if nobody else had access to your computer, but remember that you computer sometimes gets backed up.  So remember to clean out the ~/.bash_history file.  It is sufficient to use a text editor.