Created
April 30, 2018 16:29
-
-
Save mgagne/65f033cbc5fdd4c8d1f45e90c943a5f4 to your computer and use it in GitHub Desktop.
RAM weigher for Nova - Mitaka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# All Rights Reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); you may | |
# not use this file except in compliance with the License. You may obtain | |
# a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
# License for the specific language governing permissions and limitations | |
# under the License. | |
from oslo_log import log as logging | |
import nova.conf | |
from nova.i18n import _LW | |
from nova.scheduler.filters import utils | |
from nova.scheduler import weights | |
CONF = nova.conf.CONF | |
LOG = logging.getLogger(__name__) | |
class AggregateRAMWeigher(weights.BaseHostWeigher): | |
"""AggregateRAMWeigher with per-aggregate RAM weight multiplier. | |
Fallback to global ram_weight_multiplier if no per-aggregate setting found. | |
""" | |
def _weigh_object(self, host_state, weight_properties): | |
aggregate_vals = utils.aggregate_values_from_key( | |
host_state, | |
'ram_weight_multiplier') | |
try: | |
weight = utils.validate_num_values( | |
aggregate_vals, | |
CONF.ram_weight_multiplier, cast_to=float) | |
except ValueError as e: | |
LOG.warning(_LW("Could not decode ram_weight_multiplier: '%s'"), e) | |
weight = CONF.ram_weight_multiplier | |
return host_state.free_ram_mb * weight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment