Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Automating Network Configuration Changes Using Scripts

 

When making a change to an existing configuration, such as to accommodate new requirements, you might find it helpful to create scripts to capture the more mundane steps involved in such changes. If there are steps that you always (or often) have to perform when you make changes, you can collect those steps into a script to be run at the right time. The scripts can be run from the CLI manually by creating an operation (op) script, or they can be triggered when an event occurs by creating an event script.

In addition to achieving the desired outcome of your configuration change, you also want to make sure that there are no undesired outcomes. You can automate validation of future configuration changes by using a commit script, which is executed when a commit is issued. Commit scripts allow you to enforce custom configuration rules and to execute any additional steps that you want to run automatically.

Creating on-box scripts is detailed in the Automation Scripting Feature Guide.

If you are interested in creating an off-box script or application, then a client that makes use of the NETCONF protocol is what you want. Raw NETCONF is not well suited for someone who is learning how to automate network operations. We recommend using Junos PyEZ. By using Python and the Junos PyEZ library, you can very quickly create scripts to manage your device running Junos OS. Junos PyEZ takes care of much of the overhead of connecting and communicating with the device. Figure 1 illustrates how, by leveraging Junos PyEZ, a NETCONF script written in Python is reduced from 48 lines to just 7.

Figure 1: Why We Call It Junos PyEZ
Why We Call It Junos PyEZ

By using Python and Junos PyEZ on any convenient system (for example, your laptop), you can connect to a device running Junos OS and quickly examine its attributes. From there you can add configuration change commands. A good approach to get started is to copy and run the Junos PyEZ samples, such as “Hello, World”, on your local system, and then run them successfully against your devices running Junos OS; the samples are available from GitHub. This will help you gain familiarity and confidence in Junos PyEZ’s power and utility. The Junos PyEZ documentation is available at Junos PyEZ. For a video demonstration of Junos PyEZ, see Junos PyEZ - Hello, World .