Skip to content

Instantly share code, notes, and snippets.

@mgagne
Last active May 1, 2018 14:27
Show Gist options
  • Save mgagne/659ca02e63779802de6f7aec8cda612a to your computer and use it in GitHub Desktop.
Save mgagne/659ca02e63779802de6f7aec8cda612a to your computer and use it in GitHub Desktop.
Favor reserved host - Nova scheduler - Mitaka
from oslo_config import cfg
from nova.scheduler import weights
CONF = cfg.CONF
opts = [
cfg.FloatOpt('reserved_host_for_tenant_weight_multiplier',
default=1.0,
help='Multiplier used for reserved host. Negative '
'numbers mean to stack vs spread.'),
]
CONF.register_opts(opts)
class ReservedHostForTenantWeigher(weights.BaseHostWeigher):
def weight_multiplier(self):
return CONF.reserved_host_for_tenant_weight_multiplier
def _weigh_object(self, host_state, weight_properties):
stats = host_state.stats
if stats.get('reserved_for_tenant_id'):
return 1.0
return 0.0
from nova.scheduler import filters
def normalize_uuid(uuid):
return uuid.lower().replace('-', '')
class TenantFilter(filters.BaseHostFilter):
def host_passes(self, host_state, spec_obj):
project_id = normalize_uuid(spec_obj.project_id)
stats = host_state.stats
reserved_for = stats.get('reserved_for_tenant_id')
return not reserved_for or (
normalize_uuid(reserved_for) == project_id
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment