def run(self, line): if not self.childs: _print("Exec %s(line=%s), overwrite this method!" % (self.name, line)) return print("\nIncomplete Command: %s\n" % line) self.print_childs_help()
def run(self, line): if not self.childs: _print("Exec %s(line=%s), overwrite this method!" % (self.name, line)) return print "\nIncomplete Command: %s\n" % line self.print_childs_help()
def run(self, line): destination = line.split()[-1] import subprocess try: subprocess.call(['traceroute', '%s' % destination]) except KeyboardInterrupt: _print("Traceroute canceled.") return
def run(self, line): arg = line.split()[-1] if arg not in self.args(): _print("%% Invalid argument: %s" % arg) _print("\tUse:") _print("\trunning-config -- Show RAM configuration") _print("\tstartup-config -- Show NVRAM configuration") return _print("Executing show %s..." % arg)
def _next_command(self, state, buf=''): args = self.childs.keys() completions = [c + ' ' for c in args if c.startswith(buf)] completions = completions + [None] logger.debug('PossibleCompletions=>%s' % completions) if len(completions) > 2 and state == 0 and not buf: logger.debug("Showing all completions...") _print("Possible Completions:") for child in self.childs.keys(): _print(" %s%s" % (child.ljust(16), self.childs[child].help)) return None return completions[state]
def run(self, line): self.prompt = "RouterA" self.prompt_delim = "#" password = getpass.getpass() if password != 'python': _print("%% Invalid Password, access denied") return configure = Command("configure", help="Enter configure mode") terminal = ConfigureTerminal("terminal") configure.addChild(terminal) show = Show('show', help="Show configurations", dynamic_args=True) self.addChild(configure) self.addChild(show) self.loop()
def run(self, line): self.prompt = "RouterA" self.prompt_delim = "#" password = getpass.getpass() if password != 'python': _print("%% Invalid Password") return configure = Command("configure", help="Enter configure mode") terminal = ConfigureTerminal("terminal") configure.addChild(terminal) show = Show('show', help="Show configurations", dynamic_args=True) self.addChild(configure) self.addChild(show) self.loop()
def run(self, line): _print("Exec %s(line=%s), overwrite this method!" % (self.name, line))
def run(self, line): args = line.split() if not len(args) == 2: self.respond('Please specify a tube') return False tube = args[-1] try: self.respond('Put a message onto tube "{0}":'.format(tube)) if tube not in self.beanstalkd.tubes(): self.respond( ' tube {0} does not exist and will be created'.format( tube)) priority = self.request(' priority (default: {0}): '.format( 2**31), default=None) delay = self.request(' delay (default: 0): ', default=0) ttr = self.request(' time-to-run (default: 120s): ', default=None) body = self.request( ' body (ctrl+d to continue):', default="", stream=True, ) self.respond(""" Confirm job: tube: {tube} priority: {priority} delay: {delay}s ttr: {ttr}s --body:-- {body} --------- """.format( tube=tube, priority=priority, delay=delay, ttr=ttr if ttr else 120, body=body, )) if not self.user_wants_to_continue(): return self.cancel() self.beanstalkd.use(tube) kwargs = {} if priority: kwargs['priority'] = priority if delay: kwargs['delay'] = int(delay) if ttr: kwargs['ttr'] = int(ttr) jid = self.beanstalkd.put(body, **kwargs) self.respond('Successfully created job: {0}'.format(jid)) except KeyboardInterrupt: _print('Cancelling put operation.') return False
def run(self, line): args = line.split() if not len(args) == 2: self.respond('Please specify a tube') return False tube = args[-1] try: self.respond('Put a message onto tube "{0}":'.format(tube)) if tube not in self.beanstalkd.tubes(): self.respond( ' tube {0} does not exist and will be created'.format(tube) ) priority = self.request( ' priority (default: {0}): '.format(2**31), default=None ) delay = self.request( ' delay (default: 0): ', default=0 ) ttr = self.request( ' time-to-run (default: 120s): ', default=None ) body = self.request( ' body (ctrl+d to continue):', default="", stream=True, ) self.respond(""" Confirm job: tube: {tube} priority: {priority} delay: {delay}s ttr: {ttr}s --body:-- {body} --------- """.format( tube=tube, priority=priority, delay=delay, ttr=ttr if ttr else 120, body=body, )) if not self.user_wants_to_continue(): return self.cancel() self.beanstalkd.use(tube) kwargs = {} if priority: kwargs['priority'] = priority if delay: kwargs['delay'] = int(delay) if ttr: kwargs['ttr'] = int(ttr) jid = self.beanstalkd.put(body, **kwargs) self.respond('Successfully created job: {0}'.format(jid)) except KeyboardInterrupt: _print('Cancelling put operation.') return False
def run(self, line): _print("Route added!")
def set_address(self, line): addr = line.split()[-1] _print("Setting interface %s address %s" % (self.interface, addr))
def emit(self, record): _print(self.format(record))