EAPI Script To Push Extensions Across List of EOS Devices Using Python
EAPI Script To Push Extensions Across List of EOS Devices Using Python
shalin
Contents [hide]
Introduction
Pre-Requisites
Deployment methods
Script Components
Script Explanation
eAPI Script (automated_patch_push.py)
Github Repo Script
Introduction
This article demonstrates Arista’s EOS automation capabilities leveraging eAPI. This
document walks you through a script to Secure Copy (SCP) an extension on Arista
switches along with installing the extension on the list of switches defined in the script.
Pre-Requisites
This script is supported on Linux/Unix/Mac Operation Systems. The Arista eAPI must be
enabled on the switches and can be configured as follows:
Arista> enable
Arista# configure terminal
Arista(config)# management api http-commands
Arista(config-mgmt-api-http-cmds)# [no] shutdown
Arista(config-mgmt-api-http-cmds)# [no] protocol https [port ]
Arista(config-mgmt-api-http-cmds)# [no] protocol http [port ]
Deployment methods
There is a choice of different options to install extensions across devices.
a. User needs to securely copy the file into flash across all the switches
3. Using Python based eAPI script to install extensions across list of devices, we will
discuss this script further in the next section of this article.
Script Components
1. automated_patch_push.py
2. hosts.txt
3. output_logs.txt
Script Explanation
The script automated_patch_push.py reads the list of devices from the file hosts.txt and
creates a list. The script communicates with the list of Switches using eAPI configured on
the switch and the jsonrpclib module.
The script first copies the desired extensions on the switch and then runs the set of
commands to install the extension on the switch. The script then logs the failure/success of
the tasks in output_logs.txt file.
for ip in ips:
ip = ip.rstrip()
destination = "%s@%s:" % (user, ip)
#Command to SCP extension on the switch
2/3
for few secs....." %(ip)
try:
pexpect.run(scp_cmd)
child = pexpect.spawn(scp_cmd)
child.expect(r'.*assword:')
child.sendline(password)
child.expect(pexpect.EOF,timeout=5)
output_lines = child.before
print output_lines
except:
print "COPYING FILE SecurityAdvisory0030-Hotfix.swix TO SWITCH %s FAILED" % (ip)
else:
print "COPYING FILE SecurityAdvisory0030-Hotfix.swix TO SWITCH %s SUCCESFUL" %
(ip)
inShare
3/3