Last active
January 23, 2017 12:36
-
-
Save tcuthbert/45a4e6fa94c343994fa0bbaf2733e315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
from time import sleep | |
from twisted.internet.defer import Deferred | |
from zope.interface import implements | |
from twisted.internet import reactor | |
from twisted.web.client import Agent | |
from twisted.web.http_headers import Headers | |
from twisted.internet.defer import succeed | |
from twisted.web.iweb import IBodyProducer | |
from twisted.python import log | |
#log.startLogging(sys.stdout, setStdout=False) | |
from trigger.netdevices import NetDevices | |
def handle_results(results, device): | |
if "SOME VALUE" in results: | |
return device.run_commands(['blah some ios command']) | |
# Create reference to upgraded switch. | |
nd = NetDevices() | |
dev = nd.find('pe1.demo.localdomain') | |
# Open connection to device. | |
dev.open() | |
# Pause due to timing inconsistencies experienced in some devices. | |
sleep(1) | |
# Initialise our results and kick off our main loop. | |
r11 = result = None | |
while True: | |
# The purpose here is to continually check for the string GO in our configuration and if we do | |
# we notify the current users the Animal hierarchy | |
r11 = dev.run_commands(['show run | in GO']) | |
sleep(2) | |
try: | |
if 'GO' in r11.result[0]: | |
print "You must obey your pythonic overlord." | |
r11 = dev.run_commands(['send *\rPYTHONS EAT GOPHERS\r\x1a']) | |
r11.addCallback(handle_results, dev) | |
result = r11.result[0] | |
r11.addBoth(dev.close) | |
break | |
else: | |
print "Did you know I am running in a while True loop?!?!?!" | |
except: | |
pass | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment