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