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 x.__class__.__doc__ 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
 
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)
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, incoming=None)
Execute a KVM cmd, after completing it with some last minute data
source code
 
StartInstance(self, instance, block_devices)
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
 
FinalizeMigration(self, instance, info, success)
Finalize an instance migration.
source code
 
MigrateInstance(self, instance, target, live)
Migrate an instance to a target node.
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
 
_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
 
_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
 
_GetKVMVersion(cls)
Return the installed KVM version
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

Inherited from hv_base.BaseHypervisor: GetLinuxNodeInfo

Class Variables [hide private]
boolean CAN_MIGRATE = True
whether this hypervisor can do migration (either live or non-live)
  _ROOT_DIR = constants.RUN_GANETI_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"
  _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_KERNEL_PATH: hv_base.OPT_FILE_CHECK...
a dict of parameter name: check type; the check type is a five-tuple containing:
  _MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)...
  _MIGRATION_INFO_MAX_BAD_ANSWERS = 5
  _MIGRATION_INFO_RETRY_DELAY = 2
  _VERSION_RE = re.compile(r"\b(\d+)\.(\d+)\.(\d+)\b")
  ANCILLARY_FILES = [_KVM_NETWORK_SCRIPT,]
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ 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

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

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

StartInstance(self, instance, block_devices)

source code 

Start an instance.

Overrides: hv_base.BaseHypervisor.StartInstance

_GetKVMVersion(cls)
Class Method

source code 

Return the installed KVM version

Returns:
(version, v_maj, v_min, v_rev), or None

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

FinalizeMigration(self, instance, info, success)

source code 

Finalize an instance migration.

Stop the incoming mode KVM.

Parameters:
Overrides: hv_base.BaseHypervisor.FinalizeMigration

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

GetNodeInfo(self)

source code 

Return information about the node.

This is just a wrapper over the base GetLinuxNodeInfo method.

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
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 binary exists.

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]

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_KERNEL_PATH: hv_base.OPT_FILE_CHECK, constants.HV_INITRD\
_PATH: hv_base.OPT_FILE_CHECK, constants.HV_ROOT_PATH: hv_base.NO_CHEC\
K, constants.HV_KERNEL_ARGS: hv_base.NO_CHECK, constants.HV_ACPI: hv_b\
ase.NO_CHECK, constants.HV_SERIAL_CONSOLE: hv_base.NO_CHECK, constants\
.HV_VNC_BIND_ADDRESS:(False, lambda x:(netutils.IP4Address.IsValid(x) \
or utils.IsNormAbsPath(x)), "the VNC bind address must be either a val\
id IP address or an absolute" " pathname", None, None), constants.HV_V\
NC_TLS: hv_base.NO_CHECK, constants.HV_VNC_X509: hv_base.OPT_DIR_CHECK\
...

_MIGRATION_STATUS_RE

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