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.

read(length=None)

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

Parameters
  • 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.

Parameters
  • iter – an iter which may also be readable

  • chunk_size – maximum size of chunk

glance_store.common.utils.cooperative_iter(iter)

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

Parameters

iter – an iterator to wrap

glance_store.common.utils.cooperative_read(fd)

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

Parameters

fd – a file descriptor to wrap

glance_store.common.utils.is_uuid_like(val)

Returns validation of a value as a UUID.

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