Previous topic

The nova.virt.libvirt.imagecache Module

Next topic

The nova.virt.libvirt.vif Module

This Page

Psst... hey. You're reading the latest content, but it might be out of sync with code. You can read Nova 2011.2 docs or all OpenStack docs too.

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)
copy_image(src, dest)

Copy a disk image

Parameters:
  • src – Source image
  • dest – Destination path
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_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
ensure_tree(path)

Create a directory (and any ancestor directories required)

Parameters:path – Directory to create
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

get_open_port(start_port, end_port)

Find an available port

Parameters:
  • start_port – Start of acceptable port range
  • end_port – End of acceptable port range
is_valid_info_file(path)

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

load_file(path)

Read contents of file

Parameters:path – File to read
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
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.

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)