Created
August 7, 2015 21:55
-
-
Save theY4Kman/f18c624478a4b45932c2 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
| ############################################################################### | |
| # 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