fix lp 798361
This commit is contained in:
@@ -33,6 +33,7 @@ from nova import flags
|
|||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
|
|
||||||
|
from nova.compute import api as compute_api
|
||||||
from nova.scheduler import api
|
from nova.scheduler import api
|
||||||
from nova.scheduler import driver
|
from nova.scheduler import driver
|
||||||
|
|
||||||
@@ -52,10 +53,21 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
"""Call novaclient zone method. Broken out for testing."""
|
"""Call novaclient zone method. Broken out for testing."""
|
||||||
return api.call_zone_method(context, method, specs=specs, zones=zones)
|
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."""
|
"""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
|
kwargs['instance_id'] = instance_id
|
||||||
|
|
||||||
rpc.cast(context,
|
rpc.cast(context,
|
||||||
db.queue_get_for(context, "compute", host),
|
db.queue_get_for(context, "compute", host),
|
||||||
{"method": "run_instance",
|
{"method": "run_instance",
|
||||||
@@ -115,8 +127,8 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
nova.servers.create(name, image_ref, flavor_id, ipgroup, meta, files,
|
nova.servers.create(name, image_ref, flavor_id, ipgroup, meta, files,
|
||||||
child_blob, reservation_id=reservation_id)
|
child_blob, reservation_id=reservation_id)
|
||||||
|
|
||||||
def _provision_resource_from_blob(self, context, item, instance_id,
|
def _provision_resource_from_blob(self, context, build_plan_item,
|
||||||
request_spec, kwargs):
|
instance_id, request_spec, kwargs):
|
||||||
"""Create the requested resource locally or in a child zone
|
"""Create the requested resource locally or in a child zone
|
||||||
based on what is stored in the zone blob info.
|
based on what is stored in the zone blob info.
|
||||||
|
|
||||||
@@ -132,12 +144,12 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
request."""
|
request."""
|
||||||
|
|
||||||
host_info = None
|
host_info = None
|
||||||
if "blob" in item:
|
if "blob" in build_plan_item:
|
||||||
# Request was passed in from above. Is it for us?
|
# Request was passed in from above. Is it for us?
|
||||||
host_info = self._decrypt_blob(item['blob'])
|
host_info = self._decrypt_blob(build_plan_item['blob'])
|
||||||
elif "child_blob" in item:
|
elif "child_blob" in build_plan_item:
|
||||||
# Our immediate child zone provided this info ...
|
# Our immediate child zone provided this info ...
|
||||||
host_info = item
|
host_info = build_plan_item
|
||||||
|
|
||||||
if not host_info:
|
if not host_info:
|
||||||
raise InvalidBlob()
|
raise InvalidBlob()
|
||||||
@@ -147,19 +159,18 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
self._ask_child_zone_to_create_instance(context, host_info,
|
self._ask_child_zone_to_create_instance(context, host_info,
|
||||||
request_spec, kwargs)
|
request_spec, kwargs)
|
||||||
else:
|
else:
|
||||||
self._provision_resource_locally(context, host_info,
|
self._provision_resource_locally(context, host_info, request_spec)
|
||||||
instance_id, kwargs)
|
|
||||||
|
|
||||||
def _provision_resource(self, context, item, instance_id, request_spec,
|
def _provision_resource(self, context, build_plan_item, instance_id,
|
||||||
kwargs):
|
request_spec, kwargs):
|
||||||
"""Create the requested resource in this Zone or a child zone."""
|
"""Create the requested resource in this Zone or a child zone."""
|
||||||
if "hostname" in item:
|
if "hostname" in build_plan_item:
|
||||||
self._provision_resource_locally(context, item, instance_id,
|
self._provision_resource_locally(context, build_plan_item,
|
||||||
kwargs)
|
request_spec)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._provision_resource_from_blob(context, item, instance_id,
|
self._provision_resource_from_blob(context, build_plan_item,
|
||||||
request_spec, kwargs)
|
instance_id, request_spec, kwargs)
|
||||||
|
|
||||||
def _adjust_child_weights(self, child_results, zones):
|
def _adjust_child_weights(self, child_results, zones):
|
||||||
"""Apply the Scale and Offset values from the Zone definition
|
"""Apply the Scale and Offset values from the Zone definition
|
||||||
@@ -215,8 +226,8 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
break
|
break
|
||||||
|
|
||||||
item = build_plan.pop(0)
|
item = build_plan.pop(0)
|
||||||
self._provision_resource(context, item, instance_id, request_spec,
|
self._provision_resource(context, build_plan_item, instance_id,
|
||||||
kwargs)
|
request_spec, kwargs)
|
||||||
|
|
||||||
# Returning None short-circuits the routing to Compute (since
|
# Returning None short-circuits the routing to Compute (since
|
||||||
# we've already done it here)
|
# we've already done it here)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ def fake_ask_child_zone_to_create_instance(context, zone_info,
|
|||||||
was_called = True
|
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
|
global was_called
|
||||||
was_called = True
|
was_called = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user