summaryrefslogtreecommitdiff
path: root/ironic/drivers/modules/image_cache.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@redhat.com>2014-05-07 18:04:33 +0200
committerDmitry Tantsur <dtantsur@redhat.com>2014-05-28 11:19:06 +0200
commit7562dac1e27c13fca44e18f38f1c1874a7cf13b4 (patch)
treed67661ad6ab364b51c9382c81a740e75232bcbe8 /ironic/drivers/modules/image_cache.py
parent301d2c62bc38aa7bcc63ef051969130fcecb6654 (diff)
downloadironic-7562dac1e27c13fca44e18f38f1c1874a7cf13b4.tar.gz
Consider free disk space before downloading images into cache
This patch makes PXE driver ensure it has enough disk space to actually download required images. If it does not, it tries to make some space by starting cache clean up. While it would be better to have this code in ImageCache itself, by keeping it in PXE module we have the ability to clean up both caches, not only current one, thus reclaiming more space. We clean up instance image cache first, because: 1. It's probably larger 2. Instance images are not required for running instances, so they are more likely to be cleaned In the follow-up patch I'll implement hints for clean_up() call on how much space we need. Otherwise clean_up procedure may think that nothing needs to be cleaned even though we don't have enough space for new downloads. This patch also adds ironic.common.images.download_size() helper and makes master_dir attribute of ImageCache public. One more side-effect on implementation is that values in pxe_info dict are now tuples (as they are supposed to be), not lists. Change-Id: I1e7294b6e7155d83e72cfd144abdca858cab0aae Partial-Bug: #1316168
Diffstat (limited to 'ironic/drivers/modules/image_cache.py')
-rw-r--r--ironic/drivers/modules/image_cache.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/ironic/drivers/modules/image_cache.py b/ironic/drivers/modules/image_cache.py
index cee42bf3e..0d525ebcf 100644
--- a/ironic/drivers/modules/image_cache.py
+++ b/ironic/drivers/modules/image_cache.py
@@ -57,7 +57,7 @@ class ImageCache(object):
:param cache_ttl: cache entity TTL in seconds
:param image_service: Glance image service to use, None for default
"""
- self._master_dir = master_dir
+ self.master_dir = master_dir
self._cache_size = cache_size
self._cache_ttl = cache_ttl
self._image_service = image_service
@@ -76,7 +76,7 @@ class ImageCache(object):
:param ctx: context
"""
img_download_lock_name = 'download-image'
- if self._master_dir is None:
+ if self.master_dir is None:
#NOTE(ghe): We don't share images between instances/hosts
if not CONF.parallel_image_downloads:
with lockutils.lock(img_download_lock_name, 'ironic-'):
@@ -90,7 +90,7 @@ class ImageCache(object):
#TODO(ghe): have hard links and counts the same behaviour in all fs
master_file_name = service_utils.parse_image_ref(uuid)[0]
- master_path = os.path.join(self._master_dir, master_file_name)
+ master_path = os.path.join(self.master_dir, master_file_name)
if CONF.parallel_image_downloads:
img_download_lock_name = 'download-image:%s' % master_file_name
@@ -133,7 +133,7 @@ class ImageCache(object):
"""
#TODO(ghe): timeout and retry for downloads
#TODO(ghe): logging when image cannot be created
- fd, tmp_path = tempfile.mkstemp(dir=self._master_dir)
+ fd, tmp_path = tempfile.mkstemp(dir=self.master_dir)
os.close(fd)
images.fetch_to_raw(ctx, uuid, tmp_path,
self._image_service)
@@ -151,13 +151,13 @@ class ImageCache(object):
Protected by global lock, so that no one messes with master images
after we get listing and before we actually delete files.
"""
- if self._master_dir is None:
+ if self.master_dir is None:
return
LOG.debug("Starting clean up for master image cache %(dir)s" %
- {'dir': self._master_dir})
+ {'dir': self.master_dir})
- listing = _find_candidates_for_deletion(self._master_dir)
+ listing = _find_candidates_for_deletion(self.master_dir)
survived = self._clean_up_too_old(listing)
self._clean_up_ensure_cache_size(survived)
@@ -187,8 +187,8 @@ class ImageCache(object):
listing = sorted(listing,
key=lambda entry: entry[1],
reverse=True)
- total_listing = (os.path.join(self._master_dir, f)
- for f in os.listdir(self._master_dir))
+ total_listing = (os.path.join(self.master_dir, f)
+ for f in os.listdir(self.master_dir))
total_size = sum(os.path.getsize(f)
for f in total_listing)
while total_size > self._cache_size and listing:
@@ -206,7 +206,7 @@ class ImageCache(object):
LOG.info(_("After cleaning up cache dir %(dir)s "
"cache size %(actual)d is still larger than "
"threshold %(expected)d") %
- {'dir': self._master_dir, 'actual': total_size,
+ {'dir': self.master_dir, 'actual': total_size,
'expected': self._cache_size})