Skip to content

Instantly share code, notes, and snippets.

@tcuthbert
Created November 21, 2016 23:04
Show Gist options
  • Save tcuthbert/0ff027d3e0523f86a9c257914a7d7428 to your computer and use it in GitHub Desktop.
Save tcuthbert/0ff027d3e0523f86a9c257914a7d7428 to your computer and use it in GitHub Desktop.
party.py
import sys
import string
from trigger.netdevices import NetDevices
from twisted.internet import reactor
from twisted.python import log
log.startLogging(sys.stdout, setStdout=False)
nd = NetDevices()
devices = [nd.find("pe1.demo.localdomain"), nd.find("pe2.demo.localdomain")]
def print_result(data):
"""Display results from a command"""
print 'Result:', data
def stop_reactor(data):
"""Stop the event loop"""
print 'Stopping reactor'
if reactor.running:
reactor.stop()
def get_deployment_config(device):
with open('deploy/{device}.conf'.format(device=device), 'r') as f:
return f.readlines()
# Schedule the deployment of each devices new configuration
for device in devices:
# Pull in new configuration for device
deployment = get_deployment_config(device.nodeName)
deployment = [i.translate(string.maketrans('\n', ' ')) for i in deployment]
# Create an event chain that will execute a given list of commands on this
# device
#async = device.execute(['copy tftp://192.168.100.10/{host}.conf'.format(host=device.nodeName) + " running-config\r\r"])
async = device.execute(['config t'] + deployment, with_errors=True)
# When we get results from the commands executed, call this
async.addCallback(print_result)
# Once we're out of commands, or we an encounter an error, call this
async.addBoth(stop_reactor)
# Start the event loop
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment