fix lp 798361

This commit is contained in:
Sandy Walsh
2011-06-20 16:56:59 -07:00
parent 0c042d6bed
commit e92004cd77
2 changed files with 31 additions and 20 deletions

View File

@@ -33,6 +33,7 @@ from nova import flags
from nova import log as logging
from nova import rpc
from nova.compute import api as compute_api
from nova.scheduler import api
from nova.scheduler import driver
@@ -52,10 +53,21 @@ class ZoneAwareScheduler(driver.Scheduler):
"""Call novaclient zone method. Broken out for testing."""
return api.call_zone_method(context, method, specs=specs, zones=zones)
def _provision_resource_locally(self, context, item, instance_id, kwargs):
def _provision_resource_locally(self, context, build_plan_item,
request_spec):
"""Create the requested resource in this Zone."""
host = item['hostname']
host = build_plan_item['hostname']
base_options = request_spec['instance_properties']
# TODO(sandy): I guess someone needs to add block_device_mapping
# support at some point? Also, OS API has no concept of security
# groups.
instance = compute_api.create_db_entry_for_new_instance(context,
base_options, None, [])
instance_id = instance['instance_id']
kwargs['instance_id'] = instance_id
rpc.cast(context,
db.queue_get_for(context, "compute", host),
{"method": "run_instance",
@@ -115,8 +127,8 @@ class ZoneAwareScheduler(driver.Scheduler):
nova.servers.create(name, image_ref, flavor_id, ipgroup, meta, files,
child_blob, reservation_id=reservation_id)
def _provision_resource_from_blob(self, context, item, instance_id,
request_spec, kwargs):
def _provision_resource_from_blob(self, context, build_plan_item,
instance_id, request_spec, kwargs):
"""Create the requested resource locally or in a child zone
based on what is stored in the zone blob info.
@@ -132,12 +144,12 @@ class ZoneAwareScheduler(driver.Scheduler):
request."""
host_info = None
if "blob" in item:
if "blob" in build_plan_item:
# Request was passed in from above. Is it for us?
host_info = self._decrypt_blob(item['blob'])
elif "child_blob" in item:
host_info = self._decrypt_blob(build_plan_item['blob'])
elif "child_blob" in build_plan_item:
# Our immediate child zone provided this info ...
host_info = item
host_info = build_plan_item
if not host_info:
raise InvalidBlob()
@@ -147,19 +159,18 @@ class ZoneAwareScheduler(driver.Scheduler):
self._ask_child_zone_to_create_instance(context, host_info,
request_spec, kwargs)
else:
self._provision_resource_locally(context, host_info,
instance_id, kwargs)
self._provision_resource_locally(context, host_info, request_spec)
def _provision_resource(self, context, item, instance_id, request_spec,
kwargs):
def _provision_resource(self, context, build_plan_item, instance_id,
request_spec, kwargs):
"""Create the requested resource in this Zone or a child zone."""
if "hostname" in item:
self._provision_resource_locally(context, item, instance_id,
kwargs)
if "hostname" in build_plan_item:
self._provision_resource_locally(context, build_plan_item,
request_spec)
return
self._provision_resource_from_blob(context, item, instance_id,
request_spec, kwargs)
self._provision_resource_from_blob(context, build_plan_item,
instance_id, request_spec, kwargs)
def _adjust_child_weights(self, child_results, zones):
"""Apply the Scale and Offset values from the Zone definition
@@ -215,8 +226,8 @@ class ZoneAwareScheduler(driver.Scheduler):
break
item = build_plan.pop(0)
self._provision_resource(context, item, instance_id, request_spec,
kwargs)
self._provision_resource(context, build_plan_item, instance_id,
request_spec, kwargs)
# Returning None short-circuits the routing to Compute (since
# we've already done it here)

View File

@@ -110,7 +110,7 @@ def fake_ask_child_zone_to_create_instance(context, zone_info,
was_called = True
def fake_provision_resource_locally(context, item, instance_id, kwargs):
def fake_provision_resource_locally(context, build_plan, request_spec):
global was_called
was_called = True