Skip to content

Instantly share code, notes, and snippets.

@tcuthbert
Created May 10, 2016 15:07
Show Gist options
  • Save tcuthbert/fa96cbf0340756e97f28da1b9c0fd201 to your computer and use it in GitHub Desktop.
Save tcuthbert/fa96cbf0340756e97f28da1b9c0fd201 to your computer and use it in GitHub Desktop.
import sys
from datetime import datetime
import time
from pprint import pprint
from trigger.cmds import Commando
from twisted.python import log
from twisted.internet import reactor
from trigger.netdevices import NetDevices, NetDevice
if __name__ == '__main__':
# log.startLogging(sys.stdout)
nd = NetDevices()
dev = nd.find('r1.demo.local')
dev.open()
commands = ['term length 0', 'sh ip int brief']
results1 = dev.run_commands(commands)
start_time = time.time()
fired1 = False
fired2 = False
results2 = None
while True:
end_time = time.time()
if end_time - start_time >= 10.0:
break
try:
if results1.results.values()[0] and fired1 is False:
print results1.results
fired1 = True
except Exception as e:
pass
try:
if fired2 is False and end_time - start_time >= 5.0:
results2 = dev.run_commands(['show version | in uptime'])
fired2 = True
if fired2 is True and results2.results.values()[0]:
print results2.results
print "You're fired"
break
except Exception as e:
pass
dev.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment