From da1b387d36cda0297da097f1389bd382559d6fa5 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 7 Nov 2012 12:58:34 -0800 Subject: Avoid unnecessary system_metadata db lookup The bittorrent code in the xenapi driver added a specific database query for the instance_system_metadata. This query is unnecessary, as the system_metadata is available in the instance object itself. This patch removes the queries and adds the small amount of format translation required. Change-Id: If72593289e18d2c45db8e782972eb9051e10d740 --- nova/virt/xenapi/vm_utils.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index d0f59f56f..f6d28ca54 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -38,7 +38,6 @@ from nova import block_device from nova.compute import instance_types from nova.compute import power_state from nova import config -from nova import db from nova import exception from nova import flags from nova.image import glance @@ -181,6 +180,13 @@ 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. @@ -922,9 +928,7 @@ def _create_image(context, session, instance, name_label, image_id, elif cache_images == 'all': cache = True elif cache_images == 'some': - # FIXME(sirp): This should be eager loaded like instance metadata - sys_meta = db.instance_system_metadata_get(context, - instance['uuid']) + sys_meta = _system_metadata_to_dict(instance['system_metadata']) try: cache = utils.bool_from_str(sys_meta['image_cache_in_nova']) except KeyError: @@ -1017,9 +1021,7 @@ def _image_uses_bittorrent(context, instance): if xenapi_torrent_images == 'all': bittorrent = True elif xenapi_torrent_images == 'some': - # FIXME(sirp): This should be eager loaded like instance metadata - sys_meta = db.instance_system_metadata_get(context, - instance['uuid']) + sys_meta = _system_metadata_to_dict(instance['system_metadata']) try: bittorrent = utils.bool_from_str(sys_meta['image_bittorrent']) except KeyError: -- cgit