diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-15 21:58:15 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-15 21:58:15 +0000 |
| commit | f1008417bf01e42ec30bccb436d0c14964aa7548 (patch) | |
| tree | c003f049bf9e7e27ef3e8534bb08e8365be81eaa | |
| parent | e1a9d42fcb2f2728f5732265a6b3a81f101f4219 (diff) | |
| parent | b5ddcb2a91caac505b0ad35f65f058cdd80f9ec9 (diff) | |
| download | nova-f1008417bf01e42ec30bccb436d0c14964aa7548.tar.gz nova-f1008417bf01e42ec30bccb436d0c14964aa7548.tar.xz nova-f1008417bf01e42ec30bccb436d0c14964aa7548.zip | |
Merge "Adds property to selectively enable image caching."
| -rw-r--r-- | nova/flags.py | 9 | ||||
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 28 |
2 files changed, 31 insertions, 6 deletions
diff --git a/nova/flags.py b/nova/flags.py index 9e4467989..c427a7e94 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -409,9 +409,12 @@ global_opts = [ cfg.ListOpt('isolated_hosts', default=[], help='Host reserved for specific images'), - cfg.BoolOpt('cache_images', - default=True, - help='Cache glance images locally'), + cfg.StrOpt('cache_images', + default='all', + help='Cache glance images locally. `all` will cache all' + ' images, `some` will only cache images that have the' + ' image_property `cache_in_nova=True`, and `none` turns' + ' off caching entirely'), cfg.BoolOpt('use_cow_images', default=True, help='Whether to use cow images'), 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) |
