ganeti :: hypervisor :: hv_kvm :: KVMHypervisor :: Class KVMHypervisor
[hide private]
[frames] | no frames]

Class KVMHypervisor

source code


KVM hypervisor interface

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
tuple
_InstancePidAlive(self, instance_name)
Returns the instance pidfile, pid, and liveness.
source code
 
_CheckDown(self, instance_name)
Raises an error unless the given instance is down.
source code
dictionary of int:int
_GetVcpuThreadIds(self, instance_name)
Get a mapping of vCPU no.
source code
 
_ExecuteCpuAffinity(self, instance_name, cpu_mask)
Complete CPU pinning.
source code
 
ListInstances(self)
Get the list of running instances.
source code
tuple of strings
GetInstanceInfo(self, instance_name)
Get instance properties.
source code
 
GetAllInstancesInfo(self)
Get properties of all instances.
source code
 
_GenerateKVMRuntime(self, instance, block_devices, startup_paused, kvmhelp)
Generate KVM information to start an instance.
source code
 
_WriteKVMRuntime(self, instance_name, data)
Write an instance's KVM runtime
source code
 
_ReadKVMRuntime(self, instance_name)
Read an instance's KVM runtime
source code
 
_SaveKVMRuntime(self, instance, kvm_runtime)
Save an instance's KVM runtime
source code
 
_LoadKVMRuntime(self, instance, serialized_runtime=None)
Load an instance's KVM runtime
source code
 
_RunKVMCmd(self, name, kvm_cmd, tap_fds=None)
Run the KVM cmd and check for errors
source code
 
_ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, incoming=None)
Execute a KVM cmd, after completing it with some last minute data.
source code
 
StartInstance(self, instance, block_devices, startup_paused)
Start an instance.
source code
 
_CallMonitorCommand(self, instance_name, command)
Invoke a command on the instance monitor.
source code
 
StopInstance(self, instance, force=False, retry=False, name=None)
Stop an instance.
source code
 
CleanupInstance(self, instance_name)
Cleanup after a stopped instance
source code
 
RebootInstance(self, instance)
Reboot an instance.
source code
string
MigrationInfo(self, instance)
Get instance information to perform a migration.
source code
 
AcceptInstance(self, instance, info, target)
Prepare to accept an instance.
source code
 
FinalizeMigrationDst(self, instance, info, success)
Finalize the instance migration on the target node.
source code
 
MigrateInstance(self, instance, target, live)
Migrate an instance to a target node.
source code
 
FinalizeMigrationSource(self, instance, success, live)
Finalize the instance migration on the source node.
source code
objects.MigrationStatus
GetMigrationStatus(self, instance)
Get the migration status
source code
 
BalloonInstanceMemory(self, instance, mem)
Balloon an instance memory to a certain value.
source code
 
GetNodeInfo(self)
Return information about the node.
source code
 
Verify(self)
Verify the hypervisor.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
_InstancePidFile(cls, instance_name)
Returns the instance pidfile.
source code
 
_InstanceUidFile(cls, instance_name)
Returns the instance uidfile.
source code
tuple
_InstancePidInfo(cls, pid)
Check pid file for instance information.
source code
 
_InstanceMonitor(cls, instance_name)
Returns the instance monitor socket name
source code
 
_InstanceSerial(cls, instance_name)
Returns the instance serial socket name
source code
 
_InstanceQmpMonitor(cls, instance_name)
Returns the instance serial QMP socket name
source code
 
_InstanceKVMRuntime(cls, instance_name)
Returns the instance KVM runtime filename
source code
 
_InstanceChrootDir(cls, instance_name)
Returns the name of the KVM chroot dir of the instance
source code
 
_InstanceNICDir(cls, instance_name)
Returns the name of the directory holding the tap device files for a given instance.
source code
 
_InstanceNICFile(cls, instance_name, seq)
Returns the name of the file containing the tap device for a given NIC
source code
 
_InstanceKeymapFile(cls, instance_name)
Returns the name of the file containing the keymap for a given instance
source code
 
_TryReadUidFile(cls, uid_file)
Try to read a uid file
source code
 
_RemoveInstanceRuntimeFiles(cls, pidfile, instance_name)
Removes an instance's rutime sockets/files/dirs.
source code
 
_AssignCpuAffinity(cls, cpu_mask, process_id, thread_dict)
Change CPU affinity for running VM according to given CPU mask.
source code
 
_ParseKVMVersion(cls, text)
Parse the KVM version from the --help output.
source code
 
_GetKVMOutput(cls, kvm_path, option)
Return the output of a kvm invocation
source code
 
_GetKVMVersion(cls, kvm_path)
Return the installed KVM version.
source code
 
_GetDefaultMachineVersion(cls, kvm_path)
Return the default hardware revision (e.g.
source code
 
GetInstanceConsole(cls, instance, hvparams, beparams)
Return a command for connecting to the console of an instance.
source code
 
CheckParameterSyntax(cls, hvparams)
Check the given parameters for validity.
source code
 
ValidateParameters(cls, hvparams)
Check the given parameters for validity.
source code
 
PowercycleNode(cls)
KVM powercycle, just a wrapper over Linux powercycle.
source code

Inherited from hv_base.BaseHypervisor: GetAncillaryFiles, LinuxPowercycle

Static Methods [hide private]
 
_SocatUnixConsoleParams()
Returns the correct parameters for socat
source code
 
_ConfigureNIC(instance, seq, nic, tap)
Run the network configuration script for a specified NIC
source code
 
_VerifyAffinityPackage() source code
int
_BuildAffinityCpuMask(cpu_list)
Create a CPU mask suitable for sched_setaffinity from a list of CPUs.
source code

Inherited from hv_base.BaseHypervisor: GetLinuxNodeInfo

Inherited from hv_base.BaseHypervisor (private): _FormatVerifyResults

Class Variables [hide private]
boolean CAN_MIGRATE = True
whether this hypervisor can do migration (either live or non-live)
  _ROOT_DIR = pathutils.RUN_DIR+ "/kvm-hypervisor"
  _PIDS_DIR = _ROOT_DIR+ "/pid"
  _UIDS_DIR = _ROOT_DIR+ "/uid"
  _CTRL_DIR = _ROOT_DIR+ "/ctrl"
  _CONF_DIR = _ROOT_DIR+ "/conf"
  _NICS_DIR = _ROOT_DIR+ "/nic"
  _KEYMAP_DIR = _ROOT_DIR+ "/keymap"
  _CHROOT_DIR = _ROOT_DIR+ "/chroot"
  _CHROOT_QUARANTINE_DIR = _ROOT_DIR+ "/chroot-quarantine"
  _DIRS = [_ROOT_DIR, _PIDS_DIR, _UIDS_DIR, _CTRL_DIR, _CONF_DIR...
  PARAMETERS = {constants.HV_KVM_PATH: hv_base.REQ_FILE_CHECK, c...
a dict of parameter name: check type; the check type is a five-tuple containing:
  _VIRTIO = "virtio"
  _VIRTIO_NET_PCI = "virtio-net-pci"
  _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)...
  _MIGRATION_PROGRESS_RE = re.compile(r"\s*transferred\s+ram:\s+...
  _MIGRATION_INFO_MAX_BAD_ANSWERS = 5
  _MIGRATION_INFO_RETRY_DELAY = 2
  _VERSION_RE = re.compile(r"\b(\d+)\.(\d+)(\.(\d+))?\b")
  _CPU_INFO_RE = re.compile(r"cpu\s+\#(\d+).*thread_id\s*=\s*(\d...
  _CPU_INFO_CMD = "info cpus"
  _CONT_CMD = "cont"
  _DEFAULT_MACHINE_VERSION_RE = re.compile(r"^(\S+).*\(default\)...
  _CHECK_MACHINE_VERSION_RE = staticmethod(lambda x: re.compile(...
  _QMP_RE = re.compile(r"^-qmp\s", re.M)
  _SPICE_RE = re.compile(r"^-spice\s", re.M)
  _VHOST_RE = re.compile(r"^-net\s.*,vhost=on|off", re.M)
  _ENABLE_KVM_RE = re.compile(r"^-enable-kvm\s", re.M)
  _DISABLE_KVM_RE = re.compile(r"^-disable-kvm\s", re.M)
  _NETDEV_RE = re.compile(r"^-netdev\s", re.M)
  _DISPLAY_RE = re.compile(r"^-display\s", re.M)
  _MACHINE_RE = re.compile(r"^-machine\s", re.M)
  _NEW_VIRTIO_RE = re.compile(r"^name \"%s\"" % _VIRTIO_NET_PCI,...
  _BOOT_RE = re.compile(r"^-drive\s([^-]|(?<!^)-)*,boot=on\|off"...
  ANCILLARY_FILES = [_KVM_NETWORK_SCRIPT,]
  ANCILLARY_FILES_OPT = [_KVM_NETWORK_SCRIPT,]
  _KVMOPT_HELP = "help"
  _KVMOPT_MLIST = "mlist"
  _KVMOPT_DEVICELIST = "devicelist"
  _KVMOPTS_CMDS = {_KVMOPT_HELP:(["--help"], False), _KVMOPT_MLI...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_InstancePidInfo(cls, pid)
Class Method

source code 

Check pid file for instance information.

Check that a pid file is associated with an instance, and retrieve information from its command line.

Parameters:
  • pid (string or int) - process id of the instance to check
Returns: tuple
(instance_name, memory, vcpus)
Raises:

_InstancePidAlive(self, instance_name)

source code 

Returns the instance pidfile, pid, and liveness.

Parameters:
  • instance_name (string) - instance name
Returns: tuple
(pid file name, pid, liveness)

_SocatUnixConsoleParams()
Static Method

source code 

Returns the correct parameters for socat

If we have a new-enough socat we can use raw mode with an escape character.

_ConfigureNIC(instance, seq, nic, tap)
Static Method

source code 

Run the network configuration script for a specified NIC

Parameters:
  • instance (instance object) - instance we're acting on
  • seq (int) - nic sequence number
  • nic (nic object) - nic we're acting on
  • tap (str) - the host's tap interface this NIC corresponds to

_BuildAffinityCpuMask(cpu_list)
Static Method

source code 

Create a CPU mask suitable for sched_setaffinity from a list of CPUs.

See man taskset for more info on sched_setaffinity masks. For example: [ 0, 2, 5, 6 ] will return 101 (0x65, 0..01100101).

Parameters:
  • cpu_list (list of int) - list of physical CPU numbers to map to vCPUs in order
Returns: int
a bit mask of CPU affinities

_AssignCpuAffinity(cls, cpu_mask, process_id, thread_dict)
Class Method

source code 

Change CPU affinity for running VM according to given CPU mask.

Parameters:
  • cpu_mask (string) - CPU mask as given by the user. e.g. "0-2,4:all:1,3"
  • process_id (int) - process ID of KVM process. Used to pin entire VM to physical CPUs.
  • thread_dict (dict int:int) - map of virtual CPUs to KVM thread IDs

_GetVcpuThreadIds(self, instance_name)

source code 

Get a mapping of vCPU no. to thread IDs for the instance

Parameters:
  • instance_name (string) - instance in question
Returns: dictionary of int:int
a dictionary mapping vCPU numbers to thread IDs

_ExecuteCpuAffinity(self, instance_name, cpu_mask)

source code 

Complete CPU pinning.

Parameters:
  • instance_name (string) - name of instance
  • cpu_mask (string) - CPU pinning mask as entered by user

ListInstances(self)

source code 

Get the list of running instances.

We can do this by listing our live instances directory and checking whether the associated kvm process is still alive.

Overrides: hv_base.BaseHypervisor.ListInstances

GetInstanceInfo(self, instance_name)

source code 

Get instance properties.

Parameters:
  • instance_name (string) - the instance name
Returns: tuple of strings
(name, id, memory, vcpus, stat, times)
Overrides: hv_base.BaseHypervisor.GetInstanceInfo

GetAllInstancesInfo(self)

source code 

Get properties of all instances.

Returns:
list of tuples (name, id, memory, vcpus, stat, times)
Overrides: hv_base.BaseHypervisor.GetAllInstancesInfo

_GenerateKVMRuntime(self, instance, block_devices, startup_paused, kvmhelp)

source code 

Generate KVM information to start an instance.

Parameters:
  • kvmhelp (string) - output of kvm --help

Attention: this function must not have any side-effects; for example, it must not write to the filesystem, or read values from the current system the are expected to differ between nodes, since it is only run once at instance startup; actions/kvm arguments that can vary between systems should be done in _ExecuteKVMRuntime

_RunKVMCmd(self, name, kvm_cmd, tap_fds=None)

source code 

Run the KVM cmd and check for errors

Parameters:
  • name (string) - instance name
  • kvm_cmd (list of strings) - runcmd input for kvm
  • tap_fds (list of int) - fds of tap devices opened by Ganeti

_ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, incoming=None)

source code 

Execute a KVM cmd, after completing it with some last minute data.

Parameters:
  • incoming (tuple of strings) - (target_host_ip, port)
  • kvmhelp (string) - output of kvm --help

StartInstance(self, instance, block_devices, startup_paused)

source code 

Start an instance.

Overrides: hv_base.BaseHypervisor.StartInstance

_ParseKVMVersion(cls, text)
Class Method

source code 

Parse the KVM version from the --help output.

Parameters:
  • text (string) - output of kvm --help
Returns:
(version, v_maj, v_min, v_rev)
Raises:

_GetKVMOutput(cls, kvm_path, option)
Class Method

source code 

Return the output of a kvm invocation

Parameters:
  • kvm_path (string) - path to the kvm executable
  • option (a key of _KVMOPTS_CMDS) - kvm option to fetch the output from
Returns:
output a supported kvm invocation
Raises:

_GetKVMVersion(cls, kvm_path)
Class Method

source code 

Return the installed KVM version.

Returns:
(version, v_maj, v_min, v_rev)
Raises:

_GetDefaultMachineVersion(cls, kvm_path)
Class Method

source code 

Return the default hardware revision (e.g. pc-1.1)

StopInstance(self, instance, force=False, retry=False, name=None)

source code 

Stop an instance.

Parameters:
  • instance - instance to stop
  • force - whether to do a "hard" stop (destroy)
  • retry - whether this is just a retry call
  • name - if this parameter is passed, the the instance object should not be used (will be passed as None), and the shutdown must be done by name only
Overrides: hv_base.BaseHypervisor.StopInstance

CleanupInstance(self, instance_name)

source code 

Cleanup after a stopped instance

Parameters:
  • instance_name - instance name to cleanup after
Overrides: hv_base.BaseHypervisor.CleanupInstance

RebootInstance(self, instance)

source code 

Reboot an instance.

Overrides: hv_base.BaseHypervisor.RebootInstance

MigrationInfo(self, instance)

source code 

Get instance information to perform a migration.

Parameters:
Returns: string
content of the KVM runtime file
Overrides: hv_base.BaseHypervisor.MigrationInfo

AcceptInstance(self, instance, info, target)

source code 

Prepare to accept an instance.

Parameters:
  • instance (objects.Instance) - instance to be accepted
  • info (string) - content of the KVM runtime file on the source node
  • target (string) - target host (usually ip), on this node
Overrides: hv_base.BaseHypervisor.AcceptInstance

FinalizeMigrationDst(self, instance, info, success)

source code 

Finalize the instance migration on the target node.

Stop the incoming mode KVM.

Parameters:
Overrides: hv_base.BaseHypervisor.FinalizeMigrationDst

MigrateInstance(self, instance, target, live)

source code 

Migrate an instance to a target node.

The migration will not be attempted if the instance is not currently running.

Parameters:
  • instance (objects.Instance) - the instance to be migrated
  • target (string) - ip address of the target node
  • live (boolean) - perform a live migration
Overrides: hv_base.BaseHypervisor.MigrateInstance

FinalizeMigrationSource(self, instance, success, live)

source code 

Finalize the instance migration on the source node.

Parameters:
  • instance (objects.Instance) - the instance that was migrated
  • success (bool) - whether the migration succeeded or not
  • live (bool) - whether the user requested a live migration or not
Overrides: hv_base.BaseHypervisor.FinalizeMigrationSource

GetMigrationStatus(self, instance)

source code 

Get the migration status

Parameters:
Returns: objects.MigrationStatus
the status of the current migration (one of constants.HV_MIGRATION_VALID_STATUSES), plus any additional progress info that can be retrieved from the hypervisor
Overrides: hv_base.BaseHypervisor.GetMigrationStatus

BalloonInstanceMemory(self, instance, mem)

source code 

Balloon an instance memory to a certain value.

Parameters:
  • instance (objects.Instance) - instance to be accepted
  • mem (int) - actual memory size to use for instance runtime
Overrides: hv_base.BaseHypervisor.BalloonInstanceMemory

GetNodeInfo(self)

source code 

Return information about the node.

Returns:
a dict with the following keys (values in MiB):
  • memory_total: the total memory size on the node
  • memory_free: the available memory on the node for instances
  • memory_dom0: the memory used by the node itself, if available
  • hv_version: the hypervisor version in the form (major, minor, revision)
Overrides: hv_base.BaseHypervisor.GetNodeInfo

GetInstanceConsole(cls, instance, hvparams, beparams)
Class Method

source code 

Return a command for connecting to the console of an instance.

Overrides: hv_base.BaseHypervisor.GetInstanceConsole

Verify(self)

source code 

Verify the hypervisor.

Check that the required binaries exist.

Returns:
Problem description if something is wrong, None otherwise
Overrides: hv_base.BaseHypervisor.Verify

CheckParameterSyntax(cls, hvparams)
Class Method

source code 

Check the given parameters for validity.

Parameters:
  • hvparams (dict) - dictionary with parameter names/value
Raises:
Overrides: hv_base.BaseHypervisor.CheckParameterSyntax

ValidateParameters(cls, hvparams)
Class Method

source code 

Check the given parameters for validity.

Parameters:
  • hvparams (dict) - dictionary with parameter names/value
Raises:
Overrides: hv_base.BaseHypervisor.ValidateParameters

PowercycleNode(cls)
Class Method

source code 

KVM powercycle, just a wrapper over Linux powercycle.

Overrides: hv_base.BaseHypervisor.PowercycleNode

Class Variable Details [hide private]

_DIRS

Value:
[_ROOT_DIR, _PIDS_DIR, _UIDS_DIR, _CTRL_DIR, _CONF_DIR, _NICS_DIR, _CH\
ROOT_DIR, _CHROOT_QUARANTINE_DIR, _KEYMAP_DIR]

PARAMETERS

a dict of parameter name: check type; the check type is a five-tuple containing:
  • the required flag (boolean)
  • a function to check for syntax, that will be used in CheckParameterSyntax, in the master daemon process
  • an error message for the above function
  • a function to check for parameter validity on the remote node, in the ValidateParameters function
  • an error message for the above function
Value:
{constants.HV_KVM_PATH: hv_base.REQ_FILE_CHECK, constants.HV_KERNEL_PA\
TH: hv_base.OPT_FILE_CHECK, constants.HV_INITRD_PATH: hv_base.OPT_FILE\
_CHECK, constants.HV_ROOT_PATH: hv_base.NO_CHECK, constants.HV_KERNEL_\
ARGS: hv_base.NO_CHECK, constants.HV_ACPI: hv_base.NO_CHECK, constants\
.HV_SERIAL_CONSOLE: hv_base.NO_CHECK, constants.HV_SERIAL_SPEED: hv_ba\
se.NO_CHECK, constants.HV_VNC_BIND_ADDRESS:(False, lambda x:(netutils.\
IP4Address.IsValid(x) or utils.IsNormAbsPath(x)), "the VNC bind addres\
s must be either a valid IP address or an absolute" " pathname", None,\
...

_MIGRATION_STATUS_RE

Value:
re.compile("Migration\s+status:\s+(\w+)", re.M | re.I)

_MIGRATION_PROGRESS_RE

Value:
re.compile(r"\s*transferred\s+ram:\s+(?P<transferred>\d+)\s+kbytes\s*\\
n" r"\s*remaining\s+ram:\s+(?P<remaining>\d+)\s+kbytes\s*\n" r"\s*tota\
l\s+ram:\s+(?P<total>\d+)\s+kbytes\s*\n", re.I)

_CPU_INFO_RE

Value:
re.compile(r"cpu\s+\#(\d+).*thread_id\s*=\s*(\d+)", re.I)

_DEFAULT_MACHINE_VERSION_RE

Value:
re.compile(r"^(\S+).*\(default\)", re.M)

_CHECK_MACHINE_VERSION_RE

Value:
staticmethod(lambda x: re.compile(r"^(%s)[ ]+.*PC" % x, re.M))

_NEW_VIRTIO_RE

Value:
re.compile(r"^name \"%s\"" % _VIRTIO_NET_PCI, re.M)

_BOOT_RE

Value:
re.compile(r"^-drive\s([^-]|(?<!^)-)*,boot=on\|off", re.M | re.S)

_KVMOPTS_CMDS

Value:
{_KVMOPT_HELP:(["--help"], False), _KVMOPT_MLIST:(["-M", "?"], False),\
 _KVMOPT_DEVICELIST:(["-device", "?"], True),}