Commit 7216c95f authored by Antoine Millet's avatar Antoine Millet
Browse files

Implemented title command on cli handler

parent 109732ad
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -296,7 +296,36 @@ class CliHandler(RegisteredCCHandler):

        return errs.get_dict()

    @listed
    def title(self, query, new_title):
        """ Edit the title of a VM.

        :param query: the tql query to select objects.
        """

        objects = self.client.list(query, show=('r', 'p', 'h'), method='shell')
        if not objects:
            raise NotImplementedError('No objects matched by query')
        elif len(objects) != 1:
            raise NotImplementedError('Can change title on only one VM at once')
        errs = Reporter()
        for obj in objects:
            if obj['r'] != 'vm':
                errs.error(obj['id'], 'bad role')
                continue
            try:
                hvcon = self.server.get_client(obj['p'])
            except KeyError:
                errs.error(obj['id'], 'hypervisor not connected')
            else:
                try:
                    hvcon.proxy.vm_change_title(obj['h'], new_title)
                except Exception as err:
                    errs.error(obj['id'], str(err))
                else:
                    errs.success(obj['id'], 'title has been edited')

        return errs.get_dict()

    #
    # Account management: