glance_store.common.utils module

System-level utilities and helper functions.

class glance_store.common.utils.CooperativeReader(fd)

Bases: object

An eventlet thread friendly class for reading in image data.

When accessing data either through the iterator or the read method we perform a sleep to allow a co-operative yield. When there is more than one image being uploaded/downloaded this prevents eventlet thread starvation, ie allows all threads to be scheduled periodically rather than having the same thread be continuously active.


Return the next chunk of the underlying iterator.

This is replaced with cooperative_read in __init__ if the underlying fd already supports read().

glance_store.common.utils.chunkiter(fp, chunk_size=65536)

Return an iterator to a file-like obj which yields fixed size chunks

  • fp – a file-like object

  • chunk_size – maximum size of chunk

glance_store.common.utils.chunkreadable(iter, chunk_size=65536)

Wrap a readable iterator with a reader yielding chunks of a preferred size, otherwise leave iterator unchanged.

  • iter – an iter which may also be readable

  • chunk_size – maximum size of chunk


Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation.


iter – an iterator to wrap


Wrap a file descriptor’s read with a partial function which schedules after each read. This can prevent eventlet thread starvation.


fd – a file descriptor to wrap

glance_store.common.utils.get_hasher(hash_algo, usedforsecurity=True)

Returns the required hasher, given the hashing algorithm. This is primarily to ensure that the hash algorithm is correctly chosen when executed on a FIPS enabled system

  • hash_algo – hash algorithm requested

  • usedforsecurity – whether the hashes are used in a security context


Returns validation of a value as a UUID.

For our purposes, a UUID is a canonical form string: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa