Merge "Avoid unnecessary system_metadata db lookup"

This commit is contained in:
Jenkins 2012-11-12 18:16:06 +00:00 committed by Gerrit Code Review
commit 6a63baadae
1 changed files with 9 additions and 7 deletions

View File

@ -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: