Blog Viewer

Scripting How-To: Automate Junos using Python scripts

By ksator posted 04-22-2016 12:57

  

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

#Automation
#Python
#How-To
#ScriptingHow-To
#JUNOS

Permalink