libcloud.utils.misc module

class libcloud.utils.misc.ReprMixin[source]

Bases: object

Mixin class which adds __repr__ and __str__ methods for the attributes specified on the class.

libcloud.utils.misc.dict2str(data)[source]

Create a string with a whitespace and newline delimited text from a dictionary.

For example, this: {‘cpu’: ‘1100’, ‘ram’: ‘640’, ‘smp’: ‘auto’}

becomes: cpu 1100 ram 640 smp auto

cpu 2200 ram 1024

libcloud.utils.misc.find(value, predicate)[source]
libcloud.utils.misc.get_driver(drivers, provider, deprecated_providers=None, deprecated_constants=None)[source]

Get a driver.

Parameters:
  • drivers (dict) – Dictionary containing valid providers.

  • provider (libcloud.types.Provider) – Id (constant) of provider to get the driver for.

Param:

deprecated_providers: Dictionary with information about the deprecated drivers.

Param:

deprecated_constants: Dictionary with information about the deprecated provider constants.

libcloud.utils.misc.get_new_obj(obj, klass, attributes)[source]

Pass attributes from the existing object ‘obj’ and attributes dictionary to a ‘klass’ constructor. Attributes from ‘attributes’ dictionary are only passed to the constructor if they are not None.

libcloud.utils.misc.get_secure_random_string(size)[source]

Return a string of size random bytes. Returned string is suitable for cryptographic use.

Parameters:

size (int) – Size of the generated string.

Returns:

Random string.

Return type:

str

libcloud.utils.misc.lowercase_keys(dictionary)[source]
libcloud.utils.misc.merge_valid_keys(params, valid_keys, extra)[source]

Merge valid keys from extra into params dictionary and return dictionary with keys which have been merged.

Note: params is modified in place.

libcloud.utils.misc.reverse_dict(dictionary)[source]
libcloud.utils.misc.set_driver(drivers, provider, module, klass)[source]

Sets a driver.

Parameters:
  • drivers – Dictionary to store providers.

  • provider (libcloud.types.Provider) – Id of provider to set driver for

  • module (L) – The module which contains the driver

  • klass – The driver class name

libcloud.utils.misc.str2dicts(data)[source]

Create a list of dictionaries from a whitespace and newline delimited text.

For example, this: cpu 1100 ram 640

cpu 2200 ram 1024

becomes: [{‘cpu’: ‘1100’, ‘ram’: ‘640’}, {‘cpu’: ‘2200’, ‘ram’: ‘1024’}]