ironic.drivers.modules.image_cache module¶
Utility for caching master images.
- class ironic.drivers.modules.image_cache.ImageCache(master_dir, cache_size, cache_ttl)[source]¶
Bases:
object
Class handling access to cache for master images.
- clean_up(amount=None)[source]¶
Clean up directory with images, keeping cache of the latest images.
Files with link count >1 are never deleted. Protected by global lock, so that no one messes with master images after we get listing and before we actually delete files.
- Parameters:
amount – if present, amount of space to reclaim in bytes, cleaning will stop, if this goal was reached, even if it is possible to clean up more files
- fetch_image(href, dest_path, ctx=None, force_raw=True, expected_format=None, expected_checksum=None, expected_checksum_algo=None)[source]¶
Fetch image by given href to the destination path.
Does nothing if destination path exists and is up to date with cache and href contents. Only creates a hard link (dest_path) to cached image if requested image is already in cache and up to date with href contents. Otherwise downloads an image, stores it in cache and creates a hard link (dest_path) to it.
- Parameters:
href – image UUID or href to fetch
dest_path – destination file path
ctx – context
force_raw – boolean value, whether to convert the image to raw format
expected_format – The expected image format.
expected_checksum – The expected image checksum
expected_checksum_algo – The expected image checksum algorithm, if needed/supplied.
- ironic.drivers.modules.image_cache.clean_up_caches(ctx, directory, images_info)[source]¶
Explicitly cleanup caches based on their priority (if required).
This cleans up the caches to free up the amount of space required for the images in images_info. The caches are cleaned up one after the other in the order of their priority. If we still cannot free up enough space after trying all the caches, this method throws exception.
- Parameters:
ctx – context
directory – the directory (of the cache) to be freed up.
images_info – a list of tuples of the form (image_uuid,path) for which space is to be created in cache.
- Raises:
InsufficientDiskSpace exception, if we cannot free up enough space after trying all the caches.