glance.image_cache.drivers package

Submodules

glance.image_cache.drivers.base module

Base attribute driver class

class glance.image_cache.drivers.base.Driver[source]

Bases: object

clean(stall_time=None)[source]

Dependent on the driver, clean up and destroy any invalid or incomplete cached images

configure()[source]

Configure the driver to use the stored configuration options Any store that needs special configuration should implement this method. If the store was not able to successfully configure itself, it should raise exception.BadDriverConfiguration

delete_all_cached_images()[source]

Removes all cached image files and any attributes about the images and returns the number of cached image files that were deleted.

delete_all_queued_images()[source]

Removes all queued image files and any attributes about the images and returns the number of queued image files that were deleted.

delete_cached_image(image_id)[source]

Removes a specific cached image file and any attributes about the image

Parameters:image_id – Image ID
delete_queued_image(image_id)[source]

Removes a specific queued image file and any attributes about the image

Parameters:image_id – Image ID
get_cache_size()[source]

Returns the total size in bytes of the image cache.

get_cached_images()[source]

Returns a list of records about cached images.

The list of records shall be ordered by image ID and shall look like:

[
    {
    'image_id': <IMAGE_ID>,
    'hits': INTEGER,
    'last_modified': ISO_TIMESTAMP,
    'last_accessed': ISO_TIMESTAMP,
    'size': INTEGER
    }, ...
]
get_image_filepath(image_id, cache_status='active')[source]

This crafts an absolute path to a specific entry

Parameters:
  • image_id – Image ID
  • cache_status – Status of the image in the cache
get_image_size(image_id)[source]

Return the size of the image file for an image with supplied identifier.

Parameters:image_id – Image ID
get_least_recently_accessed()[source]

Return a tuple containing the image_id and size of the least recently accessed cached file, or None if no cached files.

get_queued_images()[source]

Returns a list of image IDs that are in the queue. The list should be sorted by the time the image ID was inserted into the queue.

is_cacheable(image_id)[source]

Returns True if the image with the supplied ID can have its image file cached, False otherwise.

Parameters:image_id – Image ID
is_cached(image_id)[source]

Returns True if the image with the supplied ID has its image file cached.

Parameters:image_id – Image ID
is_queued(image_id)[source]

Returns True if the image identifier is in our cache queue.

Parameters:image_id – Image ID
open_for_read(image_id)[source]

Open and yield file for reading the image file for an image with supplied identifier.

Parameters:image_id – Image ID
open_for_write(image_id)[source]

Open a file for writing the image file for an image with supplied identifier.

Parameters:image_id – Image ID
queue_image(image_id)[source]

Puts an image identifier in a queue for caching. Return True on successful add to the queue, False otherwise...

Parameters:image_id – Image ID
set_paths()[source]

Creates all necessary directories under the base cache directory

glance.image_cache.drivers.sqlite module

Cache driver that uses SQLite to store information about cached images

class glance.image_cache.drivers.sqlite.Driver[source]

Bases: glance.image_cache.drivers.base.Driver

Cache driver that uses xattr file tags and requires a filesystem that has atimes set.

clean(stall_time=None)[source]

Delete any image files in the invalid directory and any files in the incomplete directory that are older than a configurable amount of time.

configure()[source]

Configure the driver to use the stored configuration options Any store that needs special configuration should implement this method. If the store was not able to successfully configure itself, it should raise exception.BadDriverConfiguration

delete_all_cached_images()[source]

Removes all cached image files and any attributes about the images

delete_all_queued_images()[source]

Removes all queued image files and any attributes about the images

delete_cached_image(image_id)[source]

Removes a specific cached image file and any attributes about the image

Parameters:image_id – Image ID
delete_invalid_files()[source]

Removes any invalid cache entries

delete_queued_image(image_id)[source]

Removes a specific queued image file and any attributes about the image

Parameters:image_id – Image ID
delete_stalled_files(older_than)[source]

Removes any incomplete cache entries older than a supplied modified time.

Parameters:older_than – Files written to on or before this timestamp will be deleted.
get_cache_files(basepath)[source]

Returns cache files in the supplied directory

Parameters:basepath – Directory to look in for cache files
get_cache_size()[source]

Returns the total size in bytes of the image cache.

get_cached_images()[source]

Returns a list of records about cached images.

get_db(*args, **kwds)[source]

Returns a context manager that produces a database connection that self-closes and calls rollback if an error occurs while using the database connection

get_hit_count(image_id)[source]

Return the number of hits that an image has.

Parameters:image_id – Opaque image identifier
get_least_recently_accessed()[source]

Return a tuple containing the image_id and size of the least recently accessed cached file, or None if no cached files.

get_queued_images()[source]

Returns a list of image IDs that are in the queue. The list should be sorted by the time the image ID was inserted into the queue.

initialize_db()[source]
is_being_cached(image_id)[source]

Returns True if the image with supplied id is currently in the process of having its image file cached.

Parameters:image_id – Image ID
is_cacheable(image_id)[source]

Returns True if the image with the supplied ID can have its image file cached, False otherwise.

Parameters:image_id – Image ID
is_cached(image_id)[source]

Returns True if the image with the supplied ID has its image file cached.

Parameters:image_id – Image ID
is_queued(image_id)[source]

Returns True if the image identifier is in our cache queue.

Parameters:image_id – Image ID
open_for_read(*args, **kwds)[source]

Open and yield file for reading the image file for an image with supplied identifier.

Parameters:image_id – Image ID
open_for_write(*args, **kwds)[source]

Open a file for writing the image file for an image with supplied identifier.

Parameters:image_id – Image ID
queue_image(image_id)[source]

This adds a image to be cache to the queue.

If the image already exists in the queue or has already been cached, we return False, True otherwise

Parameters:image_id – Image ID
class glance.image_cache.drivers.sqlite.SqliteConnection(*args, **kwargs)[source]

Bases: sqlite3.Connection

SQLite DB Connection handler that plays well with eventlet, slightly modified from Swift’s similar code.

commit()[source]
execute(*args, **kwargs)[source]
glance.image_cache.drivers.sqlite.delete_cached_file(path)[source]
glance.image_cache.drivers.sqlite.dict_factory(cur, row)[source]

glance.image_cache.drivers.xattr module

Cache driver that uses xattr file tags and requires a filesystem that has atimes set.

Assumptions

  1. Cache data directory exists on a filesytem that updates atime on reads (‘noatime’ should NOT be set)

  2. Cache data directory exists on a filesystem that supports xattrs. This is optional, but highly recommended since it allows us to present ops with useful information pertaining to the cache, like human readable filenames and statistics.

  3. glance-prune is scheduled to run as a periodic job via cron. This

    is needed to run the LRU prune strategy to keep the cache size within the limits set by the config file.

Cache Directory Notes

The image cache data directory contains the main cache path, where the active cache entries and subdirectories for handling partial downloads and errored-out cache images.

The layout looks like:

$image_cache_dir/
entry1 entry2 ... incomplete/ invalid/ queue/
class glance.image_cache.drivers.xattr.Driver[source]

Bases: glance.image_cache.drivers.base.Driver

Cache driver that uses xattr file tags and requires a filesystem that has atimes set.

clean(stall_time=None)[source]

Delete any image files in the invalid directory and any files in the incomplete directory that are older than a configurable amount of time.

configure()[source]

Configure the driver to use the stored configuration options Any store that needs special configuration should implement this method. If the store was not able to successfully configure itself, it should raise exception.BadDriverConfiguration

delete_all_cached_images()[source]

Removes all cached image files and any attributes about the images

delete_all_queued_images()[source]

Removes all queued image files and any attributes about the images

delete_cached_image(image_id)[source]

Removes a specific cached image file and any attributes about the image

Parameters:image_id – Image ID
delete_queued_image(image_id)[source]

Removes a specific queued image file and any attributes about the image

Parameters:image_id – Image ID
get_cache_size()[source]

Returns the total size in bytes of the image cache.

get_cached_images()[source]

Returns a list of records about cached images.

get_hit_count(image_id)[source]

Return the number of hits that an image has.

Parameters:image_id – Opaque image identifier
get_least_recently_accessed()[source]

Return a tuple containing the image_id and size of the least recently accessed cached file, or None if no cached files.

get_queued_images()[source]

Returns a list of image IDs that are in the queue. The list should be sorted by the time the image ID was inserted into the queue.

is_being_cached(image_id)[source]

Returns True if the image with supplied id is currently in the process of having its image file cached.

Parameters:image_id – Image ID
is_cacheable(image_id)[source]

Returns True if the image with the supplied ID can have its image file cached, False otherwise.

Parameters:image_id – Image ID
is_cached(image_id)[source]

Returns True if the image with the supplied ID has its image file cached.

Parameters:image_id – Image ID
is_queued(image_id)[source]

Returns True if the image identifier is in our cache queue.

open_for_read(*args, **kwds)[source]

Open and yield file for reading the image file for an image with supplied identifier.

Parameters:image_id – Image ID
open_for_write(*args, **kwds)[source]

Open a file for writing the image file for an image with supplied identifier.

Parameters:image_id – Image ID
queue_image(image_id)[source]

This adds a image to be cache to the queue.

If the image already exists in the queue or has already been cached, we return False, True otherwise

Parameters:image_id – Image ID
reap_invalid(grace=None)[source]

Remove any invalid cache entries

Parameters:grace – Number of seconds to keep an invalid entry around for debugging purposes. If None, then delete immediately.
reap_stalled(grace=None)[source]

Remove any stalled cache entries

Parameters:grace – Number of seconds to keep an invalid entry around for debugging purposes. If None, then delete immediately.
glance.image_cache.drivers.xattr.delete_cached_file(path)[source]
glance.image_cache.drivers.xattr.get_all_regular_files(basepath)[source]
glance.image_cache.drivers.xattr.get_xattr(path, key, **kwargs)[source]

Return the value for a particular xattr

If the key doesn’t not exist, or xattrs aren’t supported by the file system then a KeyError will be raised, that is, unless you specify a default using kwargs.

glance.image_cache.drivers.xattr.inc_xattr(path, key, n=1)[source]

Increment the value of an xattr (assuming it is an integer).

BEWARE, this code does have a RACE CONDITION, since the read/update/write sequence is not atomic.

Since the use-case for this function is collecting stats–not critical– the benefits of simple, lock-free code out-weighs the possibility of an occasional hit not being counted.

glance.image_cache.drivers.xattr.set_xattr(path, key, value)[source]

Set the value of a specified xattr.

If xattrs aren’t supported by the file-system, we skip setting the value.

Module contents