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
Parameters: |
|
---|
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.
Parameters: |
|
---|
glance.common.utils.
cooperative_iter
(iter)[source]¶Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation.
Parameters: | 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.
Parameters: | 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.
Parameters: | 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.
Parameters: |
|
---|---|
Raises: | InvalidFilterOperatorValue – if an unknown operator is provided |
Returns: | 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
Parameters: | 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
Parameters: | 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.
Parameters: | expression – the expression to parse |
---|---|
Returns: | 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.