OpenStack Compute (Nova)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ram.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) 2011 OpenStack Foundation
  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. RAM Weigher. Weigh hosts by their RAM usage.
  17. The default is to spread instances across all hosts evenly. If you prefer
  18. stacking, you can set the 'ram_weight_multiplier' option (by configuration
  19. or aggregate metadata) to a negative number and the weighing has the opposite
  20. effect of the default.
  21. """
  22. import nova.conf
  23. from nova.scheduler import utils
  24. from nova.scheduler import weights
  25. CONF = nova.conf.CONF
  26. class RAMWeigher(weights.BaseHostWeigher):
  27. minval = 0
  28. def weight_multiplier(self, host_state):
  29. """Override the weight multiplier."""
  30. return utils.get_weight_multiplier(
  31. host_state, 'ram_weight_multiplier',
  32. CONF.filter_scheduler.ram_weight_multiplier)
  33. def _weigh_object(self, host_state, weight_properties):
  34. """Higher weights win. We want spreading to be the default."""
  35. return host_state.free_ram_mb