From 7b34a2d767b60e053ac1f49d1cdd8c853b8d9133 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 13 Apr 2012 23:53:14 -0500 Subject: Refactor availability zone handling out to a method. Also moves filter_properties closer to where it's used. Change-Id: Ic2a95c2f15d138632e807249da0c26082dd1a7bf --- nova/compute/api.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 7f1a1a0d4..21c58f54c 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -273,6 +273,20 @@ class API(BaseAPI): return kernel_id, ramdisk_id + def _handle_availability_zone(self, availability_zone): + # 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. + forced_host = None + if availability_zone and ':' in availability_zone: + availability_zone, forced_host = availability_zone.split(':') + + if not availability_zone: + availability_zone = FLAGS.default_schedule_zone + + return availability_zone, forced_host + def _create_instance(self, context, instance_type, image_href, kernel_id, ramdisk_id, min_count, max_count, @@ -362,21 +376,8 @@ class API(BaseAPI): 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 = {} - - filter_properties['scheduler_hints'] = scheduler_hints + availability_zone, forced_host = self._handle_availability_zone( + availability_zone) base_options = { 'reservation_id': reservation_id, @@ -427,6 +428,10 @@ class API(BaseAPI): # a child zone. rpc_method = rpc.call + filter_properties = dict(scheduler_hints=scheduler_hints) + if context.is_admin and forced_host: + filter_properties['force_hosts'] = [forced_host] + # TODO(comstud): We should use rpc.multicall when we can # retrieve the full instance dictionary from the scheduler. # Otherwise, we could exceed the AMQP max message size limit. -- cgit