Package ganeti :: Package hypervisor :: Module hv_kvm
[hide private]
[frames] | no frames]

Module hv_kvm

source code

KVM hypervisor

Classes [hide private]
  QmpMessage
QEMU Messaging Protocol (QMP) message.
  MonitorSocket
  QmpConnection
Connection to the QEMU Monitor using the QEMU Monitor Protocol (QMP).
  KVMHypervisor
KVM hypervisor interface
Functions [hide private]
 
_GetDriveURI(disk, link, uri)
Helper function to get the drive uri to be used in --drive kvm option
source code
 
_GenerateDeviceKVMId(dev_type, dev)
Helper function to generate a unique device name used by KVM
source code
 
_GetFreeSlot(slots, slot=None, reserve=False)
Helper method to get first available slot in a bitarray
source code
 
_GetExistingDeviceInfo(dev_type, device, runtime)
Helper function to get an existing device inside the runtime file
source code
tuple
_UpgradeSerializedRuntime(serialized_runtime)
Upgrade runtime data
source code
tuple
_AnalyzeSerializedRuntime(serialized_runtime)
Return runtime entries for a serialized runtime file
source code
 
_GetTunFeatures(fd, _ioctl=fcntl.ioctl)
Retrieves supported TUN features from file descriptor.
source code
 
_ProbeTapVnetHdr(fd, _features_fn=_GetTunFeatures)
Check whether to enable the IFF_VNET_HDR flag.
source code
tuple
_OpenTap(vnet_hdr=True)
Open a new tap device and return its file descriptor.
source code
Variables [hide private]
  affinity = None
  fdsend = None
  _KVM_NETWORK_SCRIPT = pathutils.CONF_DIR+ "/kvm-vif-bridge"
  _KVM_START_PAUSED_FLAG = "-S"
  TUNSETIFF = 0x400454ca
  TUNGETIFF = 0x800454d2
  TUNGETFEATURES = 0x800454cf
  IFF_TAP = 0x0002
  IFF_NO_PI = 0x1000
  IFF_ONE_QUEUE = 0x2000
  IFF_VNET_HDR = 0x4000
  _SPICE_ADDITIONAL_PARAMS = frozenset([constants.HV_KVM_SPICE_I...
SPICE parameters which depend on constants.HV_KVM_SPICE_BIND
  _AVAILABLE_PCI_SLOT = bitarray("0")
  _KVM_NICS_RUNTIME_INDEX = 1
  _KVM_DISKS_RUNTIME_INDEX = 3
  _DEVICE_RUNTIME_INDEX = {constants.HOTPLUG_TARGET_DISK: _KVM_D...
  _FIND_RUNTIME_ENTRY = {constants.HOTPLUG_TARGET_NIC: lambda ni...
  _RUNTIME_DEVICE = {constants.HOTPLUG_TARGET_NIC: lambda d: d, ...
  _RUNTIME_ENTRY = {constants.HOTPLUG_TARGET_NIC: lambda d, e: d...

Imports: errno, os, re, tempfile, time, logging, pwd, struct, fcntl, shutil, socket, stat, StringIO, bitarray, utils, constants, errors, serializer, objects, uidpool, ssconf, netutils, pathutils, hv_base, utils_wrapper


Function Details [hide private]

_GetDriveURI(disk, link, uri)

source code 

Helper function to get the drive uri to be used in --drive kvm option

Parameters:
  • disk (objects.Disk) - A disk configuration object
  • link (string) - The device link as returned by _SymlinkBlockDev()
  • uri (string) - The drive uri as returned by _CalculateDeviceURI()

_GenerateDeviceKVMId(dev_type, dev)

source code 

Helper function to generate a unique device name used by KVM

QEMU monitor commands use names to identify devices. Here we use their pci slot and a part of their UUID to name them. dev.pci might be None for old devices in the cluster.

Parameters:
  • dev_type (sting) - device type of param dev
  • dev (objects.Disk or objects.NIC) - the device object for which we generate a kvm name
Raises:

_GetFreeSlot(slots, slot=None, reserve=False)

source code 

Helper method to get first available slot in a bitarray

Parameters:
  • slots (bitarray) - the bitarray to operate on
  • slot (integer) - if given we check whether the slot is free
  • reserve (boolean) - whether to reserve the first available slot or not
Returns:
the idx of the (first) available slot
Raises:

_GetExistingDeviceInfo(dev_type, device, runtime)

source code 

Helper function to get an existing device inside the runtime file

Used when an instance is running. Load kvm runtime file and search for a device based on its type and uuid.

Parameters:
  • dev_type (sting) - device type of param dev
  • device (objects.Disk or objects.NIC) - the device object for which we generate a kvm name
  • runtime (tuple (cmd, nics, hvparams, disks)) - the runtime data to search for the device
Raises:
  • errors.HotplugError - in case the requested device does not exist (e.g. device has been added without --hotplug option) or device info has not pci slot (e.g. old devices in the cluster)

_UpgradeSerializedRuntime(serialized_runtime)

source code 

Upgrade runtime data

Remove any deprecated fields or change the format of the data. The runtime files are not upgraded when Ganeti is upgraded, so the required modification have to be performed here.

Parameters:
  • serialized_runtime (string) - raw text data read from actual runtime file
Returns: tuple
(cmd, nic dicts, hvparams, bdev dicts)

_AnalyzeSerializedRuntime(serialized_runtime)

source code 

Return runtime entries for a serialized runtime file

Parameters:
  • serialized_runtime (string) - raw text data read from actual runtime file
Returns: tuple
(cmd, nics, hvparams, bdevs)

_GetTunFeatures(fd, _ioctl=fcntl.ioctl)

source code 

Retrieves supported TUN features from file descriptor.

See Also: _ProbeTapVnetHdr

_ProbeTapVnetHdr(fd, _features_fn=_GetTunFeatures)

source code 

Check whether to enable the IFF_VNET_HDR flag.

To do this, _all_ of the following conditions must be met:

  1. TUNGETFEATURES ioctl() *must* be implemented
  2. TUNGETFEATURES ioctl() result *must* contain the IFF_VNET_HDR flag
  3. TUNGETIFF ioctl() *must* be implemented; reading the kernel code in drivers/net/tun.c there is no way to test this until after the tap device has been created using TUNSETIFF, and there is no way to change the IFF_VNET_HDR flag after creating the interface, catch-22! However both TUNGETIFF and TUNGETFEATURES were introduced in kernel version 2.6.27, thus we can expect TUNGETIFF to be present if TUNGETFEATURES is.
Parameters:
  • fd (int) - the file descriptor of /dev/net/tun

_OpenTap(vnet_hdr=True)

source code 

Open a new tap device and return its file descriptor.

This is intended to be used by a qemu-type hypervisor together with the -net tap,fd=<fd> command line parameter.

Parameters:
  • vnet_hdr (boolean) - Enable the VNET Header
Returns: tuple
(ifname, tapfd)

Variables Details [hide private]

_SPICE_ADDITIONAL_PARAMS

SPICE parameters which depend on constants.HV_KVM_SPICE_BIND

Value:
frozenset([constants.HV_KVM_SPICE_IP_VERSION, constants.HV_KVM_SPICE_P\
ASSWORD_FILE, constants.HV_KVM_SPICE_LOSSLESS_IMG_COMPR, constants.HV_\
KVM_SPICE_JPEG_IMG_COMPR, constants.HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR, c\
onstants.HV_KVM_SPICE_STREAMING_VIDEO_DETECTION, constants.HV_KVM_SPIC\
E_USE_TLS,])

_DEVICE_RUNTIME_INDEX

Value:
{constants.HOTPLUG_TARGET_DISK: _KVM_DISKS_RUNTIME_INDEX, constants.HO\
TPLUG_TARGET_NIC: _KVM_NICS_RUNTIME_INDEX}

_FIND_RUNTIME_ENTRY

Value:
{constants.HOTPLUG_TARGET_NIC: lambda nic, kvm_nics: [n for n in kvm_n\
ics if n.uuid== nic.uuid], constants.HOTPLUG_TARGET_DISK: lambda disk,\
 kvm_disks: [(d, l, u) for(d, l, u) in kvm_disks if d.uuid== disk.uuid\
]}

_RUNTIME_DEVICE

Value:
{constants.HOTPLUG_TARGET_NIC: lambda d: d, constants.HOTPLUG_TARGET_D\
ISK: lambda(d, e, _): d}

_RUNTIME_ENTRY

Value:
{constants.HOTPLUG_TARGET_NIC: lambda d, e: d, constants.HOTPLUG_TARGE\
T_DISK: lambda d, e:(d, e [0], e [1])}