Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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.")
Beispiel #5
0
 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)
Beispiel #6
0
 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.")
Beispiel #7
0
 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)
Beispiel #8
0
 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,))
Beispiel #9
0
 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.")
Beispiel #10
0
 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,))
Beispiel #11
0
 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.")
Beispiel #12
0
 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!")
Beispiel #13
0
 def network(self, argv):
     """network
 Enter network configuration mode."""
     cmd = self.clone(NetworkCommands)
     cmd._setup(models.Network, "%BNetwork%N> ")
     raise CLI.NewCommand(cmd)
Beispiel #14
0
 def users(self, argv):
     """users
 Enter User editor mode."""
     cmd = self.clone(UserCommands)
     cmd._setup(models.User, "%YUsers%N> ")
     raise CLI.NewCommand(cmd)