Utilities and helper functions.
ComparableMixin
¶Bases: object
DO_NOTHING
¶Class that literrally does nothing.
We inherit from str in case it’s called with json.dumps.
DoNothing
¶Bases: str
Class that literrally does nothing.
We inherit from str in case it’s called with json.dumps.
Semaphore
(limit)¶Bases: object
Custom semaphore to workaround eventlet issues with multiprocessing.
TraceWrapperMetaclass
¶Bases: type
Metaclass that wraps all methods of a class with trace_method.
This metaclass will cause every function inside of the class to be decorated with the trace_method decorator.
To use the metaclass you define a class like so: @six.add_metaclass(utils.TraceWrapperMetaclass) class MyClass(object):
TraceWrapperWithABCMetaclass
¶Bases: abc.ABCMeta
, cinder.utils.TraceWrapperMetaclass
Metaclass that wraps all methods of a class with trace.
as_int
(obj, quiet=True)¶brick_attach_volume_encryptor
(context, attach_info, encryption)¶Attach encryption layer.
brick_detach_volume_encryptor
(attach_info, encryption)¶Detach encryption layer.
brick_get_connector
(protocol, driver=None, use_multipath=False, device_scan_attempts=3, *args, **kwargs)¶Wrapper to get a brick connector object.
This automatically populates the required protocol as well as the root_helper needed to execute commands.
brick_get_connector_properties
(multipath=False, enforce_multipath=False)¶Wrapper to automatically set root_helper in brick calls.
Parameters: |
|
---|
brick_get_encryptor
(connection_info, *args, **kwargs)¶Wrapper to get a brick encryptor object.
build_or_str
(elements, str_format=None)¶Builds a string of elements joined by ‘or’.
Will join strings with the ‘or’ word and if a str_format is provided it will be used to format the resulted joined string. If there are no elements an empty string will be returned.
Parameters: |
|
---|
calculate_max_over_subscription_ratio
(capability, global_max_over_subscription_ratio)¶calculate_virtual_free_capacity
(total_capacity, free_capacity, provisioned_capacity, thin_provisioning_support, max_over_subscription_ratio, reserved_percentage, thin)¶Calculate the virtual free capacity based on thin provisioning support.
Parameters: |
|
---|---|
Returns: | the calculated virtual free capacity. |
check_exclusive_options
(**kwargs)¶Checks that only one of the provided options is actually not-none.
Iterates over all the kwargs passed in and checks that only one of said arguments is not-none, if more than one is not-none then an exception will be raised with the names of those arguments who were not-none.
check_metadata_properties
(metadata=None)¶Checks that the volume metadata properties are valid.
check_ssh_injection
(cmd_list)¶check_string_length
(value, name, min_length=0, max_length=None, allow_all_spaces=True)¶Check the length of specified string.
Parameters: |
|
---|
convert_str
(text)¶Convert to native string.
Convert bytes and Unicode strings to native strings:
create_ordereddict
(adict)¶Given a dict, return a sorted OrderedDict.
execute
(*cmd, **kwargs)¶Convenience wrapper around oslo’s execute() method.
get_blkdev_major_minor
(path, lookup_for_file=True)¶Get ‘major:minor’ number of block device.
Get the device’s ‘major:minor’ number of a block device to control I/O ratelimit of the specified path. If lookup_for_file is True and the path is a regular file, lookup a disk device which the file lies on and returns the result for the device.
get_bool_param
(param_string, params, default=False)¶get_file_gid
(path)¶This primarily exists to make unit testing easier.
get_file_mode
(path)¶This primarily exists to make unit testing easier.
get_file_size
(path)¶Returns the file size.
get_log_levels
(prefix)¶get_log_method
(level_string)¶get_root_helper
()¶if_notifications_enabled
(f)¶Calls decorated method only if notifications are enabled.
is_blk_device
(dev)¶last_completed_audit_period
(unit=None)¶This method gives you the most recently completed audit period.
limit_operations
(func)¶Decorator to limit the number of concurrent operations.
This method decorator expects to have a _semaphore attribute holding an initialized semaphore in the self instance object.
We can get the appropriate semaphore with the semaphore_factory method.
log_unsupported_driver_warning
(driver)¶Annoy the log about unsupported drivers.
make_dev_path
(dev, partition=None, base='/dev')¶Return a path to a particular device.
>>> make_dev_path('xvdc')
/dev/xvdc
>>> make_dev_path('xvdc', 1)
/dev/xvdc1
monkey_patch
()¶Patches decorators for all functions in a specified module.
If the CONF.monkey_patch set as True, this function patches a decorator for all functions in specified modules.
You can set decorators for each modules using CONF.monkey_patch_modules. The format is “Module path:Decorator function”. Example: ‘cinder.api.ec2.cloud:’ cinder.openstack.common.notifier.api.notify_decorator’
Parameters of the decorator are as follows. (See cinder.openstack.common.notifier.api.notify_decorator)
Parameters: |
|
---|
notifications_enabled
(conf)¶Check if oslo notifications are enabled.
paths_normcase_equal
(path_a, path_b)¶require_driver_initialized
(driver)¶Verifies if driver is initialized
If the driver is not initialized, an exception will be raised.
Params driver: | The driver instance. |
---|---|
Raises: | exception.DriverNotInitialized |
retry
(retry_param, interval=1, retries=3, backoff_rate=2, wait_random=False, retry=<class 'tenacity.retry.retry_if_exception_type'>)¶retry_if_exit_code
(codes)¶Bases: tenacity.retry.retry_if_exception
Retry on ProcessExecutionError specific exit codes.
robust_file_write
(directory, filename, data)¶Robust file write.
Use “write to temp file and rename” model for writing the persistence file.
Parameters: |
|
---|
semaphore_factory
(limit, concurrent_processes)¶Get a semaphore to limit concurrent operations.
The semaphore depends on the limit we want to set and the concurrent processes that need to be limited.
service_expired_time
(with_timezone=False)¶set_log_levels
(prefix, level_string)¶setup_tracing
(trace_flags)¶Set global variables for each trace flag.
Sets variables TRACE_METHOD and TRACE_API, which represent whether to log methods or api traces.
Parameters: | trace_flags – a list of strings |
---|
synchronized
(name, *, lock_file_prefix='cinder-', 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.
tempdir
(**kwargs)¶temporary_chown
(path, owner_uid=None)¶Temporarily chown a path.
Params owner_uid: | |
---|---|
UID of temporary owner (defaults to current user) |
trace
(*dec_args, **dec_kwargs)¶Trace calls to the decorated function.
This decorator should always be defined as the outermost decorator so it is defined last. This is important so it does not interfere with other decorators.
Using this decorator on a function will cause its execution to be logged at DEBUG level with arguments, return values, and exceptions.
Returns: | a function decorator |
---|
trace_api
(*dec_args, **dec_kwargs)¶Decorates a function if TRACE_API is true.
trace_method
(f)¶Decorates a function if TRACE_METHOD is true.
validate_dictionary_string_length
(specs)¶Check the length of each key and value of dictionary.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.