diff options
| author | Rick Harris <rconradharris@gmail.com> | 2012-06-11 19:47:18 +0000 |
|---|---|---|
| committer | Rick Harris <rconradharris@gmail.com> | 2012-06-11 20:02:11 +0000 |
| commit | b5ddcb2a91caac505b0ad35f65f058cdd80f9ec9 (patch) | |
| tree | c2b0a95745c78882502f87154c8304a980722b1f /nova/virt | |
| parent | b1b09368f07b178416949b045f459bd00ec491a3 (diff) | |
Adds property to selectively enable image caching.
The image-property `cache_in_nova` can be used to choose which images
should be cached in Nova. One use-case would be to cache base images but
not any customer snapshots.
Change-Id: I1b8ac914a6effd4cd4653aae7e4eac9d14d0e7bd
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 69478d34f..1eb56b880 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -36,6 +36,7 @@ from eventlet import greenthread from nova.compute import instance_types from nova.compute import power_state +from nova import db from nova import exception from nova import flags from nova.image import glance @@ -677,12 +678,33 @@ def create_image(context, session, instance, image_id, image_type): Returns: A list of dictionaries that describe VDIs """ - if FLAGS.cache_images and image_type != ImageType.DISK_ISO: + cache_images = FLAGS.cache_images.lower() + + # Deterimine if the image is cacheable + if image_type == ImageType.DISK_ISO: + cache = False + 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']) + try: + cache = utils.bool_from_str(sys_meta['image_cache_in_nova']) + except KeyError: + cache = False + elif cache_images == 'none': + cache = False + else: + LOG.warning(_("Unrecognized cache_images value '%s', defaulting to" + " True"), FLAGS.cache_images) + cache = True + + # Fetch (and cache) the image + if cache: vdis = _create_cached_image( context, session, instance, image_id, image_type) else: - # If caching is disabled, we do not have to keep a copy of the - # image. Fetch the image from glance. vdis = fetch_image( context, session, instance, image_id, image_type) |
