The nova.virt.disk.api Module

Utility methods to resize, repartition, and modify disk images.

Includes injection of SSH PGP keys into authorized_keys file.

can_resize_image(image, size)

Check whether we can resize the container image file. :param image: path to local image file :param size: the image size in bytes

clean_lxc_namespace(container_dir)

Clean up the container namespace rootfs mounting one spawned.

It will umount the mounted names that are mounted but leave the linked devices alone.

extend(image, size)

Increase image to size.

Parameters:
  • image – instance of nova.virt.image.model.Image
  • size – image size in bytes
get_disk_size(path)

Get the (virtual) size of a disk image

Parameters:path – Path to the disk image
Returns:Size (in bytes) of the given disk image as it would be seen by a virtual machine.
get_file_extension_for_os_type(os_type, specified_fs=None)
get_fs_type_for_os_type(os_type)
inject_data(image, key=None, net=None, metadata=None, admin_password=None, files=None, partition=None, mandatory=())

Inject the specified items into a disk image.

Parameters:
  • image – instance of nova.virt.image.model.Image
  • key – the SSH public key to inject
  • net – the network configuration to inject
  • metadata – the user metadata to inject
  • admin_password – the root password to set
  • files – the files to copy into the image
  • partition – the partition number to access
  • mandatory – the list of parameters which must not fail to inject

If an item name is not specified in the MANDATORY iterable, then a warning is logged on failure to inject that item, rather than raising an exception.

it will mount the image as a fully partitioned disk and attempt to inject into the specified partition number.

If PARTITION is not specified the image is mounted as a single partition.

Returns True if all requested operations completed without issue. Raises an exception if a mandatory item can’t be injected.

inject_data_into_fs(fs, key, net, metadata, admin_password, files, mandatory=())

Injects data into a filesystem already mounted by the caller. Virt connections can call this directly if they mount their fs in a different way to inject_data.

If an item name is not specified in the MANDATORY iterable, then a warning is logged on failure to inject that item, rather than raising an exception.

Returns True if all requested operations completed without issue. Raises an exception if a mandatory item can’t be injected.

is_image_extendable(image)

Check whether we can extend the image.

mkfs(os_type, fs_label, target, run_as_root=True, specified_fs=None)

Format a file or block device using a user provided command for each os type. If user has not provided any configuration, format type will be used according to a default_ephemeral_format configuration or a system defaults.

resize2fs(image, check_exit_code=False, run_as_root=False)
setup_container(image, container_dir)

Setup the LXC container.

Parameters:
  • image – instance of nova.virt.image.model.Image
  • container_dir – directory to mount the image at

It will mount the loopback image to the container directory in order to create the root filesystem for the container.

Returns path of image device which is mounted to the container directory.

teardown_container(container_dir, container_root_device=None)

Teardown the container rootfs mounting once it is spawned.

It will umount the container that is mounted, and delete any linked devices.

Previous topic

The nova.virt.diagnostics Module

Next topic

The nova.virt.disk.mount.api Module

Project Source

This Page