The apmec.common.utils Module

The apmec.common.utils Module

Utilities and helper functions.

apmec.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.

apmec.common.utils.deep_update(orig_dict, new_dict)
apmec.common.utils.deprecate_warning(what, as_of, in_favor_of=None, remove_in=1)
apmec.common.utils.dict2tuple(d)
apmec.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

apmec.common.utils.generate_resource_name(resource, prefix='tmpl')
apmec.common.utils.get_hostname()
apmec.common.utils.is_valid_ipv4(address)

Verify that address represents a valid IPv4 address.

apmec.common.utils.is_valid_vlan_tag(vlan)
apmec.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

apmec.common.utils.log_opt_values(log)
apmec.common.utils.subprocess_popen(args, stdin=None, stdout=None, stderr=None, shell=False, env=None)
apmec.common.utils.synchronized(name, external=False, lock_path=None, semaphores=None, delay=0.01)

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.