Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created August 7, 2015 21:55
Show Gist options
  • Select an option

  • Save theY4Kman/f18c624478a4b45932c2 to your computer and use it in GitHub Desktop.

Select an option

Save theY4Kman/f18c624478a4b45932c2 to your computer and use it in GitHub Desktop.
###############################################################################
# MY CODE
###############################################################################
class Command(object):
command = None
def __init__(self, arg=None):
self.arg = arg
def get_command(self):
return self.command
def run_command_chain(command_class):
# Create reactor
# Hook up all the bits
# Run the reactor
pass
###############################################################################
# YOUR CODE
###############################################################################
class FigureOutInterface(Command):
command = 'show vlan 0'
def process(self, command_output):
if command_output == '1':
return SwitchTypeOneCommand(command_output.strip())
else:
return SwitchTypeTwoCommand(command_output)
class SwitchTypeOneCommand(Command):
def get_command(self):
return 'disable ' + self.arg
def process(self, command_output):
if command_output == 'error':
raise Exception
class SwitchTypeTwoCommand(Command):
def get_command(self):
return 'ultra-disable ' + self.arg
def process(self, command_output):
if command_output == 'error':
raise Exception
if __name__ == '__main__':
run_command_chain(FigureOutInterface())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment