Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. # Copyright (c) 2011 Openstack, LLC.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15.  
  16. """
  17. The Host Filter classes are a way to ensure that only hosts that are
  18. appropriate are considered when creating a new instance. Hosts that are
  19. either incompatible or insufficient to accept a newly-requested instance
  20. are removed by Host Filter classes from consideration. Those that pass
  21. the filter are then passed on for weighting or other process for ordering.
  22.  
  23. Filters are in the 'filters' directory that is off the 'scheduler'
  24. directory of nova. Additional filters can be created and added to that
  25. directory; be sure to add them to the filters/__init__.py file so that
  26. they are part of the nova.schedulers.filters namespace.
  27. """
  28.  
  29. import types
  30.  
  31. from nova import exception
  32. from nova import flags
  33. import nova.scheduler
  34. from nova import log as logging
  35.  
  36. LOG = logging.getLogger('nova.scheduler.CLOUDBUILDERS')
  37.  
  38. # NOTE(Vek): Even though we don't use filters in here anywhere, we
  39. # depend on default_host_filter being available in FLAGS,
  40. # and that happens only when filters/abstract_filter.py is
  41. # imported.
  42. from nova.scheduler import filters
  43.  
  44.  
  45. FLAGS = flags.FLAGS
  46.  
  47.  
  48. def _get_filters():
  49. # Imported here to avoid circular imports
  50. from nova.scheduler import filters
  51.  
  52. def get_itm(nm):
  53. return getattr(filters, nm)
  54.  
  55. return [get_itm(itm) for itm in dir(filters)
  56. if (type(get_itm(itm)) is types.TypeType)
  57. and issubclass(get_itm(itm), filters.AbstractHostFilter)
  58. and get_itm(itm) is not filters.AbstractHostFilter]
  59.  
  60.  
  61. def choose_host_filter(filter_name=None):
  62. """Since the caller may specify which filter to use we need
  63. to have an authoritative list of what is permissible. This
  64. function checks the filter name against a predefined set
  65. of acceptable filters.
  66. """
  67. if not filter_name:
  68. filter_name = FLAGS.default_host_filter
  69. LOG.debug(_("#1 ---> FILTER ON NOVA.CONF : %s"), (filter_name))
  70. for filter_class in _get_filters():
  71. LOG.debug(_("#2 ---> FILTER BEING READ : %s"), (filter_class.__name__))
  72. if filter_class.__name__ == filter_name:
  73. return filter_class()
  74. raise exception.SchedulerHostFilterNotFound(filter_name=filter_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement