Utilities and helper functions.
ironic.common.utils.
check_dir
(directory_to_check=None, required_space=1)[source]¶Check a directory is usable.
This function can be used by drivers to check that directories they need to write to are usable. This should be called from the drivers init function. This function checks that the directory exists and then calls check_dir_writable and check_dir_free_space. If directory_to_check is not provided the default is to use the temp directory.
directory_to_check – the directory to check.
required_space – amount of space to check for in MiB.
PathNotFound if directory can not be found
DirectoryNotWritable if user is unable to write to the directory
InsufficientDiskSpace – if free space is < required space
ironic.common.utils.
execute
(*cmd, **kwargs)[source]¶Convenience wrapper around oslo’s execute() method.
cmd – Passed to processutils.execute.
use_standard_locale – True | False. Defaults to False. If set to True, execute command with standard locale added to environment variables.
(stdout, stderr) from process execution
UnknownArgumentError
ProcessExecutionError
ironic.common.utils.
file_has_content
(path, content, hash_algo='sha256')[source]¶Checks that content of the file is the same as provided reference.
path – path to file
content – reference content to check against
hash_algo – hashing algo from hashlib to use, default is ‘sha256’
True if the hash of reference content is the same as the hash of file’s content, False otherwise
ironic.common.utils.
get_updated_capabilities
(current_capabilities, new_capabilities)[source]¶Returns an updated capability string.
This method updates the original (or current) capabilities with the new capabilities. The original capabilities would typically be from a node’s properties[‘capabilities’]. From new_capabilities, any new capabilities are added, and existing capabilities may have their values updated. This updated capabilities string is returned.
current_capabilities – Current capability string
new_capabilities – the dictionary of capabilities to be updated.
An updated capability string. with new_capabilities.
ValueError, if current_capabilities is malformed or if new_capabilities is not a dictionary
ironic.common.utils.
is_hostname_safe
(hostname)[source]¶Old check for valid logical node names.
Retained for compatibility with REST API < 1.10.
In practice, this check has several shortcomings and errors that are more thoroughly documented in bug #1468508.
hostname – The hostname to be validated.
True if valid. False if not.
ironic.common.utils.
is_memory_insufficent
(raise_if_fail=False)[source]¶Checks available system memory and holds the deployment process.
Evaluates the current system memory available, meaning can be allocated to a process by the kernel upon allocation request, and delays the execution until memory has been freed, or until it has timed out.
This method will issue a sleep, if the amount of available memory is
insufficent. This is configured using the
[DEFAULT]minimum_memory_wait_time
and the
[DEFAULT]minimum_memory_wait_retries
.
raise_if_fail – Default False, but if set to true an InsufficentMemory exception is raised upon insufficent memory.
True if the check has timed out. Otherwise None is returned.
InsufficentMemory if the raise_if_fail parameter is set to True.
ironic.common.utils.
is_valid_datapath_id
(datapath_id)[source]¶Verify the format of an OpenFlow datapath_id.
Check if a datapath_id is valid and contains 16 hexadecimal digits. Datapath ID format: the lower 48-bits are for a MAC address, while the upper 16-bits are implementer-defined.
datapath_id – OpenFlow datapath_id to be validated.
True if valid. False if not.
ironic.common.utils.
is_valid_logical_name
(hostname)[source]¶Determine if a logical name is valid.
The logical name may only consist of RFC3986 unreserved characters, to wit:
ALPHA / DIGIT / “-” / “.” / “_” / “~”
ironic.common.utils.
is_valid_no_proxy
(no_proxy)[source]¶Check no_proxy validity
Check if no_proxy value that will be written to environment variable by ironic-python-agent is valid.
no_proxy – the value that requires validity check. Expected to be a comma-separated list of host names, IP addresses and domain names (with optional :port).
True if no_proxy is valid, False otherwise.
ironic.common.utils.
mount
(src, dest, *args)[source]¶Mounts a device/image file on specified location.
src – the path to the source file for mounting
dest – the path where it needs to be mounted.
args – a tuple containing the arguments to be passed to mount command.
processutils.ProcessExecutionError if it failed to run the process.
ironic.common.utils.
parse_instance_info_capabilities
(node)[source]¶Parse the instance_info capabilities.
One way of having these capabilities set is via Nova, where the capabilities are defined in the Flavor extra_spec and passed to Ironic by the Nova Ironic driver.
NOTE: Although our API fully supports JSON fields, to maintain the backward compatibility with Juno the Nova Ironic driver is sending it as a string.
node – a single Node.
InvalidParameterValue if the capabilities string is not a dictionary or is malformed.
A dictionary with the capabilities if found, otherwise an empty dictionary.
ironic.common.utils.
pop_node_nested_field
(node, collection, field, default=None)[source]¶Pop a value from a dictionary field of a node.
node – Node object.
collection – Name of the field with the dictionary.
field – Nested field name.
default – The default value to return.
The removed value or the default.
ironic.common.utils.
render_template
(template, params, is_file=True)[source]¶Renders Jinja2 template file with given parameters.
template – full path to the Jinja2 template file
params – dictionary with parameters to use when rendering
is_file – whether template is file or string with template itself
the rendered template as a string
ironic.common.utils.
safe_rstrip
(value, chars=None)[source]¶Removes trailing characters from a string if that does not make it empty
value – A string value that will be stripped.
chars – Characters to remove.
Stripped value.
ironic.common.utils.
set_node_nested_field
(node, collection, field, value)[source]¶Set a value in a dictionary field of a node.
node – Node object.
collection – Name of the field with the dictionary.
field – Nested field name.
value – New value.
ironic.common.utils.
umount
(loc, *args)[source]¶Umounts a mounted location.
loc – the path to be unmounted.
args – a tuple containing the arguments to be passed to the umount command.
processutils.ProcessExecutionError if it failed to run the process.
ironic.common.utils.
validate_and_normalize_datapath_id
(datapath_id)[source]¶Validate an OpenFlow datapath_id and return normalized form.
Checks whether the supplied OpenFlow datapath_id is formally correct and normalize it to all lower case.
datapath_id – OpenFlow datapath_id to be validated and normalized.
Normalized and validated OpenFlow datapath_id.
InvalidDatapathID If an OpenFlow datapath_id is not valid.
ironic.common.utils.
validate_and_normalize_mac
(address)[source]¶Validate a MAC address and return normalized form.
Checks whether the supplied MAC address is formally correct and normalize it to all lower case.
address – MAC address to be validated and normalized.
Normalized and validated MAC address.
InvalidMAC If the MAC address is not valid.
ironic.common.utils.
validate_network_port
(port, port_name='Port')[source]¶Validates the given port.
port – TCP/UDP port.
port_name – Name of the port.
An integer port number.
InvalidParameterValue, if the port is invalid.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.