Skip to content

Commit

Permalink
Add option to force hosts to scheduler
Browse files Browse the repository at this point in the history
Change-Id: I7364115e247ebeb441fa838ac66db5ef5f608b55
  • Loading branch information
vishvananda committed Jan 21, 2012
1 parent 1bf066c commit 16ea348
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
22 changes: 18 additions & 4 deletions nova/compute/api.py
Expand Up @@ -284,6 +284,20 @@ def _create_instance(self, context, instance_type,
root_device_name = block_device.properties_root_device_name(
image['properties'])

# NOTE(vish): We have a legacy hack to allow admins to specify hosts
# via az using az:host. It might be nice to expose an
# api to specify specific hosts to force onto, but for
# now it just supports this legacy hack.
host = None
if availability_zone:
availability_zone, _x, host = availability_zone.partition(':')
if not availability_zone:
availability_zone = FLAGS.default_schedule_zone
if context.is_admin and host:
filter_properties = {'force_hosts': [host]}
else:
filter_properties = {}

base_options = {
'reservation_id': reservation_id,
'image_ref': image_href,
Expand Down Expand Up @@ -343,7 +357,8 @@ def _create_instance(self, context, instance_type,
availability_zone, injected_files,
admin_password, image,
num_instances, requested_networks,
block_device_mapping, security_group)
block_device_mapping, security_group,
filter_properties)

if create_instance_here:
return ([instance], reservation_id)
Expand Down Expand Up @@ -516,7 +531,8 @@ def _schedule_run_instance(self,
num_instances,
requested_networks,
block_device_mapping,
security_group):
security_group,
filter_properties):
"""Send a run_instance request to the schedulers for processing."""

pid = context.project_id
Expand All @@ -525,8 +541,6 @@ def _schedule_run_instance(self,
LOG.debug(_("Sending create to scheduler for %(pid)s/%(uid)s's") %
locals())

filter_properties = {}

request_spec = {
'image': image,
'instance_properties': base_options,
Expand Down
2 changes: 2 additions & 0 deletions nova/flags.py
Expand Up @@ -467,3 +467,5 @@ def _get_my_ip():

DEFINE_integer('service_down_time', 60,
'maximum time since last check-in for up service')
DEFINE_string('default_schedule_zone', None,
'zone to use when user doesnt specify one')
3 changes: 3 additions & 0 deletions nova/scheduler/host_manager.py
Expand Up @@ -117,6 +117,9 @@ def passes_filters(self, filter_fns, filter_properties):

if self.host in filter_properties.get('ignore_hosts', []):
return False
force_hosts = filter_properties.get('force_hosts', [])
if force_hosts:
return self.host in force_hosts
for filter_fn in filter_fns:
if not filter_fn(self, filter_properties):
return False
Expand Down
2 changes: 0 additions & 2 deletions nova/scheduler/simple.py
Expand Up @@ -35,8 +35,6 @@
"maximum number of volume gigabytes to allow per host")
flags.DEFINE_integer("max_networks", 1000,
"maximum number of networks to allow per host")
flags.DEFINE_string('default_schedule_zone', None,
'zone to use when user doesnt specify one')
flags.DEFINE_list('isolated_images', [], 'Images to run on isolated host')
flags.DEFINE_list('isolated_hosts', [], 'Host reserved for specific images')
flags.DEFINE_boolean('skip_isolated_core_check', True,
Expand Down
20 changes: 18 additions & 2 deletions nova/tests/scheduler/test_host_manager.py
Expand Up @@ -18,8 +18,6 @@

import datetime

import mox

from nova import db
from nova import exception
from nova import log as logging
Expand Down Expand Up @@ -364,3 +362,21 @@ def test_host_state_passes_filters_fails_from_ignore(self):
result = fake_host.passes_filters(filter_fns, filter_properties)
self.mox.VerifyAll()
self.assertFalse(result)

def test_host_state_passes_filters_skipped_from_force(self):
fake_host = host_manager.HostState('host1', 'compute')
filter_properties = {'force_hosts': ['host1']}

cls1 = ComputeFilterClass1()
cls2 = ComputeFilterClass2()
self.mox.StubOutWithMock(cls1, 'host_passes')
self.mox.StubOutWithMock(cls2, 'host_passes')
filter_fns = [cls1.host_passes, cls2.host_passes]

# cls[12].host_passes() not called because of short circuit
# with matching host to force

self.mox.ReplayAll()
result = fake_host.passes_filters(filter_fns, filter_properties)
self.mox.VerifyAll()
self.assertTrue(result)

0 comments on commit 16ea348

Please sign in to comment.