The ironic_lib.disk_utils
Module¶
-
ironic_lib.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_lib.disk_utils.
convert_image
(source, dest, out_format, run_as_root=False)[source]¶ Convert image to other format.
-
ironic_lib.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_lib.disk_utils.
create_config_drive_partition
(node_uuid, device, configdrive)[source]¶ Create a partition for config drive
Checks if the device is GPT or MBR partitioned and creates config drive partition accordingly.
- Parameters
node_uuid – UUID of the Node.
device – The device path.
configdrive – Base64 encoded Gzipped configdrive content or configdrive HTTP URL.
- Raises
InstanceDeployFailure if config drive size exceeds maximum limit or if it fails to create config drive.
-
ironic_lib.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_lib.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_lib.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_lib.disk_utils.
get_image_mb
(image_path, virtual_size=True)[source]¶ Get size of an image in Megabyte.
-
ironic_lib.disk_utils.
get_uefi_disk_identifier
(dev)[source]¶ Get the uuid from the disk being exposed by the ramdisk.
This uuid is appended to the pxe config which will then be set as the root and load the bootx64.efi file using chainloader and boot the machine. This is helpful in deployments to nodes with multiple disks.
https://wiki.gentoo.org/wiki/GRUB2/Chainloading
- Parameters
dev – Path for the already populated disk device.
- Raises
InstanceDeployFailure – Image is not UEFI bootable.
- Returns
The UUID of the partition.
-
ironic_lib.disk_utils.
is_iscsi_device
(dev, node_uuid)[source]¶ check whether the device path belongs to an iscsi device.
-
ironic_lib.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
-
ironic_lib.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_lib.disk_utils.
qemu_img_info
(path)[source]¶ Return an object containing the parsed output from qemu-img info.
-
ironic_lib.disk_utils.
work_on_disk
(dev, root_mb, swap_mb, ephemeral_mb, ephemeral_format, image_path, node_uuid, preserve_ephemeral=False, configdrive=None, boot_option='netboot', boot_mode='bios', tempdir=None, disk_label=None, cpu_arch='', conv_flags=None)[source]¶ Create partitions and copy an image to the root partition.
- Parameters
dev – Path for the device to work on.
root_mb – Size of the root partition in megabytes.
swap_mb – Size of the swap partition in megabytes.
ephemeral_mb – Size of the ephemeral partition in megabytes. If 0, no ephemeral partition will be created.
ephemeral_format – The type of file system to format the ephemeral partition.
image_path – Path for the instance’s disk image. If
None
, the root partition is prepared but not populated.node_uuid – node’s uuid. Used for logging.
preserve_ephemeral – If True, no filesystem is written to the ephemeral block device, preserving whatever content it had (if the partition table has not changed).
configdrive – Optional. Base64 encoded Gzipped configdrive content or configdrive HTTP URL.
boot_option – Can be “local” or “netboot”. “netboot” by default.
boot_mode – Can be “bios” or “uefi”. “bios” by default.
tempdir – A temporary directory
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.
conv_flags – Flags that need to be sent to the dd command, to control the conversion of the original file when copying to the host. It can contain several options separated by commas.
- Returns
a dictionary containing the following keys: ‘root uuid’: UUID of root partition ‘efi system partition uuid’: UUID of the uefi system partition (if boot mode is uefi). partitions: mapping of partition types to their device paths. NOTE: If key exists but value is None, it means partition doesn’t exist.