示例#1
0
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        instance_type = filter_properties.get('instance_type') or {}
        requested_ram = instance_type.get('memory_mb', 0)
        if 'memory_mb' not in instance_type:
            LOG.warn(
                _LW("No information about requested instances\' RAM size "
                    "was found, default value (0) is used."))

        extended_cost_matrix = [[0 for j in xrange(num_instances + 1)]
                                for i in xrange(num_hosts)]

        if requested_ram == 0:
            extended_cost_matrix = [[(-hosts[i].free_ram_mb)
                                     for j in xrange(num_instances + 1)]
                                    for i in xrange(num_hosts)]
        else:
            # we use int approximation here to avoid scaling problems after
            # normalization, in the case that the free ram in all hosts are
            # of very small values
            extended_cost_matrix = [[
                -int(hosts[i].free_ram_mb / requested_ram) + j
                for j in xrange(num_instances + 1)
            ] for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
            extended_cost_matrix)
        return extended_cost_matrix
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        instance_type = filter_properties.get('instance_type') or {}
        requested_ram = instance_type.get('memory_mb', 0)
        if 'memory_mb' not in instance_type:
            LOG.warn(_LW("No information about requested instances\' RAM size "
                    "was found, default value (0) is used."))

        extended_cost_matrix = [[0 for j in xrange(num_instances + 1)]
                                for i in xrange(num_hosts)]

        if requested_ram == 0:
            extended_cost_matrix = [
                    [(-hosts[i].free_ram_mb)
                    for j in xrange(num_instances + 1)]
                    for i in xrange(num_hosts)]
        else:
            # we use int approximation here to avoid scaling problems after
            # normalization, in the case that the free ram in all hosts are
            # of very small values
            extended_cost_matrix = [
                    [-int(hosts[i].free_ram_mb / requested_ram) + j
                    for j in xrange(num_instances + 1)]
                    for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
                                                        extended_cost_matrix)
        return extended_cost_matrix
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        extended_cost_matrix = [[
            hosts[i].num_io_ops + j for j in xrange(num_instances + 1)
        ] for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
            extended_cost_matrix)
        return extended_cost_matrix
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        extended_cost_matrix = [
                [hosts[i].num_io_ops + j for j in xrange(num_instances + 1)]
                for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
                                                        extended_cost_matrix)
        return extended_cost_matrix
示例#5
0
    def test_normalize_cost_matrix_first_column_all_zero(self):
        test_matrix = [[0, 1, 2, 3], [0, -1, -2, -3], [0, 0.2, 0.4, 0.6]]

        expected_result = [[0, 1, 2, 3], [0, -1, -2, -3], [0, 0.2, 0.4, 0.6]]

        result = utils.normalize_cost_matrix(test_matrix)

        round_values = lambda x: [round(v, 4) for v in x]
        expected_result = map(round_values, expected_result)
        result = map(round_values, result)

        self.assertEqual(expected_result, result)
示例#6
0
    def test_normalize_cost_matrix(self):
        test_matrix = [[1, 2, 3, 4], [5, 7, 9, 10], [-2, -1, 0, 2]]

        expected_result = [[0.2, 0.4, 0.6, 0.8], [1.0, 1.4, 1.8, 2.0],
                           [-0.4, -0.2, 0.0, 0.4]]

        result = utils.normalize_cost_matrix(test_matrix)

        round_values = lambda x: [round(v, 4) for v in x]
        expected_result = map(round_values, expected_result)
        result = map(round_values, result)

        self.assertEqual(expected_result, result)
    def test_normalize_cost_matrix_first_column_all_zero(self):
        test_matrix = [
                [0, 1, 2, 3],
                [0, -1, -2, -3],
                [0, 0.2, 0.4, 0.6]]

        expected_result = [
                [0, 1, 2, 3],
                [0, -1, -2, -3],
                [0, 0.2, 0.4, 0.6]]

        result = utils.normalize_cost_matrix(test_matrix)

        round_values = lambda x: [round(v, 4) for v in x]
        expected_result = map(round_values, expected_result)
        result = map(round_values, result)

        self.assertEqual(expected_result, result)
    def test_normalize_cost_matrix(self):
        test_matrix = [
                [1, 2, 3, 4],
                [5, 7, 9, 10],
                [-2, -1, 0, 2]]

        expected_result = [
                [0.2, 0.4, 0.6, 0.8],
                [1.0, 1.4, 1.8, 2.0],
                [-0.4, -0.2, 0.0, 0.4]]

        result = utils.normalize_cost_matrix(test_matrix)

        round_values = lambda x: [round(v, 4) for v in x]
        expected_result = map(round_values, expected_result)
        result = map(round_values, result)

        self.assertEqual(expected_result, result)
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        instance_type = filter_properties.get('instance_type') or {}
        requested_vcpus = instance_type.get('vcpus', 0)
        if requested_vcpus <= 0:
            LOG.warn(
                _LW("Requested instances\' vCPU number is 0 or invalid, "
                    "default value (0) is used."))

        remaining_vcpus_list = []
        for i in xrange(num_hosts):
            vcpus_total = hosts[i].vcpus_total
            vcpus_used = hosts[i].vcpus_used
            if not vcpus_total:
                LOG.warn(
                    _LW("vCPUs of %(host)s not set; assuming CPU "
                        "collection broken."), {'host': hosts[i]})
                vcpus_total = 0
            remaining_vcpus = vcpus_total - vcpus_used
            remaining_vcpus_list.append(remaining_vcpus)

        extended_cost_matrix = [[0 for j in xrange(num_instances + 1)]
                                for i in xrange(num_hosts)]

        if requested_vcpus == 0:
            extended_cost_matrix = [[(-remaining_vcpus_list[i])
                                     for j in xrange(num_instances + 1)]
                                    for i in xrange(num_hosts)]
        else:
            # we use int approximation here to avoid scaling problems after
            # normalization, in the case that the free vcpus in all hosts are
            # of very small values
            extended_cost_matrix = [[
                -int(remaining_vcpus_list[i] / requested_vcpus) + j
                for j in xrange(num_instances + 1)
            ] for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
            extended_cost_matrix)
        return extended_cost_matrix
示例#10
0
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        instance_type = filter_properties.get('instance_type') or {}
        requested_vcpus = instance_type.get('vcpus', 0)
        if requested_vcpus <= 0:
            LOG.warn(_LW("Requested instances\' vCPU number is 0 or invalid, "
                    "default value (0) is used."))

        remaining_vcpus_list = []
        for i in xrange(num_hosts):
            vcpus_total = hosts[i].vcpus_total
            vcpus_used = hosts[i].vcpus_used
            if not vcpus_total:
                LOG.warn(_LW("vCPUs of %(host)s not set; assuming CPU "
                            "collection broken."), {'host': hosts[i]})
                vcpus_total = 0
            remaining_vcpus = vcpus_total - vcpus_used
            remaining_vcpus_list.append(remaining_vcpus)

        extended_cost_matrix = [[0 for j in xrange(num_instances + 1)]
                                for i in xrange(num_hosts)]

        if requested_vcpus == 0:
            extended_cost_matrix = [
                    [(-remaining_vcpus_list[i])
                    for j in xrange(num_instances + 1)]
                    for i in xrange(num_hosts)]
        else:
            # we use int approximation here to avoid scaling problems after
            # normalization, in the case that the free vcpus in all hosts are
            # of very small values
            extended_cost_matrix = [
                    [-int(remaining_vcpus_list[i] / requested_vcpus) + j
                    for j in xrange(num_instances + 1)]
                    for i in xrange(num_hosts)]
        extended_cost_matrix = utils.normalize_cost_matrix(
                                                        extended_cost_matrix)
        return extended_cost_matrix
    def get_extended_cost_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        host_weights = []
        numeric_values = []
        for host in hosts:
            metric_sum = 0.0
            for (name, ratio) in self.setting:
                metric = host.metrics.get(name, None)
                if metric:
                    metric_sum += metric.value * ratio
                else:
                    metric_sum = None
                    break
            host_weights.append(metric_sum)
            if metric_sum:
                numeric_values.append(metric_sum)
        if numeric_values:
            minval = min(numeric_values)
            maxval = max(numeric_values)
            weight_of_unavailable = (
                minval + (maxval - minval) *
                CONF.metrics.weight_multiplier_of_unavailable)
            for i in range(num_hosts):
                if host_weights[i] is None:
                    host_weights[i] = weight_of_unavailable
        else:
            host_weights = [0 for i in xrange(num_hosts)]

        extended_cost_matrix = [[(-host_weights[i])
                                 for j in xrange(num_instances + 1)]
                                for i in xrange(num_hosts)]
        extended_cost_matrix = cost_utils.normalize_cost_matrix(
            extended_cost_matrix)
        return extended_cost_matrix
示例#12
0
 def test_normalize_cost_matrix_empty_input(self):
     test_matrix = []
     expected_result = []
     result = utils.normalize_cost_matrix(test_matrix)
     self.assertEqual(expected_result, result)
 def test_normalize_cost_matrix_empty_input(self):
     test_matrix = []
     expected_result = []
     result = utils.normalize_cost_matrix(test_matrix)
     self.assertEqual(expected_result, result)