This Page

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

The nova.virt.xenapi.vmops Module

Management class for VM-related functions (spawn, reboot, etc).

class nova.virt.xenapi.vmops.SimpleDH(prime=None, base=None, secret=None)

Bases: object

This class wraps all the functionality needed to implement basic Diffie-Hellman-Merkle key exchange in Python. It features intelligent defaults for the prime and base numbers needed for the calculation, while allowing you to supply your own. It requires that the openssl binary be installed on the system on which this is run, as it uses that to handle the encryption and decryption. If openssl is not available, a RuntimeError will be raised.

bin_to_dec(binval)
compute_shared(other)
dec_to_mpi(dec)
decrypt(text)
encrypt(text)
get_public()
mpi_to_dec(mpi)
class nova.virt.xenapi.vmops.VMOps(session)

Bases: object

Management class for VM-related tasks

add_to_param_xenstore(instance_or_vm, key, val)

Takes a key/value pair and adds it to the xenstore parameter record for the given vm instance. If the key exists in xenstore, it is overwritten

add_to_xenstore(vm, path, key, value)

Adds the passed key/value pair to the xenstore record for the given VM at the specified location. A XenAPIPlugin.PluginError will be raised if any error is encountered in the write process.

clear_param_xenstore(instance_or_vm)

Removes all data from the xenstore parameter record for this VM.

clear_xenstore(vm, path)

Deletes the VM’s xenstore record for the specified path. If there is no such record, the request is ignored.

create_vifs(vm_ref, network_info)

Creates vifs for an instance.

destroy(instance)

Destroy VM instance.

This is the method exposed by xenapi_conn.destroy(). The rest of the destroy_* methods are internal.

finish_resize(instance, disk_info)
get_ajax_console(instance)

Return link to instance’s ajax console.

get_console_output(instance)

Return snapshot of console.

get_diagnostics(instance)

Return data about VM diagnostics.

get_info(instance)

Return data about VM instance.

inject_file(instance, path, contents)

Write a file to the VM instance.

The path to which it is to be written and the contents of the file need to be supplied; both will be base64-encoded to prevent errors with non-ASCII characters being transmitted. If the agent does not support file injection, or the user has disabled it, a NotImplementedError will be raised.

inject_network_info(instance, network_info=None, vm_ref=None)

shim in place which makes inject_network_info work without being passed network_info. shim goes away after nova-multi-nic

Links the base copy VHD to the COW via the XAPI plugin.

list_from_xenstore(vm, path)

Runs the xenstore-ls command to get a listing of all records from ‘path’ downward. Returns a dict with the sub-paths as keys, and the value stored in those paths as values. If nothing is found at that path, returns None.

list_instances()

List VM instances.

list_instances_detail()

List VM instances, returning InstanceInfo objects.

migrate_disk_and_power_off(instance, dest)

Copies a VHD from one host machine to another.

Parameters:
  • instance – the instance that owns the VHD in question.
  • dest – the destination host machine.
  • disk_type – values are ‘primary’ or ‘cow’.
pause(instance, callback)

Pause VM instance.

poll_rescued_instances(timeout)

Look for expirable rescued instances.

  • forcibly exit rescue mode for any instances that have been in rescue mode for >= the provided timeout
read_from_param_xenstore(instance_or_vm, keys=None)

Returns the xenstore parameter record data for the specified VM instance as a dict. Accepts an optional key or list of keys; if a value for ‘keys’ is passed, the returned dict is filtered to only return the values for those keys.

read_from_xenstore(vm, path)

Returns the value stored in the xenstore record for the given VM at the specified location. A XenAPIPlugin.PluginError will be raised if any error is encountered in the read process.

read_partial_from_param_xenstore(instance_or_vm, key_prefix)

Returns a dict of all the keys in the xenstore parameter record for the given instance that begin with the key_prefix.

reboot(instance)

Reboot VM instance.

remove_from_param_xenstore(instance_or_vm, key_or_keys)

Takes either a single key or a list of keys and removes them from the xenstore parameter record data for the given VM. If the key doesn’t exist, the request is ignored.

remove_from_xenstore(vm, path, key_or_keys)

Takes either a single key or a list of keys and removes them from the xenstoreirecord data for the given VM. If the key doesn’t exist, the request is ignored.

rescue(instance, callback)

Rescue the specified instance.

  • shutdown the instance VM.
  • set ‘bootlock’ to prevent the instance from starting in rescue.
  • spawn a rescue VM (the vm name-label will be instance-N-rescue).
reset_network(instance, vm_ref=None)

Creates uuid arg to pass to make_agent_call and calls it.

resize_instance(instance, vdi_uuid)

Resize a running instance by changing it’s RAM and disk size.

resume(instance, callback)

Resume the specified instance.

revert_resize(instance)
set_admin_password(instance, new_pass)

Set the root/admin password on the VM instance.

This is done via an agent running on the VM. Communication between nova and the agent is done via writing xenstore records. Since communication is done over the XenAPI RPC calls, we need to encrypt the password. We’re using a simple Diffie-Hellman class instead of the more advanced one in M2Crypto for compatibility with the agent code.

snapshot(instance, image_id)

Create snapshot from a running VM instance.

Parameters:
  • instance – instance to be snapshotted
  • image_id – id of image to upload to

Steps involved in a XenServer snapshot:

  1. XAPI-Snapshot: Snapshotting the instance using XenAPI. This

    creates: Snapshot (Template) VM, Snapshot VBD, Snapshot VDI, Snapshot VHD

  2. Wait-for-coalesce: The Snapshot VDI and Instance VDI both point to

    a ‘base-copy’ VDI. The base_copy is immutable and may be chained with other base_copies. If chained, the base_copies coalesce together, so, we must wait for this coalescing to occur to get a stable representation of the data on disk.

  3. Push-to-glance: Once coalesced, we call a plugin on the XenServer

    that will bundle the VHDs together and then push the bundle into Glance.

spawn(instance, network_info=None)
spawn_rescue(instance)

Spawn a rescue instance.

suspend(instance, callback)

Suspend the specified instance.

unpause(instance, callback)

Unpause VM instance.

unrescue(instance, callback)

Unrescue the specified instance.

  • unplug the instance VM’s disk from the rescue VM.
  • teardown the rescue VM.
  • release the bootlock to allow the instance VM to start.
write_to_param_xenstore(instance_or_vm, mapping)

Takes a dict and writes each key/value pair to the xenstore parameter record for the given vm instance. Any existing data for those keys is overwritten.

write_to_xenstore(vm, path, value)

Writes the passed value to the xenstore record for the given VM at the specified location. A XenAPIPlugin.PluginError will be raised if any error is encountered in the write process.