Commit 55e5b9a2 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added console feature

parent ef94cef9
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ class CliHandler(RegisteredCCHandler):
       CliHandler.jobs
       CliHandler.cancel
       CliHandler.jobspurge
       CliHandler.console
       CliHandler.rshell
       CliHandler.rshell_resize
       CliHandler.rshell_wait
@@ -667,6 +668,28 @@ class CliHandler(RegisteredCCHandler):
                                           'hv_dest': dest['id'],
                                           'author': self.client.login})

    @listed
    def console(self, tql):
        """ Start a remote console on object matching the provided tql.

        :param tql: tql matching only one object on which start the console
        :return: the label of the created tunnel
        """
        self.check('console', tql)
        objects = self.server.list(tql, show=('r', 'p', 'h'))
        if len(objects) != 1:
            raise NotImplementedError('Console only support one tunnel at time for now')
        errs = Reporter()
        for obj in objects:
            if obj['r'] in ('vm',):
                client = self.server.get_client(obj['p'])
                srv_to_host_tun = client.console(obj['h'])
                cli_tun = self.client.register_tunnel('console', client, srv_to_host_tun)
                errs.success(obj['id'], 'tunnel started.', output=cli_tun.label)
            else:
                errs.error(obj['id'], 'bad role')
        return errs.get_dict()

    @listed
    def rshell(self, tql):
        """ Start a remote shell on object matching the provided tql.
+7 −0
Original line number Diff line number Diff line
@@ -13,6 +13,13 @@ class HostClient(Client):
    def execute(self, command):
        return self.conn.call('execute_command', command)

    def console(self, name):
        """ Start a remote console on the specified vm.
        """
        label = self.proxy.vm_open_console(name)
        tun = self.conn.create_tunnel(label=label)
        return tun

    def rshell(self):
        """ Start a remote shell on the host.
        """