Commit 709f03d2 authored by Antoine Millet's avatar Antoine Millet
Browse files

[bug#3919] (Re)-implemented execute handler method.

parent c87e64c3
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -433,6 +433,36 @@ class CliHandler(OnlineCCHandler):
                
        return errs.get_dict()

    @listed
    def execute(self, conn, query, command):
        '''
        Execute command on matched objects (must be roles hv or host).

        :param query: the tql query to select objects.
        :param command: the command to execute on each object
        :return: a dict where key is the id of a selected object, and the value
            a tuple (errcode, message) where errcode is (success|error|warn) and
            message an error message or the output of the command in case of
            success.
        '''

        self._check(conn, 'execute', query)
        objects = self._server.list(query, show=set(('r',)))
        errs = Reporter()
        for obj in objects:
            if obj['r'] not in ('hv', 'host'):
                errs.error(obj['id'], 'bad role')
                continue
            try:
                objcon = self._server.get_connection(obj['id'])
            except KeyError:
                errs.error(obj['id'], 'node not connected')
            else:
                returned = objcon.connection.call('execute_command', command)
                errs.success(obj['id'], returned)
                
        return errs.get_dict()

    @listed
    def dbstats(self, conn):
        '''