Add missing image to instance booted from volume

When booting an instance from a volume, the image_ref for
the instance will be None. And the API do not get the image
information for the instance also. So when we calling the
related API, we get "" for instance.image.

Change-Id: I3c35ab1d7c8bcec551fb5d67d0b44418266b32a4
Closes-bug: 1317880
This commit is contained in:
liyingjun
2014-06-24 19:20:50 +08:00
parent 277c69af20
commit c3191cf0ba
4 changed files with 76 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ from nova import compute
from nova.compute import flavors
from nova import exception
from nova import objects
from nova.objects import instance as instance_obj
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
from nova.openstack.common import strutils
@@ -599,6 +600,8 @@ class Controller(wsgi.Controller):
limit=limit,
marker=marker,
want_objects=True)
for instance in instance_list:
instance_obj.add_image_ref(context, instance)
except exception.MarkerNotFound:
msg = _('marker [%s] not found') % marker
raise exc.HTTPBadRequest(explanation=msg)
@@ -766,7 +769,8 @@ class Controller(wsgi.Controller):
context = req.environ['nova.context']
instance = self.compute_api.get(context, id,
want_objects=True)
req.cache_db_instance(instance)
req.cache_db_instance(instance_obj.add_image_ref(context,
instance))
return self._view_builder.show(req, instance)
except exception.NotFound:
msg = _("Instance could not be found")