The nova.virt.libvirt.imagebackend Module

class Backend(use_cow)

Bases: object

backend(image_type=None)
image(instance, disk_name, image_type=None)

Constructs image for selected backend

Instance:Instance name.
Name:Image name.
Image_type:Image type. Optional, is CONF.libvirt.images_type by default.
snapshot(instance, disk_path, image_type=None)

Returns snapshot for given image

Path:path to image
Image_type:type of image
class Image(source_type, driver_format, is_block_dev=False)

Bases: object

SUPPORTS_CLONE = False
cache(fetch_func, filename, size=None, *args, **kwargs)

Creates image from template.

Ensures that template and image not already exists. Ensures that base directory exists. Synchronizes on template fetching.

Fetch_func:Function that creates the base image Should accept target argument.
Filename:Name of the file in the image directory
Size:Size of created image in bytes (optional)
check_image_exists()
cleanup_direct_snapshot(location, also_destroy_volume=False, ignore_errors=False)

Performs any cleanup actions required after calling direct_snapshot(), for graceful exception handling and the like.

This should be a no-op on any backend where it is not implemented.

clone(context, image_id_or_uri)

Clone an image.

Note that clone operation is backend-dependent. The backend may ask the image API for a list of image “locations” and select one or more of those locations to clone an image from.

Parameters:image_id_or_uri – The ID or URI of an image to clone.
Raises:exception.ImageUnacceptable if it cannot be cloned
create_image(prepare_template, base, size, *args, **kwargs)

Create image from template.

Contains specific behavior for each image type.

Prepare_template:
 function, that creates template. Should accept target argument.
Base:Template name
Size:Size of created image in bytes
create_snap(name)

Create a snapshot on the image. A noop on backends that don’t support snapshots.

Parameters:name – name of the snapshot
direct_snapshot(context, snapshot_name, image_format, image_id, base_image_id)

Prepare a snapshot for direct reference from glance

Raises:exception.ImageUnacceptable if it cannot be referenced directly in the specified image format
Returns:URL to be given to glance
disk_qos(info, extra_specs)
get_disk_size(name)
get_model(connection)

Get the image information model

Returns:an instance of nova.virt.image.model.Image
import_file(instance, local_file, remote_name)

Import an image from local storage into this backend.

Import a local file into the store used by this image type. Note that this is a noop for stores using local disk (the local file is considered “in the store”).

If the image already exists it will be overridden by the new file

Parameters:
  • local_file – path to the file to import
  • remote_name – the name for the file in the store
static is_file_in_instance_path()

True if the backend stores images in files under instance path.

static is_shared_block_storage()

True if the backend puts images on a shared block storage.

libvirt_fs_info(target, driver_type=None)

Get LibvirtConfigGuestFilesys filled for this image.

Target:target directory inside a container.
Driver_type:filesystem driver type, can be loop nbd or ploop.
libvirt_info(disk_bus, disk_dev, device_type, cache_mode, extra_specs, hypervisor_version)

Get LibvirtConfigGuestDisk filled for this image.

Disk_dev:Disk bus device name
Disk_bus:Disk bus type
Device_type:Device type for this image.
Cache_mode:Caching mode for this image
Extra_specs:Instance type extra specs dict.
Hypervisor_version:
 the hypervisor version
remove_snap(name, ignore_errors=False)

Remove a snapshot on the image. A noop on backends that don’t support snapshots.

Parameters:
  • name – name of the snapshot
  • ignore_errors – don’t log errors if the snapshot does not exist
resize_image(size)

Resize image to size (in bytes).

Size:Desired size of image in bytes
resolve_driver_format()

Return the driver format for self.path.

First checks self.disk_info_path for an entry. If it’s not there, calls self._get_driver_format(), and then stores the result in self.disk_info_path

See https://bugs.launchpad.net/nova/+bug/1221190

rollback_to_snap(name)

Rollback the image to the named snapshot. A noop on backends that don’t support snapshots.

Parameters:name – name of the snapshot
snapshot_extract(target, out_format)
verify_base_size(base, size, base_size=0)

Check that the base image is not larger than size. Since images can’t be generally shrunk, enforce this constraint taking account of virtual image size.

class Lvm(instance=None, disk_name=None, path=None)

Bases: nova.virt.libvirt.imagebackend.Image

create_image(prepare_template, base, size, *args, **kwargs)
static escape(filename)
get_model(connection)
remove_volume_on_error(*args, **kwds)
resize_image(size)
snapshot_extract(target, out_format)
class Ploop(instance=None, disk_name=None, path=None)

Bases: nova.virt.libvirt.imagebackend.Image

create_image(prepare_template, base, size, *args, **kwargs)
resize_image(size)
snapshot_extract(target, out_format)
class Qcow2(instance=None, disk_name=None, path=None)

Bases: nova.virt.libvirt.imagebackend.Image

create_image(prepare_template, base, size, *args, **kwargs)
get_model(connection)
static is_file_in_instance_path()
resize_image(size)
snapshot_extract(target, out_format)
class Raw(instance=None, disk_name=None, path=None)

Bases: nova.virt.libvirt.imagebackend.Image

correct_format()
create_image(prepare_template, base, size, *args, **kwargs)
get_model(connection)
static is_file_in_instance_path()
resize_image(size)
snapshot_extract(target, out_format)
class Rbd(instance=None, disk_name=None, path=None, **kwargs)

Bases: nova.virt.libvirt.imagebackend.Image

SUPPORTS_CLONE = True
check_image_exists()
cleanup_direct_snapshot(location, also_destroy_volume=False, ignore_errors=False)

Unprotects and destroys the name snapshot.

With also_destroy_volume=True, it will also cleanup/destroy the parent volume. This is useful for cleaning up when the target volume fails to snapshot properly.

clone(context, image_id_or_uri)
create_image(prepare_template, base, size, *args, **kwargs)
create_snap(name)
direct_snapshot(context, snapshot_name, image_format, image_id, base_image_id)

Creates an RBD snapshot directly.

get_disk_size(name)

Returns the size of the virtual disk in bytes.

The name argument is ignored since this backend already knows its name, and callers may pass a non-existent local file path.

get_model(connection)
import_file(instance, local_file, remote_name)
static is_shared_block_storage()
libvirt_info(disk_bus, disk_dev, device_type, cache_mode, extra_specs, hypervisor_version)

Get LibvirtConfigGuestDisk filled for this image.

Disk_dev:Disk bus device name
Disk_bus:Disk bus type
Device_type:Device type for this image.
Cache_mode:Caching mode for this image
Extra_specs:Instance type extra specs dict.
remove_snap(name, ignore_errors=False)
resize_image(size)
rollback_to_snap(name)
snapshot_extract(target, out_format)

Previous topic

The nova.virt.libvirt.host Module

Next topic

The nova.virt.libvirt.imagecache Module

Project Source

This Page