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)
6 - config drive
DISK = 2
DISK_CONFIGDRIVE_STR = 'configdrive'
DISK_ISO_STR = 'iso'
DISK_RAW_STR = 'os_raw'
DISK_STR = 'root'
DISK_VHD_STR = 'vhd'
KERNEL_STR = 'kernel'
RAMDISK_STR = 'ramdisk'
classmethod get_role(image_type_id)

Get the role played by the image, based on its type.

classmethod to_string(image_type)
attach_cd(session, vm_ref, vdi_ref, userdevice)

Create an empty VBD, then insert the CD.

clean_shutdown_vm(session, instance, vm_ref)

Unplug any instance VDIs left after an unclean restart.


Compile VM diagnostics data.

compile_info(session, vm_ref)

Fill record with VM status information.

compile_instance_diagnostics(instance, vm_rec)
create_image(context, session, instance, name_label, 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_and_ramdisk(context, session, instance, name_label)
create_vbd(session, vm_ref, vdi_ref, userdevice, vbd_type='disk', read_only=False, bootable=False, osvol=False, empty=False, unpluggable=True)

Create a VBD record and returns its reference.

create_vdi(session, sr_ref, instance, name_label, disk_type, virtual_size, read_only=False)

Create a VDI record and returns its reference.

create_vm(session, instance, name_label, kernel, ramdisk, use_pv_kernel=False, device_id=None)

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_cached_images(session, sr_ref, all_cached=False, dry_run=False)

Destroy used or unused cached images.

A cached image that is being used by at least one VM is said to be ‘used’.

In the case of an ‘unused’ image, the cached image will be the only descendent of the base-copy. So when we delete the cached-image, the refcount will drop to zero and XenServer will automatically destroy the base-copy for us.

The default behavior of this function is to destroy only ‘unused’ cached images. To destroy all cached images, use the all_cached=True kwarg.

destroy_kernel_ramdisk(session, instance, kernel, ramdisk)
destroy_vbd(session, vbd_ref)

Destroy VBD from host database.

destroy_vdi(session, vdi_ref)
destroy_vm(session, instance, vm_ref)

Destroys a VM record.


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_vm_mode(instance, disk_image_type)

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

generate_configdrive(session, instance, vm_ref, userdevice, network_info, admin_password=None, files=None)
generate_ephemeral(session, instance, vm_ref, first_userdevice, instance_name_label, total_size_gb)
generate_iso_blank_root_disk(session, instance, vm_ref, userdevice, name_label, size_gb)
generate_single_ephemeral(session, instance, vm_ref, userdevice, size_gb, instance_name_label=None)
generate_swap(session, instance, vm_ref, userdevice, name_label, swap_mb)
get_all_vdi_uuids_for_vm(session, vm_ref, min_userdevice=0)
get_instance_vdis_for_sr(session, vm_ref, sr_ref)

Return opaqueRef for all the vdis which live on sr.

get_power_state(session, vm_ref)
get_sr_path(session, sr_ref=None)

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_vdi_for_vm_safely(session, vm_ref, userdevice='0')

Retrieves the primary VDI for a VM.

get_vm_device_id(session, image_meta)
handle_ipxe_iso(session, instance, cd_vdi, network_info)

iPXE ISOs are a mechanism to allow the customer to roll their own image.

To use this feature, a service provider needs to configure the appropriate Nova flags, roll an iPXE ISO, then distribute that image to customers via Glance.

NOTE: mkisofs is not present by default in the Dom0, so the service provider can either add that package manually to Dom0 or include the mkisofs binary in the image itself.

hard_shutdown_vm(session, instance, vm_ref)
import_all_migrated_disks(session, instance, import_root=True)
is_enough_free_mem(session, instance)
is_snapshot(session, vm)
is_vm_shutdown(session, vm_ref)
lookup(session, name_label, check_rescue=False)

Look the instance up and return it if available. :param:check_rescue: if True will return the ‘name’-rescue vm if it exists, instead of just ‘name’

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

Look for the VDIs that are attached to the VM.

migrate_vhd(session, instance, vdi_uuid, dest, sr_path, seq_num, ephemeral_number=0)
preconfigure_instance(session, instance, vdi_ref, network_info)

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

remove_old_snapshots(session, instance, vm_ref)

See if there is an snapshot present that should be removed.

resize_disk(session, instance, vdi_ref, flavor)
safe_destroy_vdis(session, vdi_refs)

Tries to destroy the requested VDIs, but ignores any errors.


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


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

set_other_config_pci(session, vm_ref, params)

Set the pci key of other-config parameter to params.

set_vm_name_label(session, vm_ref, name_label)
snapshot_attached_here(*args, **kwds)
strip_base_mirror_from_vdis(session, vm_ref)
try_auto_configure_disk(session, vdi_ref, new_gb)
unplug_vbd(session, vbd_ref, this_vm_ref)
update_vdi_virtual_size(session, instance, vdi_ref, new_gb)
vdi_attached_here(*args, **kwds)
vm_ref_or_raise(session, instance_name)

Previous topic

The nova.virt.xenapi.vif Module

Next topic

The nova.virt.xenapi.vmops Module

Project Source

This Page