ironic_python_agent.disk_utils module

Various utilities related to disk handling.

Imported from ironic-lib’s disk_utils as of the following commit: https://opendev.org/openstack/ironic-lib/commit/42fa5d63861ba0f04b9a4f67212173d7013a1332

ironic_python_agent.disk_utils.block_uuid(dev)[source]

Get UUID of a block device.

Try to fetch the UUID, if that fails, try to fetch the PARTUUID.

ironic_python_agent.disk_utils.count_mbr_partitions(device)[source]

Count the number of primary and logical partitions on a MBR

Parameters:

device – The device path.

Returns:

A tuple with the number of primary partitions and logical partitions.

Raise:

ValueError if the device does not have a valid MBR partition table.

ironic_python_agent.disk_utils.dd(src, dst, conv_flags=None)[source]

Execute dd from src to dst.

ironic_python_agent.disk_utils.destroy_disk_metadata(dev, node_uuid)[source]

Destroy metadata structures on node’s disk.

Ensure that node’s disk magic strings are wiped without zeroing the entire drive. To do this we use the wipefs tool from util-linux.

Parameters:
  • dev – Path for the device to work on.

  • node_uuid – Node’s uuid. Used for logging.

ironic_python_agent.disk_utils.find_efi_partition(device)[source]

Looks for the EFI partition on a given device.

A boot partition on a GPT disk is assumed to be an EFI partition as well.

Parameters:

device – the name of the device

Returns:

the EFI partition record from list_partitions or None

ironic_python_agent.disk_utils.fix_gpt_partition(device, node_uuid)[source]

Fix GPT partition

Fix GPT table information when image is written to a disk which has a bigger extend (e.g. 30GB image written on a 60Gb physical disk).

Parameters:
  • device – The device path.

  • node_uuid – UUID of the Node.

Raises:

InstanceDeployFailure if exception is caught.

ironic_python_agent.disk_utils.get_and_validate_image_format(filename, ironic_disk_format)[source]

Get the format of a given image file and ensure it’s allowed.

This method uses the format inspector originally written for glance to safely detect the image format. It also sanity checks to ensure any specified format matches the provided one and that the format is in the allowed list of formats.

If the image format provided by Ironic is a type which doesn’t need conversion, we avoid all introspection of the image and use of qemu-img.

It also performs a basic safety check on the image.

This entire process can be bypassed, and the older code path used, by setting CONF.disable_deep_image_inspection to True.

See https://bugs.launchpad.net/ironic/+bug/2071740 for full details on why this must always happen.

Parameters:
  • filename – The name of the image file to validate.

  • ironic_disk_format – The ironic-provided expected format of the image

Returns:

tuple of validated img_format (str) and size (int)

ironic_python_agent.disk_utils.get_dev_byte_size(dev)[source]

Get the device size in bytes.

ironic_python_agent.disk_utils.get_dev_sector_size(dev)[source]

Get the device logical sector size in bytes.

ironic_python_agent.disk_utils.get_device_information(device, fields=None)[source]

Get information about a device using blkid.

Can be applied to all block devices: disks, RAID, partitions.

Parameters:
  • device – Device name.

  • fields – A list of fields to request (all by default).

Returns:

A dictionary with requested fields as keys.

Raises:

ProcessExecutionError

ironic_python_agent.disk_utils.get_disk_identifier(dev)[source]

Get the disk identifier from the disk being exposed by the ramdisk.

This disk identifier is appended to the pxe config which will then be used by chain.c32 to detect the correct disk to chainload. This is helpful in deployments to nodes with multiple disks.

http://www.syslinux.org/wiki/index.php/Comboot/chain.c32#mbr:

Parameters:

dev – Path for the already populated disk device.

Raises:

OSError – When the hexdump binary is unavailable.

Returns:

The Disk Identifier.

ironic_python_agent.disk_utils.get_partition_table_type(device)[source]

Get partition table type, msdos or gpt.

Parameters:

device – the name of the device

Returns:

dos, gpt or None

ironic_python_agent.disk_utils.is_block_device(dev)[source]

Check whether a device is block or not.

ironic_python_agent.disk_utils.is_last_char_digit(dev)[source]

check whether device name ends with a digit

ironic_python_agent.disk_utils.list_partitions(device)[source]

Get partitions information from given device.

Parameters:

device – The device path.

Returns:

list of dictionaries (one per partition) with keys: number, start, end, size (in MiB), filesystem, partition_name, flags, path.

ironic_python_agent.disk_utils.make_partitions(dev, root_mb, swap_mb, ephemeral_mb, configdrive_mb, node_uuid, commit=True, boot_option='netboot', boot_mode='bios', disk_label=None, cpu_arch='')[source]

Partition the disk device.

Create partitions for root, swap, ephemeral and configdrive on a disk device.

Parameters:
  • dev – Path for the device to work on.

  • root_mb – Size of the root partition in mebibytes (MiB).

  • swap_mb – Size of the swap partition in mebibytes (MiB). If 0, no partition will be created.

  • ephemeral_mb – Size of the ephemeral partition in mebibytes (MiB). If 0, no partition will be created.

  • configdrive_mb – Size of the configdrive partition in mebibytes (MiB). If 0, no partition will be created.

  • commit – True/False. Default for this setting is True. If False partitions will not be written to disk.

  • boot_option – Can be “local” or “netboot”. “netboot” by default.

  • boot_mode – Can be “bios” or “uefi”. “bios” by default.

  • node_uuid – Node’s uuid. Used for logging.

  • disk_label – The disk label to be used when creating the partition table. Valid values are: “msdos”, “gpt” or None; If None Ironic will figure it out according to the boot_mode parameter.

  • cpu_arch – Architecture of the node the disk device belongs to. When using the default value of None, no architecture specific steps will be taken. This default should be used for x86_64. When set to ppc64*, architecture specific steps are taken for booting a partition image locally.

Returns:

A dictionary containing the partition type as Key and partition path as Value for the partitions created by this method.

ironic_python_agent.disk_utils.partition_index_to_path(device, index)[source]

Guess a partition path based on its device and index.

Parameters:
  • device – Device path.

  • index – Partition index.

ironic_python_agent.disk_utils.partprobe(device, attempts=None)[source]

Probe partitions on the given device.

Parameters:
  • device – The block device containing partitions that is attempting to be updated.

  • attempts – Number of attempts to run partprobe, the default is read from the configuration.

Returns:

True on success, False otherwise.

ironic_python_agent.disk_utils.populate_image(src, dst, conv_flags=None, source_format=None, is_raw=False, sparse_size='0', out_format='raw', **convert_args)[source]

Populate a provided destination device with the image

Parameters:
  • src – An image already security checked in format disk_format

  • dst – A location, usually a partition or block device, to write the image

  • conv_flags – Conversion flags to pass to dd if provided

  • is_raw – Ironic indicates image is raw; do not convert!

  • sparse_size – Sparse size to pass to qemu_img

  • source_format – format of the image

  • out_format – Output format

  • convert_args – Additional arguments to optionally pass to qemu_img

ironic_python_agent.disk_utils.trigger_device_rescan(device, attempts=None)[source]

Sync and trigger device rescan.

Disk partition performed via parted, when performed on a ramdisk do not have to honor the fsync mechanism. In essence, fsync is used on the file representing the block device, which falls to the kernel filesystem layer to trigger a sync event. On a ramdisk using ramfs, this is an explicit non-operation.

As a result of this, we need to trigger a system wide sync operation which will trigger cache to flush to disk, after which partition changes should be visible upon re-scan.

When ramdisks are not in use, this also helps ensure that data has been safely flushed across the wire, such as on iscsi connections.

Parameters:
  • device – The block device containing partitions that is attempting to be updated.

  • attempts – Number of attempts to run partprobe, the default is read from the configuration.

Returns:

True on success, False otherwise.

ironic_python_agent.disk_utils.udev_settle()[source]

Wait for the udev event queue to settle.

Wait for the udev event queue to settle to make sure all devices are detected once the machine boots up.

Returns:

True on success, False otherwise.

ironic_python_agent.disk_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.