Itential Automation Gateway

Take Your Network Automation Scripts to the Next Level

Overview

Itential’s Automation Gateway Enables Network Teams to Securely Organize, Run, & Share Their Libraries of Python Scripts

Many networking practitioners have discovered the plethora of tools and scripts that are openly available to help save time by automating common networking tasks. While there are a lot of different languages available, one of them seems to be the overall favorite in the world of network automation —Python. Because of Python’s popularity, there are several networking libraries available that can help facilitate automation across network devices, and many folks have written Python scripts leveraging these networking libraries and made them freely available for anyone to use. With a little tweaking, you can take one of these scripts and make it into something you can use in your own environment.

You may find that this automation saves you a meaningful amount of time every day, but the impact that it could have for your team would be even more significant.

Here are a few questions to ask yourself:

  • If this script is useful to you, would it also be useful for other people in the networking organization?
  • Could another member take your script, modify it, and turn it into something even more useful?
  • Is there a way to take this script and easily make it available through a RESTful API?

Onboarding Your Python Script

By onboarding your Python script into Itential’s Automation Gateway, your script will be organized and made available in the application to other members of your team. Your colleagues can open the script and examine it to help understand how it works, and even safely test it in a lab environment.

At this point, someone may decide to take your script and make a copy of it, so it can be modified with changes that work for other parts of the network. Of course, that script is now available for you to also view and test as well. This opens up the ability to show everyone on the team a library of useful automations and invites them to participate in learning how these scripts work and build useful derivatives.

As a final achievement, your team may want to allow certain scripts to be published to teams outside of the networking organization, so they can be used in a self-service method (and not tie up anyone to do the work manually, of course!). This is best done using RESTful APIs, and normally this would require additional python libraries and a lot of non-network code to accomplish. However, in Itential’s Automation Gateway, this process is quite simple and straightforward.

Decorating Your Python Script

  • From the Scripts category, click on your script.
  • Click on the Edit button below.
  • Decorate your script.
  • Click the Save button.

Decorating your script is the process of creating a JSON schema the defines the necessary API parameters needed for your script to run and is based on the command-line options that are used in the script.

#! /usr/bin/python
# An example network automation python script using netmiko to get the ios version from a cisco device.
# In your environment, you will need to provide the device details in the ConnectHandler section.
import sys
from netmiko import ConnectHandler
import re
exec('from device_info import %s as device'%sys.argv[1].replace("-", "_"))
# Open CLI connection to device
with ConnectHandler(ip = device["address"],
                    port = device["ssh_port"],
                    username = device["username"],
                    use_keys = True,
                    key_file = device["key_filename"],
                    device_type = device["device_type"]) as ch:
  command = "show version"
  output = ch.send_command(command)
#find version in output using regular expressions
regex_version = re.compile(r'Cisco\sIOS\sSoftware.+Version\s([^,]+)')
version = regex_version.findall(output)
print(version[0])

As an example, here is a script (ios-show_version.py) that requires an IP address or hostname of a network device. Using this command-line option, we can create a required field like this:

Testing Your Decorated Script

Once the script is decorated, it is available through an API call. You can test that the script runs correctly using the API from inside Automation Gateway.

  • Click the 3 lines, and select API-Documentation 2.0
  • In the API Documentation window, scroll down to the section titled “Scripts”
  • Click on the entry that says “Execute a script”
  • Then click on “Try it out”
  • Edit the “Script Parameters” section to enter the correct parameters as we have defined. In this case, let’s use the string “CORE-ATL-0″ as the network device hostname.
  • Under “Script name” enter the name of the script (ios-show_version.py)
  • Click “Execute”

Scroll down a bit further in the API Documentation window and look at the responses. If everything worked, you will see the script’s output in the section labelled 200, which is a successful response code. If there were any errors, they will populate in the 400, 404, or 500 sections, which are error response codes. If you receive an error, you may need to make modifications to your script’s decoration or take a look at the input parameters that you entered in the “Script Parameters” section and verify that the data and format are correct.

Accessing your Script using the API

Once the API decoration is complete and tested successfully, an external application, tool, or system with the appropriate credentials can access and run the script, creating the ability to build your CLI-based scripts into an API-based self-service catalog.

Using Itential’s Automation Gateway as a central point for your team to share, modify, execute, and publish your python network automation scripts is a great way to multiply the benefits of network automation across the network team, and potentially across the IT organization.

Know Your Network. Automate Your Network.

Get Started with Itential Today.