Skip to content
Snippets Groups Projects
Commit b581e5fb authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

Merge branch 'master' of git:/srv/git/cc-node

parents a3d519a2 bebb9c9a
No related branches found
No related tags found
No related merge requests found
...@@ -176,8 +176,8 @@ class NodeHandler(RpcHandler): ...@@ -176,8 +176,8 @@ class NodeHandler(RpcHandler):
self.hv_handle.stop_vm(vm, stop_mode) self.hv_handle.stop_vm(vm, stop_mode)
except VMError as err: except VMError as err:
logging.warning('Error while stopping %s: %s' % (vm, err)) logging.warning('Error while stopping %s: %s' % (vm, err))
continue else:
logging.info('stop_vm: vm %s stopping' % vm) logging.info('stop_vm: vm %s stopping' % vm)
@pure @pure
def start_vm(self, vm_names=None): def start_vm(self, vm_names=None):
...@@ -189,15 +189,55 @@ class NodeHandler(RpcHandler): ...@@ -189,15 +189,55 @@ class NodeHandler(RpcHandler):
:type vm_names: :class:`list` of strings :type vm_names: :class:`list` of strings
''' '''
if vm_names is None: if vm_names is None:
vm_names = [vm.get_name() for vm in self.hv_handle._vm_list] vm_names = gen_vm_names(self.hv_handle)
logging.debug('start_vm: starting vms %s' % vm_names) logging.debug('start_vm: starting vms %s' % vm_names)
for vm in vm_names: for vm in vm_names:
try: try:
self.hv_handle.start_vm(vm) self.hv_handle.start_vm(vm)
except VMError as err: except VMError as err:
logging.warning('Error while starting %s: %s' % (vm ,err)) logging.warning('Error while starting %s: %s' % (vm ,err))
continue else:
logging.info('start_vm: vm %s starting' % vm) logging.info('start_vm: vm %s starting' % vm)
@pure
def suspend_vm(self, vm_names=None):
'''
Suspends the specifed list of vms
If vm_names is None all vms in hypervisor will be suspended
:param vm_names: the list of vms to suspend
:type vm_names: :class:`list` of strings
'''
if vm_names is None:
vm_names = gen_vm_names(self.hv_handle)
logging.debug('suspend_vm: suspending vms %s' % vm_names)
for vm in vm_names:
try:
self.hv_handle.suspend_vm(vm)
except VMError as err:
logging.info('Error while suspending %s: %s' % (vm, err))
else:
logging.info('suspend_vm: vm %s suspended' % vm)
@pure
def resume_vm(self, vm_names=None):
'''
Resumes the specified list of vms
If vm_names is None all vms in hypervisor will be resumed
:param vm_names: the list of vms to resume
:type vm_names: :class:`str`
'''
if vm_names is None:
vm_names = gen_vm_names(self.hv_handle)
logging.debug('resume_vm: resuming vms %s' % vm_names)
for vm in vm_names:
try:
self.hv_handle.resume_vm(vm)
except VMError as err:
logging.info('Error while resuming %s: %s' % (vm, err))
else:
logging.info('resume_vm: vm %s resumed' % vm)
@pure @pure
def execute_command(self, command): def execute_command(self, command):
...@@ -210,3 +250,12 @@ class NodeHandler(RpcHandler): ...@@ -210,3 +250,12 @@ class NodeHandler(RpcHandler):
''' '''
result = self.hv_handle.local_excecute(command) result = self.hv_handle.local_excecute(command)
return result return result
### Helper Functions
def gen_vm_names(hypervisor):
'''
generates a list of vm names defined in hypervisor
'''
return [vm.get_name() for vm in hypervisor._vm_list]
...@@ -56,14 +56,40 @@ class KvmHypervisor(LibvirtHypervisor): ...@@ -56,14 +56,40 @@ class KvmHypervisor(LibvirtHypervisor):
''' '''
Poweroff the specifed vm with the specified options Poweroff the specifed vm with the specified options
:param name: the name of the vm: :param name: the name of the vm
:type name: :class:`str` :type name: :class:`str`
''' '''
for vm in self._vm_list: for vm in self._vm_list:
if vm.get_name() == name: if vm.get_name() == name:
vm.shutdown() if stop_mode else vm.force_poweroff() vm.shutdown() if stop_mode else vm.force_poweroff()
return return
raise VMError('Virtual Machine %s not found: '% name) raise VMError('Virtual Machine %s not found: ' % name)
def suspend_vm(self, name):
'''
Suspends the specifed vm
:param name: the name of the vm
:type name: :class:`str`
'''
for vm in self._vm_list:
if vm.get_name() == name:
vm.suspend()
return
raise VMError('Virtual machine %s not found: ' % name)
def resume_vm(self, name):
'''
Resumes the specifed vm
:param name: the name of the vm
:type name: :class:`str`
'''
for vm in self._vm_list:
if vm.get_name() == name:
vm.resume()
return
raise VMError('Virtual machine %s not found: ' % name)
def local_excecute(self, command): def local_excecute(self, command):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment