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, size=None)

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)
find_disk(virt_dom)

Find root device path for instance

May be file or device

get_disk_backing_file(path, basename=True)

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_disk_type(path)

Retrieve disk type (raw, qcow2, lvm) for given file.

get_fc_hbas()

Get the Fibre Channel HBA information.

get_fc_hbas_info()

Get Fibre Channel WWNs and device paths from the system, if any.

get_fc_wwnns()

Get Fibre Channel WWNNs from the system, if any.

get_fc_wwpns()

Get Fibre Channel WWPNs from the system, if any.

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_instance_path(instance, forceold=False, relative=False)

Determine the correct path for instance storage.

This method determines the directory name for instance storage, while handling the fact that we changed the naming style to something more unique in the grizzly release.

Parameters:
  • instance – the instance we want a path for
  • forceold – force the use of the pre-grizzly format
  • relative – if True, just the relative path is returned
Returns:

a path to store information about that instance

get_iscsi_initiator()

Get iscsi initiator name for this machine.

get_volume_group_info(vg)

Return free/used/total space info for a volume group in bytes

Parameters:vg – volume group name
Returns:A dict containing: :total: How big the filesystem is (in bytes) :free: How much space is free (in bytes) :used: How much space is used (in bytes)
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_info(path)

Get logical volume info.

Parameters:path – logical volume path
logical_volume_size(path)

Get logical volume size in bytes.

Parameters:path – logical volume path
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
remove_logical_volumes(*paths)

Remove one or more logical volume.

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