Commit a393864c authored by Antoine Millet's avatar Antoine Millet
Browse files

Implemented start, stop, suspend and resume client handler methods using _vm_action private method.

parent 1bad4c94
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -115,6 +115,34 @@ class ClientHandler(OnlineCCHandler):
        logging.debug('Executed list function with query %s' % query)
        return self._list(query)

    def _vm_action(self, query, method, *args, **kwargs):
        query += '&vm'
        vms = self._list(query)
        hypervisors = list(self._server.iterrole('hypervisor'))
        for hv in hypervisors:
            vm_to_start = [vm['vm'] for vm in vms if vm['hv'] == hv.login]
            if vm_to_start:
                hv.connection.call(method, vm_to_start, *args, **kwargs)

    @pure
    @listed
    def start(self, query):
        self._vm_action(query, 'start_vm')

    @pure
    @listed
    def stop(self, query, force=False):
        self._vm_action(query, 'stop_vm', force)

    @pure
    @listed
    def suspend(self, query):
        self._vm_action(query, 'suspend_vm')

    @pure
    @listed
    def resume(self, query):
        self._vm_action(query, 'resume_vm')
class AuthenticationError(Exception):
    pass