From e2f2d10e1a59a6688c6f9763fff0fd45578da5eb Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 23 Jan 2013 17:34:13 -0500 Subject: Avoid db lookup in info_from_instance(). The method info_from_instance() in nova.notifications was doing a db lookup for the system_metadata for an instance. This patch updates that code to get that data from the instance that's passed in instead. The rest of the patch are related changes to make that happen. metadata_to_dict() was needed here. It lived in nova.compute.utils. nova.compute.utils already imported nova.notifications, so using it from there would have created a circular import. Move the method to nova.utils instead and update the tree to use it from its new location. I also noticed that the xen driver had a copy of metdata_to_dict(). This patch removes it and uses the common implementation in nova.utils. 'system_metadata' was added to _extra_keys of the Instance db model so that it would show up in a serialized instance. Tests failed without it as the result of getting instances via the conductor API did not include system_metadata. Now it's there. Part of bp no-db-compute. Change-Id: I451355fb26ae29f13b71438f7896c448b59f97b0 --- nova/virt/xenapi/vm_utils.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 52a5f37b2..582a9320a 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -196,13 +196,6 @@ class ImageType(object): }.get(image_type_id) -def _system_metadata_to_dict(system_metadata): - result = {} - for item in system_metadata: - result[item['key']] = item['value'] - return result - - def create_vm(session, instance, name_label, kernel, ramdisk, use_pv_kernel=False): """Create a VM record. Returns new VM reference. @@ -994,7 +987,7 @@ def _create_image(context, session, instance, name_label, image_id, elif cache_images == 'all': cache = True elif cache_images == 'some': - sys_meta = _system_metadata_to_dict(instance['system_metadata']) + sys_meta = utils.metadata_to_dict(instance['system_metadata']) try: cache = utils.bool_from_str(sys_meta['image_cache_in_nova']) except KeyError: @@ -1087,7 +1080,7 @@ def _image_uses_bittorrent(context, instance): if xenapi_torrent_images == 'all': bittorrent = True elif xenapi_torrent_images == 'some': - sys_meta = _system_metadata_to_dict(instance['system_metadata']) + sys_meta = utils.metadata_to_dict(instance['system_metadata']) try: bittorrent = utils.bool_from_str(sys_meta['image_bittorrent']) except KeyError: -- cgit