def test_kvm_hwmodel_to_cpumodel(self): models = [ cpu_model for cpu_models in KVM_HWMODEL_TO_CPUMODEL.values() for cpu_model in cpu_models] for model in self.hardware_models: self.assertIn( model, models, msg='Missing hardware_model in KVM_HWMODEL_TO_CPUMODEL')
def _set_cpu_model(hypervisor, vm, tree): """ Selects CPU model based on hardware model. """ hw_model = hypervisor.dataset_obj['hardware_model'] for arch, models in KVM_HWMODEL_TO_CPUMODEL.items(): if hw_model in models: cpu = _find_or_create(tree, 'cpu') cpu.attrib.update({ 'match': 'exact', 'mode': 'custom', }) model = _find_or_create(cpu, 'model') model.attrib.update({ 'fallback': 'allow', }) model.text = arch log.info('KVM: CPU model set to "%s"' % arch) return raise HypervisorError( 'No CPU configuration for hardware model "{}"'.format(hw_model))
def check_vm(self, vm, offline): """Check whether a VM can run on this hypervisor""" # Cheap checks should always be executed first to save time # and fail early. Same goes for checks that are more likely to fail. # Immediately check whether HV is even supported. if not offline: # Compatbile OS? os_pair = (vm.hypervisor.dataset_obj['os'], self.dataset_obj['os']) if os_pair not in MIGRATE_CONFIG: raise HypervisorError( '{} to {} migration is not supported online.'.format( *os_pair)) # Compatible CPU model? hw_pair = ( vm.hypervisor.dataset_obj['hardware_model'], self.dataset_obj['hardware_model'], ) cpu_pair = [ arch for arch, models in KVM_HWMODEL_TO_CPUMODEL.items() for model in hw_pair if model in models ] if cpu_pair[0] != cpu_pair[1]: raise HypervisorError( '{} to {} migration is not supported online.'.format( *hw_pair)) # HV in supported state? if self.dataset_obj['state'] not in ['online', 'online_reserved']: raise InvalidStateError( 'Hypervisor "{}" is not in online state ({}).'.format( self.fqdn, self.dataset_obj['state'])) # Enough CPUs? if vm.dataset_obj['num_cpu'] > self.dataset_obj['num_cpu']: raise HypervisorError( 'Not enough CPUs. Destination Hypervisor has {0}, ' 'but VM requires {1}.'.format(self.dataset_obj['num_cpu'], vm.dataset_obj['num_cpu'])) # Proper VLAN? if not self.get_vlan_network(vm.dataset_obj['intern_ip']): raise HypervisorError( 'Hypervisor "{}" does not support route_network "{}".'.format( self.fqdn, vm.route_network)) # Those checks below all require libvirt connection, # so execute them last to avoid unnecessary overhead if possible. # Enough memory? free_mib = self.free_vm_memory() if vm.dataset_obj['memory'] > free_mib: raise HypervisorError( 'Not enough memory. ' 'Destination Hypervisor has {:.2f} MiB but VM requires {} MiB ' .format(free_mib, vm.dataset_obj['memory'])) # Enough disk? free_disk_space = self.get_free_disk_size_gib() vm_disk_size = float(vm.dataset_obj['disk_size_gib']) if vm_disk_size > free_disk_space: raise HypervisorError( 'Not enough free space in VG {} to build VM while keeping' ' {} GiB reserved'.format( VG_NAME, RESERVED_DISK[self.get_storage_type()])) # VM already defined? Least likely, if at all. if self.vm_defined(vm): raise HypervisorError('VM "{}" is already defined on "{}".'.format( vm.fqdn, self.fqdn))
def check_vm(self, vm, offline): """Check whether a VM can run on this hypervisor""" if self.dataset_obj['state'] not in ['online', 'online_reserved']: raise InvalidStateError( 'Hypervisor "{}" is not in online state ({}).'.format( self.fqdn, self.dataset_obj['state'])) if self.vm_defined(vm): raise HypervisorError('VM "{}" is already defined on "{}".'.format( vm.fqdn, self.fqdn)) # Enough CPUs? if vm.dataset_obj['num_cpu'] > self.dataset_obj['num_cpu']: raise HypervisorError( 'Not enough CPUs. Destination Hypervisor has {0}, ' 'but VM requires {1}.'.format(self.dataset_obj['num_cpu'], vm.dataset_obj['num_cpu'])) # Enough memory? free_mib = self.free_vm_memory() if vm.dataset_obj['memory'] > free_mib: raise HypervisorError( 'Not enough memory. ' 'Destination Hypervisor has {:.2f} MiB but VM requires {} MiB ' .format(free_mib, vm.dataset_obj['memory'])) if not offline: # Compatbile OS? os_pair = (vm.hypervisor.dataset_obj['os'], self.dataset_obj['os']) if os_pair not in MIGRATE_CONFIG: raise HypervisorError( '{} to {} migration is not supported online.'.format( *os_pair)) # Compatible CPU model? hw_pair = ( vm.hypervisor.dataset_obj['hardware_model'], self.dataset_obj['hardware_model'], ) cpu_pair = [ arch for arch, models in KVM_HWMODEL_TO_CPUMODEL.items() for model in hw_pair if model in models ] if cpu_pair[0] != cpu_pair[1]: raise HypervisorError( '{} to {} migration is not supported online.'.format( *hw_pair)) # Enough disk? free_disk_space = self.get_free_disk_size_gib() vm_disk_size = float(vm.dataset_obj['disk_size_gib']) if vm_disk_size > free_disk_space: raise HypervisorError( 'Not enough free space in VG {} to build VM while keeping' ' {} GiB reserved'.format( VG_NAME, RESERVED_DISK[self.get_storage_type()])) # Proper VLAN? if not self.get_vlan_network(vm.dataset_obj['intern_ip']): raise HypervisorError( 'Hypervisor "{}" does not support route_network "{}".'.format( self.fqdn, vm.dataset_obj['route_network']))