summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-06-01 17:35:49 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-06-01 17:35:49 -0700
commitcf464dc7f2093ea3d1f831915ce22f54f0d1c90a (patch)
tree58ff42f6a8df40629340c270bd44dd028ee045a0 /nova
parentb05dcdc69387ecd54e40063e66355961d39b4430 (diff)
list --reservation now works across zones
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/create_instance_controller.py2
-rw-r--r--nova/api/openstack/views/servers.py12
-rw-r--r--nova/compute/api.py22
-rw-r--r--nova/scheduler/api.py8
4 files changed, 34 insertions, 10 deletions
diff --git a/nova/api/openstack/create_instance_controller.py b/nova/api/openstack/create_instance_controller.py
index 786d74e37..edb1a5007 100644
--- a/nova/api/openstack/create_instance_controller.py
+++ b/nova/api/openstack/create_instance_controller.py
@@ -116,8 +116,6 @@ class OpenstackCreateInstanceController(common.OpenstackController):
zone_blob = env['server'].get('blob')
reservation_id = env['server'].get('reservation_id')
- LOG.exception("******* CREATE_INSTANCE RES_ID=%s of %s" % (reservation_id, env))
-
inst_type = instance_types.get_instance_type_by_flavor_id(flavor_id)
extra_values = {
'instance_type': inst_type,
diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py
index 0be468edc..0ee461dde 100644
--- a/nova/api/openstack/views/servers.py
+++ b/nova/api/openstack/views/servers.py
@@ -41,10 +41,13 @@ class ViewBuilder(object):
def build(self, inst, is_detail):
"""Return a dict that represenst a server."""
- if is_detail:
- server = self._build_detail(inst)
+ if inst.get('_is_precooked', False):
+ server = dict(server=inst)
else:
- server = self._build_simple(inst)
+ if is_detail:
+ server = self._build_detail(inst)
+ else:
+ server = self._build_simple(inst)
self._build_extra(server, inst)
@@ -78,6 +81,9 @@ class ViewBuilder(object):
ctxt = nova.context.get_admin_context()
compute_api = nova.compute.API()
+
+ # TODO(sandy): Could be a bug here since the instance ID
+ # may have come from another Zone.
if compute_api.has_finished_migration(ctxt, inst['id']):
inst_dict['status'] = 'RESIZE-CONFIRM'
diff --git a/nova/compute/api.py b/nova/compute/api.py
index fc369ccd2..f9e76ffbc 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -543,6 +543,25 @@ class API(base.Base):
"""
return self.get(context, instance_id)
+ def get_all_across_zones(self, context, reservation_id):
+ """Get all instances with this reservation_id, across
+ all available Zones (if any).
+ """
+ instances = self.db.instance_get_all_by_reservation(
+ context, reservation_id)
+
+ children = scheduler_api.call_zone_method(context, "list",
+ novaclient_collection_name="servers",
+ reservation_id=reservation_id)
+
+ for zone, servers in children:
+ for server in servers:
+ LOG.debug("**** INSTANCE= %s" % server._info)
+ # Results are ready to send to user. No need to scrub.
+ server._info['_is_precooked'] = True
+ instances.append(server._info)
+ return instances
+
def get_all(self, context, project_id=None, reservation_id=None,
fixed_ip=None):
"""Get all instances filtered by one of the given parameters.
@@ -552,8 +571,7 @@ class API(base.Base):
"""
if reservation_id is not None:
- return self.db.instance_get_all_by_reservation(
- context, reservation_id)
+ return self.get_all_across_zones(context, reservation_id)
if fixed_ip is not None:
return self.db.fixed_ip_get_instance(context, fixed_ip)
diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py
index de0660713..0f423655e 100644
--- a/nova/scheduler/api.py
+++ b/nova/scheduler/api.py
@@ -118,7 +118,8 @@ def _process(func, zone):
return func(nova, zone)
-def call_zone_method(context, method, errors_to_ignore=None, *args, **kwargs):
+def call_zone_method(context, method_name, errors_to_ignore=None,
+ novaclient_collection_name='zones', *args, **kwargs):
"""Returns a list of (zone, call_result) objects."""
if not isinstance(errors_to_ignore, (list, tuple)):
# This will also handle the default None
@@ -138,11 +139,12 @@ def call_zone_method(context, method, errors_to_ignore=None, *args, **kwargs):
#TODO (dabo) - add logic for failure counts per zone,
# with escalation after a given number of failures.
continue
- zone_method = getattr(nova.zones, method)
+ novaclient_collection = getattr(nova, novaclient_collection_name)
+ collection_method = getattr(novaclient_collection, method_name)
def _error_trap(*args, **kwargs):
try:
- return zone_method(*args, **kwargs)
+ return collection_method(*args, **kwargs)
except Exception as e:
if type(e) in errors_to_ignore:
return None