Programmatically Updating EdgeOS Configurations with Python and Fabric
In this article, we will discuss how to programmatically update the configuration of EdgeOS devices using Python and the Fabric library. Fabric is a high level Python library designed to execute shell commands remotely over SSH, making it an ideal tool for managing and configuring network devices.
Prerequisites
To follow along with this article, you will need the following:
- A device running EdgeOS
- Python 3.6 or higher installed on your local machine
- The Fabric library installed. You can install it using pip:
pip install fabric3Establishing an SSH Connection
The first step in using Fabric to manage EdgeOS devices is to establish an SSH connection. This can be done using the connect function, which takes the hostname or IP address of the device as an argument, as well as any additional connection parameters such as the username and password.
from fabric import Connection
conn = Connection(host='edgeos-device', user='admin', connect_kwargs={
'password': 'password'
})Running Commands
Once the SSH connection has been established, you can use the run function to execute commands on the remote device. For example, to retrieve the current configuration of the device, you can use the following code:
config = conn.run('show running-config').stdoutMaking Changes
To make changes to the configuration of the device, you can use the put function to upload files to the device, and the run function to execute commands that modify the configuration.
# Upload a new configuration file
conn.put('new-config.conf', 'new-config.conf')
# Load the new configuration
conn.run('configure replace new-config.conf')In this article, we have discussed how to use Python and the Fabric library to programmatically update the configuration of EdgeOS devices. By establishing an SSH connection and executing commands remotely, you can easily manage and configure your EdgeOS devices in an automated and efficient manner.