Previous topic

The nova.virt.xenapi.vif Module

Next topic

The nova.virt.xenapi.vmops 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.xenapi.vm_utils Module

Helper methods for operations related to the management of VM records and their attributes like VDIs, VIFs, as well as their lookup functions.

class ImageType

Bases: object

Enumeration class for distinguishing different image types

0 - kernel image (goes on dom0’s filesystem)
1 - ramdisk image (goes on dom0’s filesystem)
2 - disk image (local SR, partitioned by objectstore plugin)
3 - raw disk image (local SR, NOT partitioned by plugin)
4 - vhd disk image (local SR, NOT inspected by XS, PV assumed for
linux, HVM assumed for Windows)
5 - ISO disk image (local SR, NOT partitioned by plugin)
DISK = 2
DISK_ISO = 5
DISK_ISO_STR = 'iso'
DISK_RAW = 3
DISK_RAW_STR = 'os_raw'
DISK_STR = 'root'
DISK_VHD = 4
DISK_VHD_STR = 'vhd'
KERNEL = 0
KERNEL_STR = 'kernel'
RAMDISK = 1
RAMDISK_STR = 'ramdisk'
classmethod from_string(image_type_str)
classmethod to_string(image_type)
auto_configure_disk(session, vdi_ref, new_gb)

Partition and resize FS to match the size specified by instance_types.root_gb.

This is a fail-safe to prevent accidentally destroying data on a disk erroneously marked as auto_disk_config=True.

The criteria for allowing resize are:

  1. ‘auto_disk_config’ must be true for the instance (and image). (If we’ve made it here, then auto_disk_config=True.)
  2. The disk must have only one partition.
  3. The file-system on the one partition must be ext3 or ext4.
average_series(data, col, until=None)
cleanup_attached_vdis(session)

Unplug any instance VDIs left after an unclean restart

clone_vdi(session, vdi_to_clone_ref)

Clones a VDI and return the new VDIs reference.

compile_diagnostics(record)

Compile VM diagnostics data

compile_info(record)

Fill record with VM status information

compile_metrics(start_time, stop_time=None)

Compile bandwidth usage, cpu, and disk metrics for all VMs on this host

copy_vdi(session, sr_ref, vdi_to_copy_ref)

Copy a VDI and return the new VDIs reference.

create_image(context, session, instance, image_id, image_type)

Creates VDI from the image stored in the local cache. If the image is not present in the cache, it streams it from glance.

Returns: A list of dictionaries that describe VDIs

create_kernel_image(context, session, instance, image_id, user_id, project_id, image_type)

Creates kernel/ramdisk file from the image stored in the cache. If the image is not present in the cache, it streams it from glance.

Returns: A list of dictionaries that describe VDIs

create_snapshot(session, instance, vm_ref, label)

Creates Snapshot (Template) VM, Snapshot VBD, Snapshot VDI, Snapshot VHD

create_vbd(session, vm_ref, vdi_ref, userdevice, vbd_type='disk', read_only=False, bootable=False)

Create a VBD record and returns its reference.

create_vdi(session, sr_ref, info, disk_type, virtual_size, read_only=False)

Create a VDI record and returns its reference.

create_vm(session, instance, kernel, ramdisk, use_pv_kernel=False)

Create a VM record. Returns new VM reference. the use_pv_kernel flag indicates whether the guest is HVM or PV

There are 3 scenarios:

  1. Using paravirtualization, kernel passed in
  2. Using paravirtualization, kernel within the image
  3. Using hardware virtualization
destroy_kernel_ramdisk(session, kernel, ramdisk)
destroy_vbd(session, vbd_ref)

Destroy VBD from host database

destroy_vdi(session, vdi_ref)
determine_disk_image_type(image_meta)

Disk Image Types are used to determine where the kernel will reside within an image. To figure out which type we’re dealing with, we use the following rules:

  1. If we’re using Glance, we can use the image_type field to determine the image_type
  2. If we’re not using Glance, then we need to deduce this based on whether a kernel_id is specified.
determine_is_pv(session, vdi_ref, disk_image_type, os_type)

Determine whether the VM will use a paravirtualized kernel or if it will use hardware virtualization.

  1. Glance (VHD): then we use os_type, raise if not set
  2. Glance (DISK_RAW): use Pygrub to figure out if pv kernel is available
  3. Glance (DISK): pv is assumed
  4. Glance (DISK_ISO): no pv is assumed
ensure_correct_host(session)

Ensure we’re connected to the host we’re running on. This is the required configuration for anything that uses vdi_attached_here.

ensure_free_mem(session, instance)
find_cached_image(session, image_id, sr_ref)

Returns the vdi-ref of the cached image.

find_iso_sr(session)

Return the storage repository to hold ISO images

find_sr(session)

Return the storage repository to hold VM images

find_vbd_by_number(session, vm_ref, number)

Get the VBD reference from the device number

generate_ephemeral(session, instance, vm_ref, userdevice, size_gb)
generate_swap(session, instance, vm_ref, userdevice, swap_mb)
get_rrd(server, vm_uuid)

Return the VM RRD XML as a string

get_rrd_server()

Return server’s scheme and address to use for retrieving RRD XMLs.

get_rrd_updates(server, start_time)

Return the RRD updates XML as a string

get_sr_path(session)

Return the path to our storage repository

This is used when we’re dealing with VHDs directly, either by taking snapshots or by restoring an image in the DISK_VHD format.

get_this_vm_ref(session)
get_this_vm_uuid()
get_vdi_for_vm_safely(session, vm_ref)

Retrieves the primary VDI for a VM

get_vhd_parent(session, vdi_rec)

Returns the VHD parent of the given VDI record, as a (ref, rec) pair. Returns None if we’re at the root of the tree.

get_vhd_parent_uuid(session, vdi_ref)
integrate_series(data, col, start, until=None)
is_snapshot(session, vm)
list_vms(session)
lookup(session, name_label)

Look the instance up and return it if available

lookup_kernel_ramdisk(session, vm)
lookup_vm_vdis(session, vm_ref)

Look for the VDIs that are attached to the VM

parse_rrd_data(doc)
parse_rrd_meta(doc)
parse_rrd_update(doc, start, until=None)
preconfigure_instance(session, instance, vdi_ref, network_info)

Makes alterations to the image before launching as part of spawn.

remap_vbd_dev(dev)

Return the appropriate location for a plugged-in VBD device

Ubuntu Maverick moved xvd? -> sd?. This is considered a bug and will be fixed in future versions:

For now, we work around it by just doing a string replace.

resize_disk(session, instance, vdi_ref, instance_type)
safe_find_iso_sr(session)

Same as find_iso_sr except raises a NotFound exception if SR cannot be determined

safe_find_sr(session)

Same as find_sr except raises a NotFound exception if SR cannot be determined

scan_default_sr(session)

Looks for the system default SR and triggers a re-scan

scan_sr(session, sr_ref=None)

Scans the SR specified by sr_ref

set_vdi_name(session, vdi_uuid, label, description, vdi_ref=None)
set_vm_name_label(session, vm_ref, name_label)
unplug_vbd(session, vbd_ref)

Unplug VBD from VM

upload_image(context, session, instance, vdi_uuids, image_id)

Requests that the Glance plugin bundle the specified VDIs and push them into Glance using the specified human-friendly name.

vdi_attached_here(*args, **kwds)
walk_vdi_chain(session, vdi_uuid)

Yield vdi_recs for each element in a VDI chain