Commit a393864c authored by Antoine Millet's avatar Antoine Millet

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

parent 1bad4c94
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment