ganeti :: hypervisor :: hv_xen :: XenHypervisor :: Class XenHypervisor
[hide private]
[frames] | no frames]

Class XenHypervisor

source code


Xen generic hypervisor interface

This is the Xen base class used for both Xen PVM and HVM. It contains all the functionality that is identical for both.

Instance Methods [hide private]
 
__init__(self, _cfgdir=None, _run_cmd_fn=None, _cmd=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_GetCommand(self, hvparams)
Returns Xen command to use.
source code
 
_RunXen(self, args, hvparams, timeout=None)
Wrapper around utils.process.RunCmd to run Xen command.
source code
str
_ConfigFileName(self, instance_name)
Get the config file name for an instance.
source code
 
_WriteConfigFile(self, instance_name, data)
Write the Xen config file for the instance.
source code
 
_ReadConfigFile(self, instance_name)
Returns the contents of the instance config file.
source code
 
_RemoveConfigFile(self, instance_name)
Remove the xen configuration file.
source code
 
_StashConfigFile(self, instance_name)
Move the Xen config file to the log directory and return its new path.
source code
 
_GetInstanceList(self, include_node, hvparams)
Wrapper around module level _GetAllInstanceList.
source code
list of strings
ListInstances(self, hvparams=None)
Get the list of running instances.
source code
(string, string, int, int, HvInstanceState, int)
GetInstanceInfo(self, instance_name, hvparams=None)
Get instance properties.
source code
(string, string, int, int, HypervisorInstanceState, int)
GetAllInstancesInfo(self, hvparams=None)
Get properties of all instances.
source code
 
_MakeConfigFile(self, instance, startup_memory, block_devices)
Gather configuration details and write to disk.
source code
 
StartInstance(self, instance, block_devices, startup_paused)
Start an instance.
source code
 
StopInstance(self, instance, force=False, retry=False, name=None, timeout=None)
Stop an instance.
source code
 
_ShutdownInstance(self, name, hvparams, timeout)
Shutdown an instance if the instance is running.
source code
 
_DestroyInstance(self, name, hvparams)
Destroy an instance if the instance if the instance exists.
source code
 
_DestroyInstanceIfAlive(self, name, hvparams) source code
 
_StopInstance(self, name, force, hvparams, timeout)
Stop an instance.
source code
 
RebootInstance(self, instance)
Reboot an instance.
source code
 
BalloonInstanceMemory(self, instance, mem)
Balloon an instance memory to a certain value.
source code
 
GetNodeInfo(self, hvparams=None)
Return information about the node.
source code
 
Verify(self, hvparams=None)
Verify the hypervisor.
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 an instance migration.
source code
 
MigrateInstance(self, cluster_name, instance, target, live)
Migrate an instance to a target node.
source code
 
_MigrateInstance(self, cluster_name, instance_name, target, port, live, hvparams, _ping_fn=netutils.TcpPing)
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
 
PowercycleNode(self, hvparams=None)
Xen-specific powercycle.
source code
 
_CheckToolstack(self, xen_cmd)
Check whether the given toolstack is available on the node.
source code
 
_CheckToolstackBinary(self, xen_cmd)
Checks whether the xen command's binary is found on the machine.
source code
bool
_CheckToolstackXlConfigured(self)
Checks whether xl is enabled on an xl-capable node.
source code

Inherited from hv_base.BaseHypervisor: CleanupInstance, HotAddDevice, HotDelDevice, HotModDevice, HotplugSupported, VerifyHotplugSupport

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

Class Methods [hide private]
 
_WriteNICInfoFile(cls, instance, idx, nic)
Write the Xen config file for the instance.
source code
 
_InstanceNICDir(cls, instance_name)
Returns 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
 
_GetConfig(cls, instance, startup_memory, block_devices)
Build Xen configuration for an instance.
source code
 
GetInstanceConsole(cls, instance, primary_node, node_group, hvparams, beparams)
Return a command for connecting to the console of an instance.
source code

Inherited from hv_base.BaseHypervisor: CheckParameterSyntax, GetAncillaryFiles, LinuxPowercycle, ValidateParameters

Static Methods [hide private]
 
_GetCommandFromHvparams(hvparams)
Returns the Xen command extracted from the given hvparams.
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)
  REBOOT_RETRY_COUNT = 60
  REBOOT_RETRY_INTERVAL = 10
  _ROOT_DIR = pathutils.RUN_DIR+ "/xen-hypervisor"
  _NICS_DIR = _ROOT_DIR+ "/nic"
  _DIRS = [_ROOT_DIR, _NICS_DIR]
  _INSTANCE_LIST_DELAYS = 0.3, 1.5, 1.0
  _INSTANCE_LIST_TIMEOUT = 5
  ANCILLARY_FILES = [XEND_CONFIG_FILE, XL_CONFIG_FILE, VIF_BRIDG...
  ANCILLARY_FILES_OPT = [XL_CONFIG_FILE,]

Inherited from hv_base.BaseHypervisor: PARAMETERS

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, _cfgdir=None, _run_cmd_fn=None, _cmd=None)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

_GetCommandFromHvparams(hvparams)
Static Method

source code 

Returns the Xen command extracted from the given hvparams.

Parameters:
  • hvparams (dict of strings) - hypervisor parameters

_GetCommand(self, hvparams)

source code 

Returns Xen command to use.

Parameters:
  • hvparams (dict of strings) - hypervisor parameters

_RunXen(self, args, hvparams, timeout=None)

source code 

Wrapper around utils.process.RunCmd to run Xen command.

Parameters:
  • hvparams (dict of strings) - dictionary of hypervisor params
  • timeout (int or None) - if a timeout (in seconds) is specified, the command will be terminated after that number of seconds.

_ConfigFileName(self, instance_name)

source code 

Get the config file name for an instance.

Parameters:
  • instance_name (str) - instance name
Returns: str
fully qualified path to instance config file

_WriteNICInfoFile(cls, instance, idx, nic)
Class Method

source code 

Write the Xen config file for the instance.

This version of the function just writes the config file from static data.

_WriteConfigFile(self, instance_name, data)

source code 

Write the Xen config file for the instance.

This version of the function just writes the config file from static data.

_GetInstanceList(self, include_node, hvparams)

source code 

Wrapper around module level _GetAllInstanceList.

Parameters:
  • hvparams (dict of strings) - hypervisor parameters to be used on this node

ListInstances(self, hvparams=None)

source code 

Get the list of running instances.

Parameters:
  • hvparams (dict of strings) - the instance's hypervisor params
Returns: list of strings
names of running instances
Overrides: hv_base.BaseHypervisor.ListInstances

GetInstanceInfo(self, instance_name, hvparams=None)

source code 

Get instance properties.

Parameters:
  • instance_name (string) - the instance name
  • hvparams (dict of strings) - the instance's hypervisor params
Returns: (string, string, int, int, HvInstanceState, int)
tuple (name, id, memory, vcpus, stat, times)
Overrides: hv_base.BaseHypervisor.GetInstanceInfo

GetAllInstancesInfo(self, hvparams=None)

source code 

Get properties of all instances.

Parameters:
  • hvparams (dict of strings) - hypervisor parameters
Returns: (string, string, int, int, HypervisorInstanceState, int)
list of tuples (name, id, memory, vcpus, state, times)
Overrides: hv_base.BaseHypervisor.GetAllInstancesInfo

_MakeConfigFile(self, instance, startup_memory, block_devices)

source code 

Gather configuration details and write to disk.

See _GetConfig for arguments.

StartInstance(self, instance, block_devices, startup_paused)

source code 

Start an instance.

Overrides: hv_base.BaseHypervisor.StartInstance

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

source code 

Stop an instance.

A soft shutdown can be interrupted. A hard shutdown tries forever.

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
  • timeout - if the parameter is not None, a soft shutdown operation will be killed after the specified number of seconds. A hard (forced) shutdown cannot have a timeout
Raises:
Overrides: hv_base.BaseHypervisor.StopInstance

_ShutdownInstance(self, name, hvparams, timeout)

source code 

Shutdown an instance if the instance is running.

The '-w' flag waits for shutdown to complete which avoids the need to poll in the case where we want to destroy the domain immediately after shutdown.

Parameters:
  • name (string) - name of the instance to stop
  • hvparams (dict of string) - hypervisor parameters of the instance
  • timeout (int or None) - a timeout after which the shutdown command should be killed, or None for no timeout

_DestroyInstance(self, name, hvparams)

source code 

Destroy an instance if the instance if the instance exists.

Parameters:
  • name (string) - name of the instance to destroy
  • hvparams (dict of string) - hypervisor parameters of the instance

_StopInstance(self, name, force, hvparams, timeout)

source code 

Stop an instance.

Parameters:
  • name (string) - name of the instance to destroy
  • force (boolean) - whether to do a "hard" stop (destroy)
  • hvparams (dict of string) - hypervisor parameters of the instance
  • timeout (int or None) - a timeout after which the shutdown command should be killed, or None for no timeout

RebootInstance(self, instance)

source code 

Reboot an instance.

Overrides: hv_base.BaseHypervisor.RebootInstance

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, hvparams=None)

source code 

Return information about the node.

Parameters:
  • hvparams - hypervisor parameters
Returns:
a dict with at least the following keys (memory 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
  • cpu_total: total number of CPUs
  • cpu_dom0: number of CPUs used by the node OS
  • cpu_nodes: number of NUMA domains
  • cpu_sockets: number of physical CPU sockets
Overrides: hv_base.BaseHypervisor.GetNodeInfo

See Also: _GetNodeInfo and _ParseNodeInfo

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

source code 

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

Overrides: hv_base.BaseHypervisor.GetInstanceConsole

Verify(self, hvparams=None)

source code 

Verify the hypervisor.

For Xen, this verifies that the xend process is running.

Parameters:
  • hvparams (dict of strings) - hypervisor parameters to be verified against
Returns:
Problem description if something is wrong, None otherwise
Overrides: hv_base.BaseHypervisor.Verify

MigrationInfo(self, instance)

source code 

Get instance information to perform a migration.

Parameters:
Returns: string
content of the xen config 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 xen config 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 an instance migration.

After a successful migration we write the xen config file. We do nothing on a failure, as we did not change anything at accept time.

Parameters:
  • instance (objects.Instance) - instance whose migration is being finalized
  • info (string) - content of the xen config file on the source node
  • success (boolean) - whether the migration was a success or a failure
Overrides: hv_base.BaseHypervisor.FinalizeMigrationDst

MigrateInstance(self, cluster_name, 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

_MigrateInstance(self, cluster_name, instance_name, target, port, live, hvparams, _ping_fn=netutils.TcpPing)

source code 

Migrate an instance to a target node.

See Also: MigrateInstance for details

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

As MigrateInstance for Xen is still blocking, if this method is called it means that MigrateInstance has completed successfully. So we can safely assume that the migration was successful and notify this fact to the client.

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

PowercycleNode(self, hvparams=None)

source code 

Xen-specific powercycle.

This first does a Linux reboot (which triggers automatically a Xen reboot), and if that fails it tries to do a Xen reboot. The reason we don't try a Xen reboot first is that the xen reboot launches an external command which connects to the Xen hypervisor, and that won't work in case the root filesystem is broken and/or the xend daemon is not working.

Parameters:
  • hvparams (dict of strings) - hypervisor params to be used on this node
Overrides: hv_base.BaseHypervisor.PowercycleNode

_CheckToolstack(self, xen_cmd)

source code 

Check whether the given toolstack is available on the node.

Parameters:
  • xen_cmd (string) - xen command (e.g. 'xm' or 'xl')

_CheckToolstackXlConfigured(self)

source code 

Checks whether xl is enabled on an xl-capable node.

Returns: bool
True if 'xl' is enabled, False otherwise

Class Variable Details [hide private]

ANCILLARY_FILES

Value:
[XEND_CONFIG_FILE, XL_CONFIG_FILE, VIF_BRIDGE_SCRIPT,]