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)
chown_for_id_maps(path, id_maps)

Change ownership of file or directory for an id mapped environment

Parameters:
  • path – File or directory whose ownership to change
  • id_maps – List of type LibvirtConfigGuestIDMap
copy_image(src, dest, host=None, receive=False, on_execute=None, on_completion=None, compression=True)

Copy a disk image to an existing directory

Parameters:
  • src – Source image
  • dest – Destination path
  • host – Remote host
  • receive – Reverse the rsync direction
  • on_execute – Callback method to store pid of process in cache
  • on_completion – Callback method to remove pid of process from cache
  • compression – Allows to use rsync operation with or without compression
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.
execute(*args, **kwargs)
extract_snapshot(disk_path, source_fmt, out_path, dest_fmt)

Extract a snapshot from a disk image. Note that nobody should write to the disk image during this operation.

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

Grab image.

fetch_raw_image(context, target, image_id, user_id, project_id, max_size=0)

Grab initrd or kernel image.

This function does not attempt raw conversion, as these images will already be in raw format.

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 open() 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_arch(image_meta)

Determine the architecture of the guest (or host).

This method determines the CPU architecture that must be supported by the hypervisor. It gets the (guest) arch info from image_meta properties, and it will fallback to the nova-compute (host) arch if no architecture info is provided in image_meta.

Parameters:image_meta – the metadata associated with the instance image
Returns:guest (or host) architecture
get_disk_backing_file(path, basename=True, format=None)

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

Get the (virtual) size of a disk image

Parameters:
  • path – Path to the disk image
  • format – the on-disk format of path
Returns:

Size (in bytes) of the given disk image as it would be seen by a virtual machine.

get_disk_type_from_path(path)

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

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_instance_path_at_destination(instance, migrate_data=None)

Get the instance path on destination node while live migration.

This method determines the directory name for instance storage on destination node, while live migration.

Parameters:
  • instance – the instance we want a path for
  • migrate_data – if not None, it is a dict which holds data required for live migration without shared storage.
Returns:

a path to store information about that instance

get_iscsi_initiator()
is_mounted(mount_path, source=None)

Check if the given source is mounted at given destination point.

is_valid_hostname(hostname)
load_file(path)

Read contents of file

Parameters:path – File to read
path_exists(path)

Returns if path exists

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)
pick_disk_driver_name(hypervisor_version, is_block_dev=False)

Pick the libvirt primary backend driver name

If the hypervisor supports multiple backend drivers we have to tell libvirt which one should be used.

Xen supports the following drivers: “tap”, “tap2”, “phy”, “file”, or “qemu”, being “qemu” the preferred one. Qemu only supports “qemu”.

Parameters:is_block_dev
Returns:driver_name or None
update_mtime(path)

Touch a file without being the owner.

Parameters:path – File bump the mtime on
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.storage.rbd_utils Module

Next topic

The nova.virt.libvirt.vif Module

Project Source

This Page