The cinder.utils Module

Utilities and helper functions.

class ProtectedExpatParser(forbid_dtd=True, forbid_entities=True, *args, **kwargs)

Bases: xml.sax.expatreader.ExpatParser

An expat parser which disables DTD’s and entities by default.

entity_decl(entityName, is_parameter_entity, value, base, systemId, publicId, notationName)
reset()
start_doctype_decl(name, sysid, pubid, has_internal_subset)
unparsed_entity_decl(name, base, sysid, pubid, notation_name)
add_visible_admin_metadata(volume)

Add user-visible admin metadata to regular metadata.

Extracts the admin metadata keys that are to be made visible to non-administrators, and adds them to the regular metadata structure for the passed-in volume.

as_int(obj, quiet=True)
brick_get_connector(protocol, driver=None, execute=<function execute at 0x2af0d33e8668>, 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 for the brick calls to automatically set the root_helper needed for cinder.

Parameters:
  • multipath – A boolean indicating whether the connector can support multipath.
  • enforce_multipath – If True, it raises exception when multipath=True is specified but multipathd is not running. If False, it falls back to multipath=False when multipathd is not running.
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_ssh_injection(cmd_list)
check_string_length(value, name, min_length=0, max_length=None)

Check the length of specified string :param value: the value of the string :param name: the name of the string :param min_length: the min_length of the string :param max_length: the max_length of the string

cinderdir()
convert_version_to_int(version)
convert_version_to_str(version_int)
convert_version_to_tuple(version_str)
create_channel(client, width, height)

Invoke an interactive shell session on server.

execute(*cmd, **kwargs)

Convenience wrapper around oslo’s execute() method.

find_config(config_path)

Find a configuration file using the given hint.

Parameters:config_path – Full or relative path to the config.
Returns:Full path of the config, if it exists.
Raises:cinder.exception.ConfigNotFound
generate_glance_url()

Generate the URL to glance.

get_blkdev_major_minor(path, lookup_for_file=True)

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_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_from_path(items, path)

Returns a list of items matching the specified path.

Takes an XPath-like expression e.g. prop1/prop2/prop3, and for each item in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the intermediate results are lists it will treat each list item individually. A ‘None’ in items or any child expressions will be ignored, this function will not throw because of None (anywhere) in items. The returned list will contain no None values.

get_root_helper()
hash_file(file_like_object)

Generate a hash for the contents of a file.

is_blk_device(dev)
is_int_like(val)

Check if a value looks like an int.

is_none_string(val)

Check if a string represents a None value.

is_valid_boolstr(val)

Check if the provided string is a valid bool string or not.

last_completed_audit_period(unit=None)

This method gives you the most recently completed audit period.

arguments:
units: string, one of ‘hour’, ‘day’, ‘month’, ‘year’
Periods normally begin at the beginning (UTC) of the period unit (So a ‘day’ period begins at midnight UTC, a ‘month’ unit on the 1st, a ‘year’ on Jan, 1) unit string may be appended with an optional offset like so: 'day@18‘ This will begin the period at 18:00 UTC. 'month@15‘ starts a monthly period on the 15th, and year@3 begins a yearly one on March 1st.
returns: 2 tuple of datetimes (begin, end)
The begin timestamp of this audit period is the same as the end of the previous.
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()

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 is as follows. (See cinder.openstack.common.notifier.api.notify_decorator)

name - name of the function function - object of the function

read_file_as_root(file_path)

Secure helper to read file as root.

remove_invalid_filter_options(context, filters, allowed_search_options)

Remove search options that are not valid for non-admin API/context.

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(exceptions, interval=1, retries=3, backoff_rate=2)
safe_minidom_parse_string(xml_string)

Parse an XML string using minidom safely.

sanitize_hostname(hostname)

Return a hostname which conforms to RFC-952 and RFC-1123 specs.

service_is_up(service)

Check whether a service is up based on last heartbeat.

tempdir(*args, **kwds)
temporary_chown(*args, **kwds)

Temporarily chown a path.

Params owner_uid:
 UID of temporary owner (defaults to current user)
walk_class_hierarchy(clazz, encountered=None)

Walk class hierarchy, yielding most derived classes first.

xhtml_escape(value)

Escapes a string so it is valid within XML or XHTML.

Previous topic

The cinder.transfer.api Module

Next topic

The cinder.version Module

This Page