Utilities and helper functions.
Bases: object
Class to wrap another and translate the ClientExceptions raised by its function calls to the actual ones.
Bases: nova.utils.RootwrapProcessHelper
Bases: object
Provides a mechanism to facilitate rolling back a series of actions when an exception is raised.
Rollback a series of actions then re-raise the exception.
Note
(sirp) This should only be called within an exception handler.
Checks that obj is of type cls, and lets PyLint infer types.
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
Delete cached file if present.
Parameters: | filename – filename to delete |
---|
Convenience wrapper around oslo’s execute() method.
Get all metadata for a list of resources after filtering.
Search_filts is a list of dictionaries, where the values in the dictionary can be string or regex string, or a list of strings/regex strings.
Let’s call a dict a ‘filter block’ and an item in the dict a ‘filter’. A tag is returned if it matches ALL the filters in a filter block. If more than one values are specified for a filter, a tag is returned if it matches ATLEAST ONE value of the filter. If more than one filter blocks are specified, the tag should match ALL the filter blocks.
For example:
- search_filts = [{‘key’: [‘key1’, ‘key2’], ‘value’: ‘val1’},
- {‘value’: ‘val2’}]
This example filter will never match a tag.
param resource_type: The resource type as a string, e.g. ‘instance’ param resource_list: List of resource objects param search_filts: Filters to filter metadata to be returned. Can be dict (e.g. {‘key’: ‘env’, ‘value’: ‘prod’}, or a list of dicts (e.g. [{‘key’: ‘env’}, {‘value’: ‘beta’}]. Note that the values of the dict can be regular expressions. param metadata_type: Provided to search for a specific metadata type (e.g. ‘system_metadata’) returns: List of dicts where each dict is of the form {‘key’: ‘somekey’, ‘value’: ‘somevalue’, ‘instance_id’: ‘some-instance-uuid-aaa’} if resource_type is ‘instance’.
Returns remote path in format acceptable for scp/rsync.
If host is IPv6 address literal, return ‘[host]:path’, otherwise ‘host:path’ is returned.
If host is None, only path is returned.
Generate an Ethernet MAC address.
Generate a random password from the supplied symbol groups.
At least one symbol from each group will be included. Unpredictable results if length is less than the number of symbol groups.
Believed to be reasonably secure (with a reasonable password length!)
Returns string that represents MD5 hash of base_str (in hex format).
If base_str is a Unicode string, encode it to UTF-8.
Returns the IP version of a network (IPv4 or IPv6).
Raises AddrFormatError if invalid network.
Check if a string represents a None value.
Check if address is valid
The provided address can be a IPv6 or a IPv4 CIDR address.
Current time as ISO string, as timeutils.isotime() is deprecated
Returns: | Current time in ISO format |
---|
Return num bytes from the end of the file, and remaining byte count.
Parameters: |
|
---|
:returns (data, remaining)
This method gives you the most recently completed audit period.
Return a path to a particular device.
>>> make_dev_path('xvdc')
/dev/xvdc
>>> make_dev_path('xvdc', 1)
/dev/xvdc1
Format a file or block device
Parameters: |
|
---|
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: ‘nova.api.ec2.cloud:nova.notifications.notify_decorator’
Parameters of the decorator is as follows. (See nova.notifications.notify_decorator)
name - name of the function function - object of the function
Parses the given server_string and returns a tuple of host and port. If it’s not a combination of host part and port, the port element is an empty string. If the input is invalid expression, return a tuple of two empty strings.
Read from a file if it has been modified.
Parameters: | force_reload – Whether to reload the file. |
---|---|
Returns: | A tuple with a boolean specifying if the data is fresh or not. |
Secure helper to read file as root.
Transform ip string to “safe” format.
Will return ipv4 addresses unchanged, but will nest ipv6 addresses inside square brackets.
Safely truncates unicode strings such that their encoded length is no greater than the length provided.
Return a hostname which conforms to RFC-952 and RFC-1123 specs except the length of hostname.
Window, Linux, and Dnsmasq has different limitation:
Windows: 255 (net_bios limits to 15, but window will truncate it) Linux: 64 Dnsmasq: 63
Due to nova-network will leverage dnsmasq to set hostname, so we chose 63.
Passthrough method for eventlet.spawn.
This utility exists so that it can be stubbed for testing without interfering with the service spawns.
It will also grab the context from the threadlocal store and add it to the store on the new thread. This allows for continuity in logging the context when using this method to spawn a new thread.
Passthrough method for eventlet.spawn_n.
This utility exists so that it can be stubbed for testing without interfering with the service spawns.
It will also grab the context from the threadlocal store and add it to the store on the new thread. This allows for continuity in logging the context when using this method to spawn a new thread.
Convenience wrapper to execute ssh command.
Temporarily chown a path.
Parameters: | owner_uid – UID of temporary owner (defaults to current user) |
---|
Temporarily set the attr on a particular object to a given value then revert when finished.
One use of this is to temporarily set the read_deleted flag on a context object:
- with temporary_mutation(context, read_deleted=”yes”):
- do_something_that_needed_deleted_objects()
Convenience wrapper around oslo’s trycmd() method.
Try to turn a string into utf-8 if possible.
The original code was copied from the utf8 function in http://github.com/facebook/tornado/blob/master/tornado/escape.py
Make sure that value is a valid integer, potentially within range.
Sends a vpn negotiation packet and returns the server session.
Returns Boolean indicating whether the vpn_server is listening. Basic packet structure is below.
Client packet (14 bytes):
0 1 8 9 13
+-+--------+-----+
|x| cli_id |?????|
+-+--------+-----+
x = packet identifier 0x38
cli_id = 64 bit identifier
? = unknown, probably flags/padding
Server packet (26 bytes):
0 1 8 9 13 14 21 2225
+-+--------+-----+--------+----+
|x| srv_id |?????| cli_id |????|
+-+--------+-----+--------+----+
x = packet identifier 0x40
cli_id = 64 bit identifier
? = unknown, probably flags/padding
bit 9 was 1 and the rest were 0 in testing
Walk class hierarchy, yielding most derived classes first.
The workarounds_opts group is for very specific reasons.
If you’re:
- Working around an issue in a system tool (e.g. libvirt or qemu) where the fix is in flight/discussed in that community.
- The tool can be/is fixed in some distributions and rather than patch the code those distributions can trivially set a config option to get the “correct” behavior.
Then this is a good place for your workaround.
Warning
Please use with care! Document the BugID that your workaround is paired with.
Escapes a string so it is valid within XML or XHTML.