Loading ccnode/ccnodehandlers.py +54 −5 Original line number Diff line number Diff line Loading @@ -176,7 +176,7 @@ class NodeHandler(RpcHandler): self.hv_handle.stop_vm(vm, stop_mode) except VMError as err: logging.warning('Error while stopping %s: %s' % (vm, err)) continue else: logging.info('stop_vm: vm %s stopping' % vm) @pure Loading @@ -189,16 +189,56 @@ class NodeHandler(RpcHandler): :type vm_names: :class:`list` of strings ''' 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) for vm in vm_names: try: self.hv_handle.start_vm(vm) except VMError as err: logging.warning('Error while starting %s: %s' % (vm ,err)) continue else: 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 def execute_command(self, command): ''' Loading @@ -210,3 +250,12 @@ class NodeHandler(RpcHandler): ''' result = self.hv_handle.local_excecute(command) 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] ccnode/kvm.py +28 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class KvmHypervisor(LibvirtHypervisor): ''' 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` ''' for vm in self._vm_list: Loading @@ -65,6 +65,32 @@ class KvmHypervisor(LibvirtHypervisor): return 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): ''' Loading Loading
ccnode/ccnodehandlers.py +54 −5 Original line number Diff line number Diff line Loading @@ -176,7 +176,7 @@ class NodeHandler(RpcHandler): self.hv_handle.stop_vm(vm, stop_mode) except VMError as err: logging.warning('Error while stopping %s: %s' % (vm, err)) continue else: logging.info('stop_vm: vm %s stopping' % vm) @pure Loading @@ -189,16 +189,56 @@ class NodeHandler(RpcHandler): :type vm_names: :class:`list` of strings ''' 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) for vm in vm_names: try: self.hv_handle.start_vm(vm) except VMError as err: logging.warning('Error while starting %s: %s' % (vm ,err)) continue else: 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 def execute_command(self, command): ''' Loading @@ -210,3 +250,12 @@ class NodeHandler(RpcHandler): ''' result = self.hv_handle.local_excecute(command) 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]
ccnode/kvm.py +28 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class KvmHypervisor(LibvirtHypervisor): ''' 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` ''' for vm in self._vm_list: Loading @@ -65,6 +65,32 @@ class KvmHypervisor(LibvirtHypervisor): return 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): ''' Loading