The nova.virt.libvirt.utils Module

chown(path, owner)

Change ownership of file or directory

Parameters:
  • path – File or directory whose ownership to change
  • owner – Desired new owner (given as uid or username)
clear_logical_volume(path)

Obfuscate the logical volume.

Parameters:path – logical volume path
copy_image(src, dest, host=None)

Copy a disk image to an existing directory

Parameters:
  • src – Source image
  • dest – Destination path
  • host – Remote host
create_cow_image(backing_file, path)

Create COW image

Creates a COW image with the given backing file

Parameters:
  • backing_file – Existing image on which to base the COW image
  • path – Desired location of the COW image
create_image(disk_format, path, size)

Create a disk image

Parameters:
  • disk_format – Disk image format (as known by qemu-img)
  • path – Desired location of the disk image
  • size – Desired size of disk image. May be given as an int or a string. If given as an int, it will be interpreted as bytes. If it’s a string, it should consist of a number with an optional suffix (‘K’ for Kibibytes, M for Mebibytes, ‘G’ for Gibibytes, ‘T’ for Tebibytes). If no suffix is given, it will be interpreted as bytes.
create_lvm_image(vg, lv, size, sparse=False)

Create LVM image.

Creates a LVM image with given size.

Parameters:
  • vg – existing volume group which should hold this image
  • lv – name for this image (logical volume)
Size :

size of image in bytes

Sparse :

create sparse logical volume

create_snapshot(disk_path, snapshot_name)

Create a snapshot in a disk image

Parameters:
  • disk_path – Path to disk image
  • snapshot_name – Name of snapshot in disk image
delete_snapshot(disk_path, snapshot_name)

Create a snapshot in a disk image

Parameters:
  • disk_path – Path to disk image
  • snapshot_name – Name of snapshot in disk image
execute(*args, **kwargs)
extract_snapshot(disk_path, source_fmt, snapshot_name, out_path, dest_fmt)

Extract a named snapshot from a disk image

Parameters:
  • disk_path – Path to disk image
  • snapshot_name – Name of snapshot in disk image
  • out_path – Desired path of extracted snapshot
fetch_image(context, target, image_id, user_id, project_id)

Grab image

file_delete(path)

Delete (unlink) file

Note: The reason this is kept in a separate module is to easily
be able to provide a stub module that doesn’t alter system state at all (for unit tests)
file_open(*args, **kwargs)

Open file

see built-in file() documentation for more details

Note: The reason this is kept in a separate module is to easily
be able to provide a stub module that doesn’t alter system state at all (for unit tests)
get_disk_backing_file(path)

Get the backing file of a disk image

Parameters:path – Path to the disk image
Returns:a path to the image’s backing store
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_fs_info(path)

Get free/used/total space info for a filesystem

Parameters:path – Any dirent on the filesystem
Returns:A dict containing:
free:How much space is free (in bytes)
used:How much space is used (in bytes)
total:How big the filesystem is (in bytes)
get_info_filename(base_path)

Construct a filename for storing addtional information about a base image.

Returns a filename.

get_iscsi_initiator()

Get iscsi initiator name for this machine

is_valid_info_file(path)

Test if a given path matches the pattern for info files.

list_logical_volumes(vg)

List logical volumes paths for given volume group.

Parameters:vg – volume group name
load_file(path)

Read contents of file

Parameters:path – File to read
logical_volume_size(path)

Get logical volume size in bytes.

Parameters:path – logical volume path
mkfs(fs, path, label=None)

Format a file or block device

Parameters:
  • fs – Filesystem type (examples include ‘swap’, ‘ext3’, ‘ext4’ ‘btrfs’, etc.)
  • path – Path to file or block device to format
  • label – Volume label to use
pick_disk_driver_name(is_block_dev=False)

Pick the libvirt primary backend driver name

If the hypervisor supports multiple backend drivers, then the name attribute selects the primary backend driver name, while the optional type attribute provides the sub-type. For example, xen supports a name of “tap”, “tap2”, “phy”, or “file”, with a type of “aio” or “qcow2”, while qemu only supports a name of “qemu”, but multiple types including “raw”, “bochs”, “qcow2”, and “qed”.

Parameters:is_block_dev
Returns:driver_name or None
read_stored_info(base_path, field=None)

Read information about an image.

Returns an empty dictionary if there is no info, just the field value if a field is requested, or the entire dictionary otherwise.

remove_logical_volumes(*paths)

Remove one or more logical volume.

volume_group_free_space(vg)

Return available space on volume group in bytes.

Parameters:vg – volume group name
write_stored_info(target, field=None, value=None)

Write information about an image.

write_to_file(path, contents, umask=None)

Write the given contents to a file

Parameters:
  • path – Destination file
  • contents – Desired contents of the file
  • umask – Umask to set when creating this file (will be reset)

Previous topic

The nova.virt.libvirt.imagecache Module

Next topic

The nova.virt.libvirt.vif Module

This Page