Esempio n. 1
0
    def get_cost_functions(self, topic=None):
        """Returns a list of tuples containing weights and cost functions to
        use for weighing hosts
        """
        if topic is None:
            # Schedulers only support compute right now.
            topic = "compute"
        if topic in self.cost_function_cache:
            return self.cost_function_cache[topic]

        cost_fns = []
        for cost_fn_str in FLAGS.least_cost_functions:
            if '.' in cost_fn_str:
                short_name = cost_fn_str.split('.')[-1]
            else:
                short_name = cost_fn_str
                cost_fn_str = "%s.%s.%s" % (__name__, self.__class__.__name__,
                                            short_name)
            if not (short_name.startswith('%s_' % topic)
                    or short_name.startswith('noop')):
                continue

            try:
                # NOTE: import_class is somewhat misnamed since
                # the weighing function can be any non-class callable
                # (i.e., no 'self')
                cost_fn = importutils.import_class(cost_fn_str)
            except ImportError:
                raise exception.SchedulerCostFunctionNotFound(
                    cost_fn_str=cost_fn_str)

            try:
                flag_name = "%s_weight" % cost_fn.__name__
                weight = getattr(FLAGS, flag_name)
            except AttributeError:
                raise exception.SchedulerWeightFlagNotFound(
                    flag_name=flag_name)
            cost_fns.append((weight, cost_fn))

        self.cost_function_cache[topic] = cost_fns
        return cost_fns
Esempio n. 2
0
def _get_cost_functions():
    """Returns a list of tuples containing weights and cost functions to
    use for weighing hosts
    """
    cost_fns_conf = CONF.least_cost_functions
    if cost_fns_conf is None:
        # The old default.  This will get fixed up below.
        fn_str = 'nova.scheduler.least_cost.compute_fill_first_cost_fn'
        cost_fns_conf = [fn_str]
    cost_fns = []
    for cost_fn_str in cost_fns_conf:
        short_name = cost_fn_str.split('.')[-1]
        if not (short_name.startswith('compute_')
                or short_name.startswith('noop')):
            continue
        # Fix up any old paths to the new paths
        if cost_fn_str.startswith('nova.scheduler.least_cost.'):
            cost_fn_str = ('nova.scheduler.weights.least_cost' +
                           cost_fn_str[25:])
        try:
            # NOTE: import_class is somewhat misnamed since
            # the weighing function can be any non-class callable
            # (i.e., no 'self')
            cost_fn = importutils.import_class(cost_fn_str)
        except ImportError:
            raise exception.SchedulerCostFunctionNotFound(
                cost_fn_str=cost_fn_str)

        try:
            flag_name = "%s_weight" % cost_fn.__name__
            weight = getattr(CONF, flag_name)
        except AttributeError:
            raise exception.SchedulerWeightFlagNotFound(flag_name=flag_name)
        # Set the original default.
        if (flag_name == 'compute_fill_first_cost_fn_weight'
                and weight is None):
            weight = -1.0
        cost_fns.append((weight, cost_fn))
    return cost_fns
Esempio n. 3
0
    def get_cost_fns(self, topic):
        """Returns a list of tuples containing weights and cost functions to
        use for weighing hosts
        """

        if topic in self.cost_fns_cache:
            return self.cost_fns_cache[topic]

        cost_fns = []
        for cost_fn_str in FLAGS.least_cost_scheduler_cost_functions:
            if '.' in cost_fn_str:
                short_name = cost_fn_str.split('.')[-1]
            else:
                short_name = cost_fn_str
                cost_fn_str = "%s.%s.%s" % (__name__, self.__class__.__name__,
                                            short_name)

            if not (short_name.startswith('%s_' % topic)
                    or short_name.startswith('noop')):
                continue

            try:
                # NOTE(sirp): import_class is somewhat misnamed since it can
                # any callable from a module
                cost_fn = utils.import_class(cost_fn_str)
            except exception.ClassNotFound:
                raise exception.SchedulerCostFunctionNotFound(
                    cost_fn_str=cost_fn_str)

            try:
                weight = getattr(FLAGS, "%s_weight" % cost_fn.__name__)
            except AttributeError:
                raise exception.SchedulerWeightFlagNotFound(
                    flag_name=flag_name)

            cost_fns.append((weight, cost_fn))

        self.cost_fns_cache[topic] = cost_fns
        return cost_fns