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

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

        project_id = filter_properties['project_id']

        host_racks_map = solver_utils.get_host_racks_map(hosts)

        affinity_racks = set([])
        affinity_hosts = set([])

        # get affinity racks/hosts
        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if project_id in hosts[i].projects:
                affinity_hosts.add(host_name)
                affinity_racks = affinity_racks.union(host_racks)

        # check each hosts for affinity
        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if (not any([rack in affinity_racks for rack in host_racks])) and (
                    host_name not in affinity_hosts):
                extended_cost_matrix[i] = [1 for j
                                            in xrange(num_instances + 1)]
            else:
                LOG.debug(_("%(host)s is in tenant affinity rack."),
                        {'host': host_name})

        return extended_cost_matrix
    def get_constraint_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        constraint_matrix = [[True for j in xrange(num_instances)]
                             for i in xrange(num_hosts)]

        max_racks = CONF.max_racks_per_tenant
        project_id = filter_properties['project_id']

        host_racks_map = solver_utils.get_host_racks_map(hosts)

        project_hosts = set([])
        project_racks = set([])
        other_racks = set([])

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if project_id in hosts[i].projects:
                project_racks = project_racks.union(host_racks)
                project_hosts.add(host_name)
            else:
                other_racks = other_racks.union(host_racks)
        other_racks = other_racks.difference(project_racks)

        additional_racks = []
        if len(project_racks) < max_racks:
            additional_rack_num = max_racks - len(project_racks)
            if additional_rack_num >= len(other_racks):
                additional_racks = list(other_racks)
            else:
                sorted_other_racks = _get_sorted_racks(other_racks, hosts,
                                                       host_racks_map,
                                                       filter_properties)
                additional_racks = sorted_other_racks[0:additional_rack_num]

        acceptable_racks = project_racks.union(additional_racks)
        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if (any([rack not in acceptable_racks for rack in host_racks])
                    and (host_name not in project_hosts)):
                constraint_matrix[i] = [False for j in xrange(num_instances)]

                LOG.debug(
                    _("%(host)s cannot accept requested instances "
                      "according to TenantRackConstraint."),
                    {'host': host_name})
            else:
                LOG.debug(
                    _("%(host)s can accept requested instances "
                      "according to TenantRackConstraint."),
                    {'host': host_name})

        return constraint_matrix
    def get_constraint_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        constraint_matrix = [[True for j in xrange(num_instances)]
                            for i in xrange(num_hosts)]

        max_racks = CONF.max_racks_per_tenant
        project_id = filter_properties['project_id']

        host_racks_map = solver_utils.get_host_racks_map(hosts)

        project_hosts = set([])
        project_racks = set([])
        other_racks = set([])

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if project_id in hosts[i].projects:
                project_racks = project_racks.union(host_racks)
                project_hosts.add(host_name)
            else:
                other_racks = other_racks.union(host_racks)
        other_racks = other_racks.difference(project_racks)

        additional_racks = []
        if len(project_racks) < max_racks:
            additional_rack_num = max_racks - len(project_racks)
            if additional_rack_num >= len(other_racks):
                additional_racks = list(other_racks)
            else:
                sorted_other_racks = _get_sorted_racks(
                        other_racks, hosts, host_racks_map, filter_properties)
                additional_racks = sorted_other_racks[0:additional_rack_num]

        acceptable_racks = project_racks.union(additional_racks)
        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if (any([rack not in acceptable_racks for rack in host_racks])
                    and (host_name not in project_hosts)):
                constraint_matrix[i] = [False for j in xrange(num_instances)]

                LOG.debug(_("%(host)s cannot accept requested instances "
                        "according to TenantRackConstraint."),
                        {'host': host_name})
            else:
                LOG.debug(_("%(host)s can accept requested instances "
                        "according to TenantRackConstraint."),
                        {'host': host_name})

        return constraint_matrix
Exemplo n.º 4
0
    def test_get_host_racks_map_no_aggregate_key(self, getconfig_mock):
        host1 = fakes.FakeSolverSchedulerHostState('host1', 'node1', {})
        host2 = fakes.FakeSolverSchedulerHostState('host2', 'node2', {})
        host3 = fakes.FakeSolverSchedulerHostState('host3', 'node3',
                {'aggregates': self.fake_aggregates[2:3]})
        host4 = fakes.FakeSolverSchedulerHostState('host4', 'node4', {})
        hosts = [host1, host2, host3, host4]

        expected_result = {'host1': set('rack1'), 'host2': set('rack1')}
        getconfig_mock.return_value = expected_result

        result = utils.get_host_racks_map(hosts)

        self.assertEqual(expected_result, result)
Exemplo n.º 5
0
    def test_get_host_racks_map_from_aggregate(self):
        host1 = fakes.FakeSolverSchedulerHostState('host1', 'node1',
                {'aggregates': self.fake_aggregates[0:1]})
        host2 = fakes.FakeSolverSchedulerHostState('host2', 'node2',
                {'aggregates': self.fake_aggregates[0:2]})
        host3 = fakes.FakeSolverSchedulerHostState('host3', 'node3',
                {'aggregates': self.fake_aggregates[2:3]})
        host4 = fakes.FakeSolverSchedulerHostState('host4', 'node4',
                {'aggregates': []})
        hosts = [host1, host2, host3, host4]

        result = utils.get_host_racks_map(hosts)
        expected_result = {
            'host1': set(['rack1']),
            'host2': set(['rack1', 'rack2'])
        }

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

        constraint_matrix = [[True for j in xrange(num_instances)]
                             for i in xrange(num_hosts)]

        scheduler_hints = filter_properties.get('scheduler_hints') or {}
        affinity_uuids = scheduler_hints.get('same_rack', [])

        if not affinity_uuids:
            return constraint_matrix

        if isinstance(affinity_uuids, six.string_types):
            affinity_uuids = [affinity_uuids]

        host_racks_map = solver_utils.get_host_racks_map(hosts)

        affinity_racks = set([])
        affinity_hosts = set([])

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if solver_utils.instance_uuids_overlap(hosts[i], affinity_uuids):
                affinity_racks = affinity_racks.union(host_racks)
                affinity_hosts.add(host_name)

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if host_name in affinity_hosts:
                LOG.debug(_("%(host)s passed same-rack check."),
                          {'host': host_name})
                continue
            elif (len(host_racks) == 0) or any(
                [rack not in affinity_racks for rack in host_racks]):
                constraint_matrix[i] = [False for j in xrange(num_instances)]
            else:
                LOG.debug(_("%(host)s passed same-rack check."),
                          {'host': host_name})

        return constraint_matrix
    def get_constraint_matrix(self, hosts, filter_properties):
        num_hosts = len(hosts)
        num_instances = filter_properties.get('num_instances')

        constraint_matrix = [[True for j in xrange(num_instances)]
                            for i in xrange(num_hosts)]

        scheduler_hints = filter_properties.get('scheduler_hints') or {}
        affinity_uuids = scheduler_hints.get('same_rack', [])

        if not affinity_uuids:
            return constraint_matrix

        if isinstance(affinity_uuids, six.string_types):
            affinity_uuids = [affinity_uuids]

        host_racks_map = solver_utils.get_host_racks_map(hosts)

        affinity_racks = set([])
        affinity_hosts = set([])

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if solver_utils.instance_uuids_overlap(hosts[i], affinity_uuids):
                affinity_racks = affinity_racks.union(host_racks)
                affinity_hosts.add(host_name)

        for i in xrange(num_hosts):
            host_name = hosts[i].host
            host_racks = host_racks_map.get(host_name, set([]))
            if host_name in affinity_hosts:
                LOG.debug(_("%(host)s passed same-rack check."),
                        {'host': host_name})
                continue
            elif (len(host_racks) == 0) or any([rack not in affinity_racks
                                                for rack in host_racks]):
                constraint_matrix[i] = [False for j in xrange(num_instances)]
            else:
                LOG.debug(_("%(host)s passed same-rack check."),
                        {'host': host_name})

        return constraint_matrix