summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-05-15 16:00:05 +0200
committerChris Behrens <cbehrens@codestud.com>2013-06-10 23:10:39 +0000
commit41eb083d228f159e8d4e566148db5994ad49143c (patch)
tree41f8828730de39290c2b03f5fe1e08e691580caa /nova/compute
parent0d5fb06b39e8244429be72f05e2066d24572dc2e (diff)
Create an image BDM for every instance
This patch makes every boot create a block device mapping if the instance was started with an image. These block devices are not used anywhere at the moment but will be used in the future as part of a more flexible block device API. This patch also makes sure they are deleted once the instance is deleted as well. Change-Id: Ia89d531be71c460f1f82fcfce34b270639a23061 blueprint: improve-block-device-handling
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py10
-rwxr-xr-xnova/compute/manager.py10
2 files changed, 20 insertions, 0 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 0674cff5f..65142aef0 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -898,6 +898,16 @@ class API(base.Base):
continue
self._update_block_device_mapping(context,
instance_type, instance_uuid, mapping)
+ # NOTE(ndipanov): Create an image bdm - at the moment
+ # this is not used but is done for easier transition
+ # in the future.
+ if (instance['image_ref'] and not
+ self.is_volume_backed_instance(context, instance, None)):
+ image_bdm = block_device.create_image_bdm(instance['image_ref'])
+ image_bdm['instance_uuid'] = instance_uuid
+ self.db.block_device_mapping_update_or_create(context,
+ image_bdm,
+ legacy=False)
def _populate_instance_shutdown_terminate(self, instance, image,
block_device_mapping):
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 998be6f76..42f8029a5 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1376,6 +1376,7 @@ class ComputeManager(manager.SchedulerDependentManager):
as necessary.
"""
instance_uuid = instance['uuid']
+ image = instance['image_ref']
if context.is_admin and context.project_id != instance['project_id']:
project_id = instance['project_id']
@@ -1429,6 +1430,15 @@ class ComputeManager(manager.SchedulerDependentManager):
self._quota_commit(context, reservations, project_id=project_id)
# ensure block device mappings are not leaked
self.conductor_api.block_device_mapping_destroy(context, bdms)
+ # NOTE(ndipanov): Delete the dummy image BDM as well. This will not
+ # be needed once the manager code is using the image
+ if image:
+ # Do not convert to legacy here - we want them all
+ leftover_bdm = \
+ self.conductor_api.block_device_mapping_get_all_by_instance(
+ context, instance)
+ self.conductor_api.block_device_mapping_destroy(context,
+ leftover_bdm)
self._notify_about_instance_usage(context, instance, "delete.end",
system_metadata=system_meta)