def config(self, argv): """config Enter configuration table edit mode.""" root = get_root(self._obj) cmd = self.clone(ConfigCommands) cmd._setup(root, "%%YConfig%%N:%s> " % (root.name,)) raise CLI.NewCommand(cmd)
def query(self, argv): """query Start a query editor.""" q = _session.query(self._obj) cmd = self.clone(QueryCommands) cmd._setup(q, "Query:%s> " % (self._obj.__name__,)) raise CLI.NewCommand(cmd)
def use(self, argv): """use <table> Use the given table. Name is class name of mapped table.""" name = argv[1] t = getattr(models, name) cls = _TABLE_EDITOR_MAP.get(name, TableCommands) cmd = self.clone(cls) cmd._setup(t, cls.get_prompt(t)) raise CLI.NewCommand(cmd)
def parent(self, argv): """parent Move to parent record.""" if self._obj.parent is not None: cmd = self.clone(TestResultRowCommands) cmd._setup(self._obj.parent, TestResultRowCommands.get_prompt(self._obj.parent)) raise CLI.NewCommand(cmd) else: self._print("No parent.")
def inspect(self, argv): """inspect ... Inspect a row.""" dbrow = self._select_one(argv) if dbrow is not None: cls = _ROW_EDITOR_MAP.get(self._obj.__name__, RowCommands) cmd = self.clone(cls) cmd._setup(dbrow, cls.get_prompt(dbrow)) raise CLI.NewCommand(cmd)
def results(self, argv): """results Show latest test results for this test suite.""" tr = self._obj.get_latest_result(_session) if tr is not None: cmd = self.clone(TestResultRowCommands) cmd._setup(tr, TestResultRowCommands.get_prompt(tr)) raise CLI.NewCommand(cmd) else: self._print("No results found.")
def interface(self, argv): """interface [add-options] <add|del|show|edit|create|attach> name Addd a new interface to this equipment. When adding, specify interface parameters with long options: --ipaddr=<ipaddr> --macaddr=<macaddr> --iftype=<iftype> --network=<netname> --ifindex=<ifindex> when deleting simply specify the name. The attach command will attach an already existing interface where the parameters are the selector. """ opts, longopts, args = self.getopt(argv, "") for opt, arg in opts: pass cmd = args[0] if cmd.startswith("add"): name = args[1] self._obj.add_interface(_session, name, ifindex=int(longopts.get("ifindex", 1)), interface_type=longopts.get("iftype", "ethernetCsmacd"), macaddr=longopts.get("macaddr"), ipaddr=longopts.get("ipaddr"), network=longopts.get("network")) elif cmd.startswith("del"): name = args[1] if self._ui.yes_no("Delete interface %s, are you sure?" % (name,)): self._obj.del_interface(_session, name) elif cmd.startswith("sho"): try: name = args[1] except IndexError: for intf in self._obj.interfaces.values(): self._print(intf) else: self._print(self._obj.interfaces[name]) elif cmd.startswith("edi"): name = args[1] intf = self._obj.interfaces[name] cmd = self.clone(InterfaceRowCommands) cmd._setup(intf, InterfaceRowCommands.get_prompt(intf)) raise CLI.NewCommand(cmd) elif cmd.startswith("crea"): intf = create(models.Interface, self._ui) intf.equipment = self._obj _session.add(intf) _session.commit() elif cmd.startswith("att"): if len(args) > 1: longopts["name"] = args[1] self._obj.attach_interface(_session, **longopts)
def chdir(self, argv): """chdir/cd <container> Make <container> the current container.""" name = argv[1] if name == "..": raise CLI.CommandQuit() item = self._get(name) if isinstance(item, dict): cmd = self.clone(ConfigCommands) cmd._setup(item, "%Ykey%N:{}> ".format(name)) raise CLI.NewCommand(cmd) else: self._print("%s: not a container." % (name,))
def fiddle(self, argv): """fiddle <handle> fiddle with a remote file object. Provide the handle id obtained from 'flist'.""" args, kwargs = CLI.breakout_args(argv[1:], vars(self._obj)) if args: handle = args[0] else: handle = self._obj.flist()[0] finfo = self._obj.get_handle_info(handle) if finfo: cmd = self.clone(FileCommand) cmd._setup(self._obj, handle, "%s> " % (finfo, )) raise CLI.NewCommand(cmd) else: self._print("No such handle on server.")
def chdir(self, argv): """chdir/cd <container> Make <container> the current container.""" name = argv[1] if name == "..": raise CLI.CommandQuit() row = _session.query(models.Config).filter(and_( models.Config.name==name, models.Config.container==self._obj)).one() if row.value is NULL: pathname = ".".join([self._obj.name, row.name]) cmd = self.clone(ConfigCommands) cmd._setup(row, "%%YConfig%%N:%s> " % pathname) raise CLI.NewCommand(cmd) else: self._print("%s: not a container." % (name,))
def interact(self, argv): """interact <pid> Interact with the raw file-like interface of a process. Provide the pid as supplied from plist.""" args, kwargs = CLI.breakout_args(argv[1:], vars(self._obj)) if args: pid = int(args[0]) else: pid = self._obj.plist()[0] pid = self._obj.poll(pid) if pid: cmd = self.clone(ProcCommand) cmd._setup(self._obj, pid, "pid %s> " % (pid, )) raise CLI.NewCommand(cmd) else: self._print("No such pid on server.")
def use(self, argv): """use <name> Use the specified agent. """ name = argv[1] clnt = self.get_remote(name) try: clnt.alive() except pyro.ConnectionClosedError: del self._objs[name] self._print("Remote agent has disconnected.") return cliclass = CLIManager.get(clnt) if cliclass is not None: cmd = self.clone(cliclass) cmd._setup(clnt, name) raise CLI.NewCommand(cmd) else: self._ui.error("No CLI found for that agent!")
def network(self, argv): """network Enter network configuration mode.""" cmd = self.clone(NetworkCommands) cmd._setup(models.Network, "%BNetwork%N> ") raise CLI.NewCommand(cmd)
def users(self, argv): """users Enter User editor mode.""" cmd = self.clone(UserCommands) cmd._setup(models.User, "%YUsers%N> ") raise CLI.NewCommand(cmd)