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

Package hv_kvm

source code

KVM hypervisor

Submodules [hide private]

Classes [hide private]
  HeadRequest
  KVMHypervisor
KVM hypervisor interface
Functions [hide private]
 
_with_qmp(fn)
Wrapper used on hotplug related methods
source code
 
_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
string
_GenerateDeviceHVInfoStr(hvinfo)
Construct the -device option string for hvinfo dict
source code
dict
_GenerateDeviceHVInfo(dev_type, kvm_devid, hv_dev_type, bus_slots)
Helper function to generate hvinfo of a device (disk, NIC)
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
 
_CheckUrl(url)
Check if a given URL exists on the server
source code
Variables [hide private]
  psutil = None
hash(x)
  fdsend = None
hash(x)
  _KVM_NETWORK_SCRIPT = pathutils.CONF_DIR+ "/kvm-vif-bridge"
  _KVM_START_PAUSED_FLAG = "-S"
  _SPICE_ADDITIONAL_PARAMS = frozenset([constants.HV_KVM_SPICE_I...
SPICE parameters which depend on constants.HV_KVM_SPICE_BIND
  _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...
  _DEVICE_TYPE = {constants.HOTPLUG_TARGET_NIC: lambda hvp: hvp ...
  _DEVICE_DRIVER = {constants.HOTPLUG_TARGET_NIC: lambda ht: "vi...
  _DEVICE_BUS = {constants.HOTPLUG_TARGET_NIC: lambda _: _PCI_BU...
  _HOTPLUGGABLE_DEVICE_TYPES = {constants.HOTPLUG_TARGET_NIC: [c...
  _PCI_BUS = "pci.0"
  _SCSI_BUS = "scsi.0"
  _MIGRATION_CAPS_DELIM = ":"

Imports: errno, os, re, tempfile, time, logging, pwd, shutil, urllib2, bitarray, utils, constants, errors, serializer, objects, uidpool, ssconf, netutils, pathutils, hv_base, utils_wrapper, QmpConnection, QmpMessage, MonitorSocket, OpenTap


Function Details [hide private]

_GetDriveURI(disk, link, uri)

source code 

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

Invoked during startup and disk hot-add. In latter case and if no userspace access mode is used it will be overriden with /dev/fdset/<fdset-id> (see HotAddDisk() and AddFd() of QmpConnection).

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()
Returns:
The drive uri to use in kvm option

_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. Since the UUID is too long for a device ID (36 chars vs. 30), we choose to use only the part until the third '-' with a disk/nic prefix. For example if a disk has UUID '932df160-7a22-4067-a566-7e0ca8386133' the resulting device ID would be 'disk-932df160-7a22-4067'.

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

_GenerateDeviceHVInfoStr(hvinfo)

source code 

Construct the -device option string for hvinfo dict

PV disk: virtio-blk-pci,id=disk-1234,bus=pci.0,addr=0x9 PV NIC: virtio-net-pci,id=nic-1234,bus=pci.0,addr=0x9 SG disk: scsi-generic,id=disk-1234,bus=scsi.0,channel=0,scsi-id=1,lun=0

Parameters:
  • hvinfo (dict) - dictionary created by _GenerateDeviceHVInfo()
Returns: string
The constructed string to be passed along with a -device option

_GenerateDeviceHVInfo(dev_type, kvm_devid, hv_dev_type, bus_slots)

source code 

Helper function to generate hvinfo of a device (disk, NIC)

hvinfo will hold all necessary info for generating the -device QEMU option. We have two main buses: a PCI bus and a SCSI bus (created by a SCSI controller on the PCI bus).

In case of PCI devices we add them on a free PCI slot (addr) on the first PCI bus (pci.0), and in case of SCSI devices we decide to put each disk on a different SCSI target (scsi-id) on the first SCSI bus (scsi.0).

Parameters:
  • dev_type (string) - either HOTPLUG_TARGET_DISK or HOTPLUG_TARGET_NIC
  • kvm_devid (string) - the id of the device
  • hv_dev_type (string) - either disk_type or nic_type hvparam
  • bus_slots (dict) - the current slots of the first PCI and SCSI buses
Returns: dict
dict including all necessary info (driver, id, bus and bus location) for generating a -device QEMU option for either a disk or a NIC

_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)

_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)

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])}

_DEVICE_TYPE

Value:
{constants.HOTPLUG_TARGET_NIC: lambda hvp: hvp [constants.HV_NIC_TYPE]\
, constants.HOTPLUG_TARGET_DISK: lambda hvp: hvp [constants.HV_DISK_TY\
PE],}

_DEVICE_DRIVER

Value:
{constants.HOTPLUG_TARGET_NIC: lambda ht: "virtio-net-pci" if ht== con\
stants.HT_NIC_PARAVIRTUAL else ht, constants.HOTPLUG_TARGET_DISK: lamb\
da ht: "virtio-blk-pci" if ht== constants.HT_DISK_PARAVIRTUAL else ht,\
}

_DEVICE_BUS

Value:
{constants.HOTPLUG_TARGET_NIC: lambda _: _PCI_BUS, constants.HOTPLUG_T\
ARGET_DISK: lambda ht: _SCSI_BUS if ht in constants.HT_SCSI_DEVICE_TYP\
ES else _PCI_BUS}

_HOTPLUGGABLE_DEVICE_TYPES

Value:
{constants.HOTPLUG_TARGET_NIC: [constants.HT_NIC_E1000, constants.HT_N\
IC_I82551, constants.HT_NIC_I8259ER, constants.HT_NIC_I85557B, constan\
ts.HT_NIC_NE2K_PCI, constants.HT_NIC_PARAVIRTUAL, constants.HT_NIC_PCN\
ET, constants.HT_NIC_RTL8139,], constants.HOTPLUG_TARGET_DISK: [consta\
nts.HT_DISK_PARAVIRTUAL, constants.HT_DISK_SCSI_BLOCK, constants.HT_DI\
SK_SCSI_GENERIC, constants.HT_DISK_SCSI_HD, constants.HT_DISK_SCSI_CD,\
]}