The ironic_lib.utils Module

Utilities and helper functions.

ironic_lib.utils.dd(src, dst, *args)[source]

Execute dd from src to dst.

Parameters
  • src – the input file for dd command.

  • dst – the output file for dd command.

  • args – a tuple containing the arguments to be passed to dd command.

Raises

processutils.ProcessExecutionError if it failed to run the process.

ironic_lib.utils.execute(*cmd, **kwargs)[source]

Convenience wrapper around oslo’s execute() method.

Executes and logs results from a system command. See docs for oslo_concurrency.processutils.execute for usage.

Parameters
  • cmd – positional arguments to pass to processutils.execute()

  • use_standard_locale – keyword-only argument. True | False. Defaults to False. If set to True, execute command with standard locale added to environment variables.

  • log_stdout – keyword-only argument. True | False. Defaults to True. If set to True, logs the output.

  • kwargs – keyword arguments to pass to processutils.execute()

Returns

(stdout, stderr) from process execution

Raises

UnknownArgumentError on receiving unknown arguments

Raises

ProcessExecutionError

Raises

OSError

ironic_lib.utils.find_devices_by_hints(devices, root_device_hints)[source]

Find all devices that match the root device hints.

Try to find devices that match the root device hints. In order for a device to be matched it needs to satisfy all the given hints.

Parameters
  • devices

    A list of dictionaries representing the devices

    containing one or more of the following keys:

    name

    (String) The device name, e.g /dev/sda

    size

    (Integer) Size of the device in bytes

    model

    (String) Device model

    vendor

    (String) Device vendor name

    serial

    (String) Device serial number

    wwn

    (String) Unique storage identifier

    wwn_with_extension

    (String): Unique storage identifier with the vendor extension appended

    wwn_vendor_extension

    (String): United vendor storage identifier

    rotational

    (Boolean) Whether it’s a rotational device or not. Useful to distinguish HDDs (rotational) and SSDs (not rotational).

    hctl

    (String): The SCSI address: Host, channel, target and lun. For example: ‘1:0:0:0’.

    by_path

    (String): The alternative device name, e.g. /dev/disk/by-path/pci-0000:00

  • root_device_hints – A dictionary with the root device hints.

Raises

ValueError, if some information is invalid.

Returns

A generator with all matching devices as dictionaries.

ironic_lib.utils.get_route_source(dest, ignore_link_local=True)[source]

Get the IP address to send packages to destination.

ironic_lib.utils.is_http_url(url)[source]
ironic_lib.utils.list_opts()[source]

Entry point for oslo-config-generator.

ironic_lib.utils.match_root_device_hints(devices, root_device_hints)[source]

Try to find a device that matches the root device hints.

Try to find a device that matches the root device hints. In order for a device to be matched it needs to satisfy all the given hints.

Parameters
  • devices

    A list of dictionaries representing the devices

    containing one or more of the following keys:

    name

    (String) The device name, e.g /dev/sda

    size

    (Integer) Size of the device in bytes

    model

    (String) Device model

    vendor

    (String) Device vendor name

    serial

    (String) Device serial number

    wwn

    (String) Unique storage identifier

    wwn_with_extension

    (String): Unique storage identifier with the vendor extension appended

    wwn_vendor_extension

    (String): United vendor storage identifier

    rotational

    (Boolean) Whether it’s a rotational device or not. Useful to distinguish HDDs (rotational) and SSDs (not rotational).

    hctl

    (String): The SCSI address: Host, channel, target and lun. For example: ‘1:0:0:0’.

    by_path

    (String): The alternative device name, e.g. /dev/disk/by-path/pci-0000:00

  • root_device_hints – A dictionary with the root device hints.

Raises

ValueError, if some information is invalid.

Returns

The first device to match all the hints or None.

ironic_lib.utils.mkfs(fs, path, label=None)[source]

Format a file or block device

Parameters
  • fs – Filesystem type (examples include ‘swap’, ‘ext3’, ‘ext4’ ‘btrfs’, etc.)

  • path – Path to file or block device to format

  • label – Volume label to use

ironic_lib.utils.parse_root_device_hints(root_device)[source]

Parse the root_device property of a node.

Parses and validates the root_device property of a node. These are hints for how a node’s root device is created. The ‘size’ hint should be a positive integer. The ‘rotational’ hint should be a Boolean value.

Parameters

root_device – the root_device dictionary from the node’s property.

Returns

a dictionary with the root device hints parsed or None if there are no hints.

Raises

ValueError, if some information is invalid.

ironic_lib.utils.wait_for_disk_to_become_available(device)[source]

Wait for a disk device to become available.

Waits for a disk device to become available for use by waiting until all process locks on the device have been released.

Timeout and iteration settings come from the configuration options used by the in-library disk_partitioner: check_device_interval and check_device_max_retries.

Params device

The path to the device.

Raises

IronicException If the disk fails to become available.