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 nova.virt.xenapi.vm_utils.ImageType
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)

classmethod from_string(image_type_str)
classmethod to_string(image_type)
class nova.virt.xenapi.vm_utils.VMHelper

Bases: nova.virt.xenapi.HelperBase

The class that wraps the helper methods together.

classmethod compile_diagnostics(session, record)

Compile VM diagnostics data

classmethod compile_info(record)

Fill record with VM status information

classmethod create_cd_vbd(session, vm_ref, vdi_ref, userdevice, bootable)

Create a VBD record. Returns a Deferred that gives the new VBD reference specific to CDRom devices.

classmethod create_snapshot(session, instance_id, vm_ref, label)

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

classmethod create_vbd(session, vm_ref, vdi_ref, userdevice, bootable)

Create a VBD record. Returns a Deferred that gives the new VBD reference.

classmethod create_vdi(session, sr_ref, name_label, virtual_size, read_only)

Create a VDI record and returns its reference.

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

Create a VM record. Returns a Deferred that gives the 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
classmethod destroy_vbd(session, vbd_ref)

Destroy VBD from host database

classmethod destroy_vdi(session, vdi_ref)
classmethod determine_disk_image_type(instance, context)

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.
classmethod determine_is_pv(session, instance_id, 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
classmethod ensure_free_mem(session, instance)
classmethod fetch_blank_disk(session, instance_type_id)
classmethod fetch_image(context, session, instance, image, user_id, project_id, image_type)

Fetch image from glance based on image type.

Returns: A single filename if image_type is KERNEL or RAMDISK
A list of dictionaries that describe VDIs, otherwise
classmethod find_vbd_by_number(session, vm_ref, number)

Get the VBD reference from the device number

classmethod 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.

classmethod get_vdi_for_vm_safely(session, vm_ref)

Retrieves the primary VDI for a VM

classmethod lookup(session, name_label)

Look the instance i up, and returns it if available

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

Look for the VDIs that are attached to the VM

classmethod preconfigure_instance(session, instance, vdi_ref, network_info)

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

classmethod scan_default_sr(session)

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

classmethod scan_sr(session, instance_id=None, sr_ref=None)

Scans the SR specified by sr_ref

classmethod unplug_vbd(session, vbd_ref)

Unplug VBD from VM

classmethod 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.

nova.virt.xenapi.vm_utils.find_iso_sr(session)

Return the storage repository to hold ISO images

nova.virt.xenapi.vm_utils.find_sr(session)

Return the storage repository to hold VM images

nova.virt.xenapi.vm_utils.get_name_label_for_image(image)
nova.virt.xenapi.vm_utils.get_rrd(host, vm_uuid)

Return the VM RRD XML as a string

nova.virt.xenapi.vm_utils.get_this_vm_ref(session)
nova.virt.xenapi.vm_utils.get_this_vm_uuid()
nova.virt.xenapi.vm_utils.get_vdi_for_vm_safely(session, vm_ref)
nova.virt.xenapi.vm_utils.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.

nova.virt.xenapi.vm_utils.get_vhd_parent_uuid(session, vdi_ref)
nova.virt.xenapi.vm_utils.ignore_failure(func, *args, **kwargs)
nova.virt.xenapi.vm_utils.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.

nova.virt.xenapi.vm_utils.safe_find_iso_sr(session)

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

nova.virt.xenapi.vm_utils.safe_find_sr(session)

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

nova.virt.xenapi.vm_utils.vbd_unplug_with_retry(session, vbd_ref)

Call VBD.unplug on the given VBD, with a retry if we get DEVICE_DETACH_REJECTED. For reasons which I don’t understand, we’re seeing the device still in use, even when all processes using the device should be dead.

nova.virt.xenapi.vm_utils.wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref, original_parent_uuid)

Spin until the parent VHD is coalesced into its parent VHD

Before coalesce:
  • original_parent_vhd
    • parent_vhd

      snapshot

Atter coalesce:
  • parent_vhd

    snapshot

nova.virt.xenapi.vm_utils.walk_vdi_chain(session, vdi_uuid)

Yield vdi_recs for each element in a VDI chain

nova.virt.xenapi.vm_utils.with_vdi_attached_here(session, vdi_ref, read_only, f)