System-level utilities and helper functions.
glance.common.utils.
CooperativeReader
(fd)[source]¶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.
glance.common.utils.
LimitingReader
(data, limit, exception_class=<class 'glance.common.exception.ImageSizeLimitExceeded'>)[source]¶Bases: object
Reader designed to fail when reading image data past the configured allowable amount.
glance.common.utils.
chunkiter
(fp, chunk_size=65536)[source]¶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.common.utils.
chunkreadable
(iter, chunk_size=65536)[source]¶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
glance.common.utils.
cooperative_iter
(iter)[source]¶Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation.
iter – an iterator to wrap
glance.common.utils.
cooperative_read
(fd)[source]¶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.common.utils.
create_mashup_dict
(image_meta)[source]¶Returns a dictionary-like mashup of the image core properties and the image custom properties from given image metadata.
image_meta – metadata of image with core and custom properties
glance.common.utils.
evaluate_filter_op
(value, operator, threshold)[source]¶Evaluate a comparison operator. Designed for use on a comparative-filtering query field.
value – evaluated against the operator, as left side of expression
operator – any supported filter operation
threshold – to compare value against, as right side of expression
InvalidFilterOperatorValue – if an unknown operator is provided
boolean result of applied comparison
glance.common.utils.
get_image_meta_from_headers
(response)[source]¶Processes HTTP headers from a supplied response that match the x-image-meta and x-image-meta-property and returns a mapping of image metadata and properties
response – Response to process
glance.common.utils.
image_meta_to_http_headers
(image_meta)[source]¶Returns a set of image metadata into a dict of HTTP headers that can be fed to either a Webob Request object or an httplib.HTTP(S)Connection object
image_meta – Mapping of image metadata
glance.common.utils.
is_valid_hostname
(hostname)[source]¶Verify whether a hostname (not an FQDN) is valid.
glance.common.utils.
no_4byte_params
(f)[source]¶Checks that no 4 byte unicode characters are allowed in dicts’ keys/values and string’s parameters
glance.common.utils.
parse_valid_host_port
(host_port)[source]¶Given a “host:port” string, attempts to parse it as intelligently as possible to determine if it is valid. This includes IPv6 [host]:port form, IPv4 ip:port form, and hostname:port or fqdn:port form.
Invalid inputs will raise a ValueError, while valid inputs will return a (host, port) tuple where the port will always be of type int.
glance.common.utils.
split_filter_op
(expression)[source]¶Split operator from threshold in an expression. Designed for use on a comparative-filtering query field. When no operator is found, default to an equality comparison.
expression – the expression to parse
a tuple (operator, threshold) parsed from expression
glance.common.utils.
split_filter_value_for_quotes
(value)[source]¶Split filter values
Split values by commas and quotes for ‘in’ operator, according api-wg.
glance.common.utils.
stash_conf_values
()[source]¶Make a copy of some of the current global CONF’s settings. Allows determining if any of these values have changed when the config is reloaded.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.