tacker.common.utils module

tacker.common.utils module

Utilities and helper functions.

tacker.common.utils.change_memory_unit(mem, to)

Changes 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.deep_update(orig_dict, new_dict)
tacker.common.utils.dict2tuple(d)
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.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.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.