예제 #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 [], [], {}
예제 #3
0
 def _simulate_migration(self, instance, node, host_loads, compute_nodes):
     source_host = instance.instance['host']
     target_host = node['hypervisor_hostname']
     vm_ram = instance['mem']
     vm_cpu = lb_utils.calculate_cpu(instance, compute_nodes)
     _host_loads = deepcopy(host_loads)
     LOG.debug(_(_host_loads))
     _host_loads[source_host]['mem'] -= vm_ram
     _host_loads[source_host]['cpu'] -= vm_cpu
     _host_loads[target_host]['mem'] += vm_ram
     _host_loads[target_host]['cpu'] += vm_cpu
     _host_loads = lb_utils.calculate_host_loads(compute_nodes, _host_loads)
     ram_sd = lb_utils.calculate_sd(_host_loads, 'mem')
     cpu_sd = lb_utils.calculate_sd(_host_loads, 'cpu')
     return {'cpu_sd': cpu_sd*self.cpu_weight,
             'ram_sd': ram_sd*self.memory_weight,
             'total_sd': cpu_sd*self.cpu_weight + ram_sd*self.memory_weight}
예제 #4
0
 def _simulate_migration(self, instance, node, host_loads, compute_nodes):
     source_host = instance.instance['host']
     target_host = node['hypervisor_hostname']
     vm_ram = instance['mem']
     vm_cpu = lb_utils.calculate_cpu(instance, compute_nodes)
     _host_loads = deepcopy(host_loads)
     LOG.debug(_(_host_loads))
     _host_loads[source_host]['mem'] -= vm_ram
     _host_loads[source_host]['cpu'] -= vm_cpu
     _host_loads[target_host]['mem'] += vm_ram
     _host_loads[target_host]['cpu'] += vm_cpu
     _host_loads = lb_utils.calculate_host_loads(compute_nodes, _host_loads)
     ram_sd = lb_utils.calculate_sd(_host_loads, 'mem')
     cpu_sd = lb_utils.calculate_sd(_host_loads, 'cpu')
     return {
         'cpu_sd': cpu_sd * self.cpu_weight,
         'ram_sd': ram_sd * self.memory_weight,
         'total_sd': cpu_sd * self.cpu_weight + ram_sd * self.memory_weight
     }