Commit 44ad9a0a authored by Aurélien Dunand's avatar Aurélien Dunand
Browse files

Implement install and uninstall commands

parent dd9f0d90
Loading
Loading
Loading
Loading
+62 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ from cloudcontrol.common.tql.db.tag import StaticTag

MIGRATION_TYPES = {'cold': ColdMigrationJob,
                   'hot': HotMigrationJob,}
RESCUE_SCRIPT = 'rescue'


class CliHandler(RegisteredCCHandler):
@@ -342,6 +341,68 @@ class CliHandler(RegisteredCCHandler):

        return errs.get_dict()

    @listed
    def install(self, query):
        """ Enable install mode on selected virtual machines.

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

        objects = self.client.list(query, show=('r', 'p', 'h', 'n', 'status'), method='install')

        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_install(obj['h'])
                except Exception as err:
                    errs.error(obj['id'], 'Unexpected exception: %s' % str(err))
                else:
                    if obj['status'] == 'stopped':
                        errs.success(obj['id'], 'vm now in install mode')
                    else:
                        errs.success(obj['id'], 'vm will be in install mode after a restart')

        return errs.get_dict()

    @listed
    def uninstall(self, query):
        """ Disable install mode on selected virtual machines.

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

        objects = self.client.list(query, show=('r', 'p', 'h', 'n', 'status'), method='install')

        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_uninstall(obj['h'])
                except Exception as err:
                    errs.error(obj['id'], 'Unexpected exception: %s' % str(err))
                else:
                    if obj['status'] == 'stopped':
                        errs.success(obj['id'], 'vm now in normal mode')
                    else:
                        errs.success(obj['id'], 'vm will be in normal mode after a restart')

        return errs.get_dict()

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