def _choose_host_to_migrate(self, context, weighted_instances, nodes): for c in weighted_instances: filtered, filter_properties = self.filter_hosts(context, c, nodes) if filtered: chosen_instance = c break if not filtered: return None, None nodes = filter_properties['nodes'] # 'memory_total' field shouldn't be normalized. for n in nodes: del n['memory_total'] filtered_nodes = [ n for n in nodes for host in filtered if n['host'] == host.hypervisor_hostname] normalized_hosts = lb_utils.normalize_params(filtered_nodes, 'host') weighted_hosts = self._weight_hosts(normalized_hosts) return weighted_hosts[0], chosen_instance
def _choose_host_to_migrate(self, context, weighted_instances, nodes): for c in weighted_instances: filtered, filter_properties = self.filter_hosts(context, c, nodes) if filtered: chosen_instance = c break if not filtered: return None, None nodes = filter_properties['nodes'] # 'memory_total' field shouldn't be normalized. for n in nodes: del n['memory_total'] filtered_nodes = [ n for n in nodes for host in filtered if n['host'] == host.hypervisor_hostname ] normalized_hosts = lb_utils.normalize_params(filtered_nodes, 'host') weighted_hosts = self._weight_hosts(normalized_hosts) return weighted_hosts[0], chosen_instance
def _choose_instance_to_migrate(self, instances, extra_info=None): instances_params = [] for i in instances: instance_resources = lb_utils.get_instance_resources(i) if instance_resources: instances_params.append(instance_resources) LOG.debug(_(instances_params)) normalized_instances = lb_utils.normalize_params(instances_params) LOG.info(_(normalized_instances)) if extra_info.get('cpu_overload'): normalized_instances = filter(lambda x: x['memory'] == 0, normalized_instances) extra_info['k_cpu'] = -1 weighted_instances = self._weight_instances(normalized_instances, extra_info) LOG.info(_(weighted_instances)) for chosen_instance in weighted_instances: chosen_instance['resources'] = filter( lambda x: x['uuid'] == chosen_instance['uuid'], instances_params)[0] yield chosen_instance