ironic.common.images module¶
Handling of VM disk images.
- ironic.common.images.check_if_image_format_is_permitted(img_format, expected_format=None, node=None)[source]¶
Checks image format consistency.
- Params img_format:
The determined image format by name.
- Params expected_format:
Optional, the expected format based upon supplied configuration values.
- Params node:
A node object or None implying image cache.
- Raises:
InvalidImage if the requested image format is not permitted by configuration, or the expected_format does not match the determined format.
- ironic.common.images.converted_size(path, estimate=False)[source]¶
Get size of converted raw image.
The size of image converted to raw format can be growing up to the virtual size of the image.
- Parameters:
path – path to the image file.
estimate – Whether to estimate the size by scaling the original size
- Returns:
For estimate=False, return the size of the raw image file. For estimate=True, return the size of the original image scaled by the configuration value raw_image_growth_factor.
- ironic.common.images.create_boot_iso(context, output_filename, kernel_href, ramdisk_href, deploy_iso_href=None, esp_image_href=None, root_uuid=None, kernel_params=None, boot_mode=None, inject_files=None, publisher_id=None)[source]¶
Creates a bootable ISO image for a node.
Given the hrefs for kernel, ramdisk, root partition’s UUID and kernel cmdline arguments, this method fetches the kernel and ramdisk, and builds a bootable ISO image that can be used to boot up the baremetal node.
- Parameters:
context – context
output_filename – the absolute path of the output ISO file
kernel_href – URL or glance uuid of the kernel to use
ramdisk_href – URL or glance uuid of the ramdisk to use
deploy_iso_href – URL or glance UUID of the deploy ISO image to extract EFI system partition image. If not specified, the esp_image_href option must be present if UEFI-bootable ISO is desired.
esp_image_href – URL or glance UUID of FAT12/16/32-formatted EFI system partition image containing the EFI boot loader (e.g. GRUB2) for each hardware architecture to boot. This image will be written onto the ISO image. If not specified, the deploy_iso_href option is only required for building UEFI-bootable ISO.
kernel_params – a string containing whitespace separated values kernel cmdline arguments of the form K=V or K (optional).
inject_files – Mapping of local source file paths to their location on the final ISO image.
publisher_id – A value to set as the publisher identifier string in the ISO image to be generated.
- Boot_mode:
the boot mode in which the deploy is to happen.
- Raises:
ImageCreationFailed, if creating boot ISO failed.
- ironic.common.images.create_esp_image_for_uefi(output_file, kernel, ramdisk, deploy_iso=None, esp_image=None, kernel_params=None, inject_files=None, publisher_id=None)[source]¶
Creates an ESP image on the specified file.
Copies the provided kernel, ramdisk and EFI system partition image (ESP) to a directory, generates the grub configuration file using kernel parameters and then generates a bootable ISO image for UEFI.
- Parameters:
output_file – the path to the file where the iso image needs to be created.
kernel – the kernel to use.
ramdisk – the ramdisk to use.
deploy_iso – deploy ISO image to extract EFI system partition image from. If not specified, the esp_image option is required.
esp_image – FAT12/16/32-formatted EFI system partition image containing the EFI boot loader (e.g. GRUB2) for each hardware architecture to boot. This image will be embedded into the ISO image. If not specified, the deploy_iso option is required.
kernel_params – a list of strings(each element being a string like ‘K=V’ or ‘K’ or combination of them like ‘K1=V1,K2,…’) to be added as the kernel cmdline.
inject_files – Mapping of local source file paths to their location on the final ISO image.
publisher_id – A value to set as the publisher identifier string in the ISO image to be generated.
- Raises:
ImageCreationFailed, if image creation failed while copying files or while running command to generate iso.
- ironic.common.images.create_isolinux_image_for_bios(output_file, kernel, ramdisk, kernel_params=None, inject_files=None, publisher_id=None)[source]¶
Creates an isolinux image on the specified file.
Copies the provided kernel, ramdisk to a directory, generates the isolinux configuration file using the kernel parameters provided, and then generates a bootable ISO image.
- Parameters:
output_file – the path to the file where the iso image needs to be created.
kernel – the kernel to use.
ramdisk – the ramdisk to use.
kernel_params – a list of strings(each element being a string like ‘K=V’ or ‘K’ or combination of them like ‘K1=V1,K2,…’) to be added as the kernel cmdline.
inject_files – Mapping of local source file paths to their location on the final ISO image.
publisher_id – A value to set as the publisher identifier string in the ISO image to be generated.
- Raises:
ImageCreationFailed, if image creation failed while copying files or while running command to generate iso.
- ironic.common.images.create_vfat_image(output_file, files_info=None, parameters=None, parameters_file='parameters.txt', fs_size_kib=100)[source]¶
Creates the fat fs image on the desired file.
This method copies the given files to a root directory (optional), writes the parameters specified to the parameters file within the root directory (optional), and then creates a vfat image of the root directory.
- Parameters:
output_file – The path to the file where the fat fs image needs to be created.
files_info –
A dict containing absolute path of file to be copied -> relative path within the vfat image. For example:
{ '/absolute/path/to/file' -> 'relative/path/within/root' ... }
parameters – A dict containing key-value pairs of parameters.
parameters_file – The filename for the parameters file.
fs_size_kib – size of the vfat filesystem in KiB.
- Raises:
ImageCreationFailed, if image creation failed while doing any of filesystem manipulation activities like creating dirs, mounting, creating filesystem, copying files, etc.
- ironic.common.images.fetch(context, image_href, path, force_raw=False, checksum=None, checksum_algo=None)[source]¶
- ironic.common.images.get_image_properties(context, image_href, properties='all')[source]¶
Returns the values of several properties of an image
- Parameters:
context – context
image_href – href of the image
properties – the properties whose values are required. This argument is optional, default value is “all”, so if not specified all properties will be returned.
- Returns:
a dict of the values of the properties. A property not on the glance metadata will have a value of None.
- ironic.common.images.get_temp_url_for_glance_image(context, image_uuid)[source]¶
Returns the tmp url for a glance image.
- Parameters:
context – context
image_uuid – the UUID of the image in glance
- Returns:
the tmp url for the glance image.
- ironic.common.images.is_source_a_path(ctx, image_source)[source]¶
Determine if the image source is a path.
This method determines if a supplied URL is a path.
- Parameters:
ctx – an admin/process context.
image_source – The supplied image source, expected to be a URL, which can be used to attempt to determine if the source is a path.
- Returns:
True if the image_source appears to be a path as opposed to an image to be downloaded. If the image source is not a path, False is returned. If any error is detected, None is returned.
- ironic.common.images.is_whole_disk_image(ctx, instance_info)[source]¶
Find out if the image is a partition image or a whole disk image.
- Parameters:
ctx – an admin context
instance_info – a node’s instance info dict
- Returns:
True for whole disk images and False for partition images and None on no image_source, the source being a path, or upon an Error.
- ironic.common.images.safety_check_image(image_path, node=None)[source]¶
Performs a safety check on the supplied image.
This method triggers the image format inspector’s to both identify the type of the supplied file and safety check logic to identify if there are any known unsafe features being leveraged, and return the detected file format in the form of a string for the caller.
- Parameters:
image_path – A fully qualified path to an image which needs to be evaluated for safety.
node – A Node object, optional. When supplied logging indicates the node which triggered this issue, but the node is not available in all invocation cases.
- Returns:
a string representing the the image type which is used.
- Raises:
InvalidImage when the supplied image is detected as unsafe, or the image format inspector has failed to parse the supplied image’s contents.