From 04e6ad112f541df68b06c17f141be916e5e8bdb2 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 3 May 2012 22:30:32 +0000 Subject: Save the original base image ref for snapshots. Save the base image ref in instance system metadata for tracking purposes. (This is modified code originally from Rick Harris.) Change-Id: I574c597c7ff2e55675ebdaa7b3213b53e61a94b7 --- nova/compute/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index dcc6a7f06..9f99e00dc 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -688,6 +688,16 @@ class API(base.Base): new_value = str(value)[:255] instance['system_metadata']['image_%s' % key] = new_value + # Keep a record of the original base image that this + # image's instance is derived from: + base_image_ref = image['properties'].get('base_image_ref') + if not base_image_ref: + # base image ref property not previously set through a snapshot. + # default to using the image ref as the base: + base_image_ref = base_options['image_ref'] + + instance['system_metadata']['image_base_image_ref'] = base_image_ref + # Use 'default' security_group if none specified. if security_groups is None: security_groups = ['default'] @@ -1173,6 +1183,13 @@ class API(base.Base): 'image_type': image_type, } + # Persist base image ref as a Glance image property + system_meta = self.db.instance_system_metadata_get( + context, instance_uuid) + base_image_ref = system_meta.get('image_base_image_ref') + if base_image_ref: + properties['base_image_ref'] = base_image_ref + sent_meta = {'name': name, 'is_public': False} if image_type == 'backup': -- cgit