Exemple #1
0
 def indicate(self, context):
     cpu_threshold = CONF.loadbalancer_standart_deviation.threshold_cpu
     mem_threshold = CONF.loadbalancer_standart_deviation.threshold_memory
     compute_nodes = db.get_compute_node_stats(context)
     instances = []
     # TODO: Make only one query that returns all instances placed on active
     # hosts.
     for node in compute_nodes:
         node_instances = db.get_instances_stat(context,
                                                node['hypervisor_hostname'])
         instances.extend(node_instances)
     compute_stats = utils.fill_compute_stats(instances, compute_nodes)
     host_loads = utils.calculate_host_loads(compute_nodes, compute_stats)
     LOG.debug(_(host_loads))
     ram_sd = utils.calculate_sd(host_loads, 'mem')
     cpu_sd = utils.calculate_sd(host_loads, 'cpu')
     if cpu_sd > cpu_threshold or ram_sd > mem_threshold:
         extra_info = {'cpu_overload': False}
         if cpu_sd > cpu_threshold:
             overloaded_host = sorted(host_loads,
                                      key=lambda x: host_loads[x]['cpu'],
                                      reverse=True)[0]
             extra_info['cpu_overload'] = True
         else:
             overloaded_host = sorted(host_loads,
                                      key=lambda x: host_loads[x]['mem'],
                                      reverse=True)[0]
         host = filter(
             lambda x: x['hypervisor_hostname'] == overloaded_host,
             compute_nodes)[0]
         LOG.debug(_(host))
         return host, compute_nodes, extra_info
     return [], [], {}
 def indicate(self, context):
     cpu_threshold = CONF.loadbalancer_standart_deviation.threshold_cpu
     mem_threshold = CONF.loadbalancer_standart_deviation.threshold_memory
     compute_nodes = db.get_compute_node_stats(context)
     instances = []
     # TODO: Make only one query that returns all instances placed on active
     # hosts.
     for node in compute_nodes:
         node_instances = db.get_instances_stat(
             context,
             node['hypervisor_hostname'])
         instances.extend(node_instances)
     compute_stats = utils.fill_compute_stats(instances, compute_nodes)
     host_loads = utils.calculate_host_loads(compute_nodes, compute_stats)
     LOG.debug(_(host_loads))
     ram_sd = utils.calculate_sd(host_loads, 'mem')
     cpu_sd = utils.calculate_sd(host_loads, 'cpu')
     if cpu_sd > cpu_threshold or ram_sd > mem_threshold:
         extra_info = {'cpu_overload': False}
         if cpu_sd > cpu_threshold:
             overloaded_host = sorted(host_loads,
                                      key=lambda x: host_loads[x]['cpu'],
                                      reverse=True)[0]
             extra_info['cpu_overload'] = True
         else:
             overloaded_host = sorted(host_loads,
                                      key=lambda x: host_loads[x]['mem'],
                                      reverse=True)[0]
         host = filter(
             lambda x:
             x['hypervisor_hostname'] == overloaded_host, compute_nodes)[0]
         LOG.debug(_(host))
         return host, compute_nodes, extra_info
     return [], [], {}
Exemple #3
0
 def min_sd(self, context, **kwargs):
     compute_nodes = kwargs.get('nodes')
     instances = []
     for node in compute_nodes:
         node_instances = db.get_instances_stat(context,
                                                node['hypervisor_hostname'])
         instances.extend(node_instances)
     host_loads = lb_utils.fill_compute_stats(instances, compute_nodes)
     LOG.debug(_(host_loads))
     vm_host_map = []
     for instance in instances:
         for node in compute_nodes:
             h_hostname = node['hypervisor_hostname']
             # Source host shouldn't be use.
             if instance.instance['host'] != h_hostname:
                 sd = self._simulate_migration(instance, node, host_loads,
                                               compute_nodes)
                 vm_host_map.append({
                     'host': h_hostname,
                     'vm': instance['instance_uuid'],
                     'sd': sd
                 })
     vm_host_map = sorted(vm_host_map, key=lambda x: x['sd']['total_sd'])
     LOG.debug(_(vm_host_map))
     for vm_host in vm_host_map:
         instance = filter(lambda x: x['instance_uuid'] == vm_host['vm'],
                           instances)[0]
         instance_resources = lb_utils.get_instance_resources(instance)
         if instance_resources:
             filter_instance = {
                 'uuid': instance['instance_uuid'],
                 'resources': instance_resources
             }
             filtered = self.filter_hosts(context,
                                          filter_instance,
                                          compute_nodes,
                                          host=vm_host['host'])
             if not filtered[0]:
                 continue
             self.migrate(context, instance['instance_uuid'],
                          vm_host['host'])
             return
 def min_sd(self, context, **kwargs):
     compute_nodes = kwargs.get('nodes')
     instances = []
     for node in compute_nodes:
         node_instances = db.get_instances_stat(
             context,
             node['hypervisor_hostname'])
         instances.extend(node_instances)
     host_loads = lb_utils.fill_compute_stats(instances, compute_nodes)
     LOG.debug(_(host_loads))
     vm_host_map = []
     for instance in instances:
         for node in compute_nodes:
             h_hostname = node['hypervisor_hostname']
             # Source host shouldn't be use.
             if instance.instance['host'] != h_hostname:
                 sd = self._simulate_migration(instance, node, host_loads,
                                               compute_nodes)
                 vm_host_map.append({'host': h_hostname,
                                     'vm': instance['instance_uuid'],
                                     'sd': sd})
     vm_host_map = sorted(vm_host_map, key=lambda x: x['sd']['total_sd'])
     LOG.debug(_(vm_host_map))
     for vm_host in vm_host_map:
         instance = filter(lambda x: x['instance_uuid'] == vm_host['vm'],
                           instances)[0]
         instance_resources = lb_utils.get_instance_resources(instance)
         if instance_resources:
             filter_instance = {'uuid': instance['instance_uuid'],
                                'resources': instance_resources}
             filtered = self.filter_hosts(context, filter_instance,
                                          compute_nodes,
                                          host=vm_host['host'])
             if not filtered[0]:
                 continue
             self.migrate(context, instance['instance_uuid'],
                          vm_host['host'])
             return