Utilities and helper functions.
tacker.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 requested amount of bytes.
Fetching the next chunk of the underlying iterator when needed. This is replaced with cooperative_read in __init__ if the underlying fd already supports read().
tacker.common.utils.
LimitingReader
(data, limit, exception_class=<class 'tacker.common.exceptions.CSARFileSizeLimitExceeded'>)¶Bases: object
Limit Reader to read data past to configured allowed amount.
Reader designed to fail when reading image data past the configured allowable amount.
read
(i)¶tacker.common.utils.
change_memory_unit
(mem, to)¶Change the memory value(mem) based on the unit(‘to’) specified.
If the unit is not specified in ‘mem’, by default, it is considered as “MB”. And this method returns only integer.
tacker.common.utils.
chunkiter
(fp, chunk_size=65536)¶Convert iterator to a file-like object.
Return an iterator to a file-like obj which yields fixed size chunks
Parameters: |
|
---|
tacker.common.utils.
chunkreadable
(iter, chunk_size=65536)¶Wrap a readable iterator.
Wrap a readable iterator with a reader yielding chunks of a preferred size, otherwise leave iterator unchanged.
Parameters: |
|
---|
tacker.common.utils.
cooperative_iter
(iter)¶Prevent eventlet thread starvation during iteration
Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation.
Parameters: | iter – an iterator to wrap |
---|
tacker.common.utils.
cooperative_read
(fd)¶Prevent eventlet thread starvationafter each read operation.
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 |
---|
tacker.common.utils.
deep_update
(orig_dict, new_dict)¶tacker.common.utils.
dict2tuple
(d)¶tacker.common.utils.
expects_func_args
(*args)¶tacker.common.utils.
find_config_file
(options, config_file)¶Return the first config file found.
We search for the paste config file in the following order: * If –config-file option is used, use that * Search for the configuration files via common cfg directories :retval Full path to config file, or None if no config file found
tacker.common.utils.
generate_resource_name
(resource, prefix='tmpl')¶tacker.common.utils.
get_auth_url_v3
(auth_url)¶tacker.common.utils.
get_hostname
()¶tacker.common.utils.
is_valid_ipv4
(address)¶Verify that address represents a valid IPv4 address.
tacker.common.utils.
is_valid_vlan_tag
(vlan)¶tacker.common.utils.
load_class_by_alias_or_classname
(namespace, name)¶Load class using stevedore alias or the class name.
Load class using the stevedore driver manager :param namespace: namespace where the alias is defined :param name: alias or class name of the class to be loaded :returns: class if calls can be loaded :raises ImportError: if class cannot be loaded
tacker.common.utils.
log_opt_values
(log)¶tacker.common.utils.
none_from_string
(orig_str)¶tacker.common.utils.
subprocess_popen
(args, stdin=None, stdout=None, stderr=None, shell=False, env=None)¶tacker.common.utils.
synchronized
(name, external=False, lock_path=None, semaphores=None, delay=0.01, fair=False)¶Synchronization decorator.
Decorating a method like so:
@synchronized('mylock')
def foo(self, *args):
...
ensures that only one thread will execute the foo method at a time.
Different methods can share the same lock:
@synchronized('mylock')
def foo(self, *args):
...
@synchronized('mylock')
def bar(self, *args):
...
This way only one of either foo or bar can be executing at a time.
Changed in version 0.3: Added delay and semaphores optional parameter.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.