Ejemplo n.º 1
0
    def _choose_host_filters(self, filter_cls_names):
        """Since the caller may specify which filters to use we need
        to have an authoritative list of what is permissible. This
        function checks the filter names against a predefined set
        of acceptable filters.
        """
        if filter_cls_names is None:
            filter_cls_names = CONF.scheduler_default_filters
        if not isinstance(filter_cls_names, (list, tuple)):
            filter_cls_names = [filter_cls_names]

        good_filters = []
        bad_filters = []
        for filter_name in filter_cls_names:
            if filter_name not in self.filter_obj_map:
                if filter_name not in self.filter_cls_map:
                    bad_filters.append(filter_name)
                    continue
                filter_cls = self.filter_cls_map[filter_name]
                self.filter_obj_map[filter_name] = filter_cls()
            good_filters.append(self.filter_obj_map[filter_name])
        if bad_filters:
            msg = ", ".join(bad_filters)
            raise exception.SchedulerHostFilterNotFound(filter_name=msg)
        return good_filters
Ejemplo n.º 2
0
 def _choose_host_filters(self, filter_cls_names):
     """Since the caller may specify which filters to use we need
     to have an authoritative list of what is permissible. This
     function checks the filter names against a predefined set
     of acceptable filters.
     """
     if filter_cls_names is None:
         filter_cls_names = CONF.scheduler_default_filters
     if not isinstance(filter_cls_names, (list, tuple)):
         filter_cls_names = [filter_cls_names]
     good_filters = []
     bad_filters = []
     for filter_name in filter_cls_names:
         found_class = False
         for cls in self.filter_classes:
             if cls.__name__ == filter_name:
                 good_filters.append(cls)
                 found_class = True
                 break
         if not found_class:
             bad_filters.append(filter_name)
     if bad_filters:
         msg = ", ".join(bad_filters)
         raise exception.SchedulerHostFilterNotFound(filter_name=msg)
     return good_filters
Ejemplo n.º 3
0
def choose_host_filter(filter_name=None):
    """Since the caller may specify which filter to use we need
    to have an authoritative list of what is permissible. This
    function checks the filter name against a predefined set
    of acceptable filters.
    """
    if not filter_name:
        filter_name = FLAGS.default_host_filter
    for filter_class in _get_filters():
        if filter_class.__name__ == filter_name:
            return filter_class()
    raise exception.SchedulerHostFilterNotFound(filter_name=filter_name)