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

Module hv_xen

source code

Xen hypervisors

Classes [hide private]
  _InstanceCrashed
Instance has reached a violent ending.
  XenHypervisor
Xen generic hypervisor interface
  XenPvmHypervisor
Xen PVM hypervisor interface
  XenHvmHypervisor
Xen HVM hypervisor interface
Functions [hide private]
 
_CreateConfigCpus(cpu_mask)
Create a CPU config string for Xen's config file.
source code
list
_RunInstanceList(fn, instance_list_errors)
Helper function for _GetAllInstanceList to retrieve the list of instances from xen.
source code
 
_ParseInstanceList(lines, include_node)
Parses the output of listing instances by xen.
source code
 
_GetAllInstanceList(fn, include_node, delays, timeout)
Return the list of instances including running and shutdown.
source code
bool
_IsInstanceRunning(instance_info)
Determine whether an instance is running.
source code
 
_IsInstanceShutdown(instance_info)
Determine whether the instance is shutdown.
source code
 
_IgnorePaused(instance_info)
Removes information about whether a Xen state is paused from the state.
source code
 
_IsCrashed(instance_info)
Returns whether an instance is in the crashed Xen state.
source code
hv_base.HvInstanceState
_XenToHypervisorInstanceState(instance_info)
Maps Xen states to hypervisor states.
source code
 
_GetRunningInstanceList(fn, include_node, delays, timeout)
Return the list of running instances.
source code
 
_GetShutdownInstanceList(fn, include_node, delays, timeout)
Return the list of shutdown instances.
source code
 
_ParseNodeInfo(info)
Return information about the node.
source code
dict
_MergeInstanceInfo(info, instance_list)
Updates node information from _ParseNodeInfo with instance info.
source code
 
_GetNodeInfo(info, instance_list)
Combines _MergeInstanceInfo and _ParseNodeInfo.
source code
 
_GetConfigFileDiskData(block_devices, blockdev_prefix, _letters=_DISK_LETTERS)
Get disk directives for Xen config file.
source code
 
_QuoteCpuidField(data)
Add quotes around the CPUID field only if necessary.
source code
 
_ConfigureNIC(instance, seq, nic, tap)
Run the network configuration script for a specified NIC
source code
 
WriteXenConfigEvents(config, hvp) source code
Variables [hide private]
  XEND_CONFIG_FILE = utils.PathJoin(pathutils.XEN_CONFIG_DIR, "x...
  XL_CONFIG_FILE = utils.PathJoin(pathutils.XEN_CONFIG_DIR, "xen...
  VIF_BRIDGE_SCRIPT = utils.PathJoin(pathutils.XEN_CONFIG_DIR, "...
  _DOM0_NAME = "Domain-0"
  _DISK_LETTERS = string.ascii_lowercase
  _FILE_DRIVER_MAP = {constants.FD_LOOP: "file", constants.FD_BL...

Imports: logging, errno, string, shutil, time, StringIO, constants, errors, utils, hv_base, netutils, objects, pathutils


Function Details [hide private]

_RunInstanceList(fn, instance_list_errors)

source code 

Helper function for _GetAllInstanceList to retrieve the list of instances from xen.

Parameters:
  • fn (callable) - Function to query xen for the list of instances
  • instance_list_errors (list) - Error list
Returns: list

_ParseInstanceList(lines, include_node)

source code 

Parses the output of listing instances by xen.

Parameters:
  • lines (list) - Result of retrieving the instance list from xen
  • include_node (boolean) - If True, return information for Dom0
Returns:
list of tuple containing (name, id, memory, vcpus, state, time spent)

_GetAllInstanceList(fn, include_node, delays, timeout)

source code 

Return the list of instances including running and shutdown.

See _RunInstanceList and _ParseInstanceList for parameter details.

_IsInstanceRunning(instance_info)

source code 

Determine whether an instance is running.

An instance is running if it is in the following Xen states: running, blocked, paused, or dying (about to be destroyed / shutdown).

For some strange reason, Xen once printed 'rb----' which does not make any sense because an instance cannot be both running and blocked. Fortunately, for Ganeti 'running' or 'blocked' is the same as 'running'.

A state of nothing '------' means that the domain is runnable but it is not currently running. That means it is in the queue behind other domains waiting to be scheduled to run. http://old-list-archives.xenproject.org/xen-users/2007-06/msg00849.html

A dying instance is about to be removed, but it is still consuming resources, and counts as running.

Parameters:
  • instance_info (string) - Information about instance, as supplied by Xen.
Returns: bool
Whether an instance is running.

_IsInstanceShutdown(instance_info)

source code 

Determine whether the instance is shutdown.

An instance is shutdown when a user shuts it down from within, and we do not remove domains to be able to detect that.

The dying state has been added as a precaution, as Xen's status reporting is weird.

_IgnorePaused(instance_info)

source code 

Removes information about whether a Xen state is paused from the state.

As it turns out, an instance can be reported as paused in almost any condition. Paused instances can be paused, running instances can be paused for scheduling, and any other condition can appear to be paused as a result of races or improbable conditions in Xen's status reporting. As we do not use Xen's pause commands in any way at the time, we can simply ignore the paused field and save ourselves a lot of trouble.

Should we ever use the pause commands, several samples would be needed before we could confirm the domain as paused.

_IsCrashed(instance_info)

source code 

Returns whether an instance is in the crashed Xen state.

When a horrible misconfiguration happens to a Xen domain, it can crash, meaning that it encounters a violent ending. While this state usually flashes only temporarily before the domain is restarted, being able to check for it allows Ganeti not to act confused and do something about it.

_XenToHypervisorInstanceState(instance_info)

source code 

Maps Xen states to hypervisor states.

Parameters:
  • instance_info (string) - Information about instance, as supplied by Xen.
Returns: hv_base.HvInstanceState

_GetRunningInstanceList(fn, include_node, delays, timeout)

source code 

Return the list of running instances.

See _GetAllInstanceList for parameter details.

_GetShutdownInstanceList(fn, include_node, delays, timeout)

source code 

Return the list of shutdown instances.

See _GetAllInstanceList for parameter details.

_ParseNodeInfo(info)

source code 

Return information about the node.

Returns:
a dict with 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
  • nr_cpus: total number of CPUs
  • nr_nodes: in a NUMA system, the number of domains
  • nr_sockets: the number of physical CPU sockets in the node
  • hv_version: the hypervisor version in the form (major, minor)

_MergeInstanceInfo(info, instance_list)

source code 

Updates node information from _ParseNodeInfo with instance info.

Parameters:
  • info (dict) - Result from _ParseNodeInfo
  • instance_list (list of tuples) - list of instance information; one tuple per instance
Returns: dict

_GetNodeInfo(info, instance_list)

source code 

Combines _MergeInstanceInfo and _ParseNodeInfo.

Parameters:
  • instance_list (list of tuples) - list of instance information; one tuple per instance

_GetConfigFileDiskData(block_devices, blockdev_prefix, _letters=_DISK_LETTERS)

source code 

Get disk directives for Xen config file.

This method builds the xen config disk directive according to the given disk_template and block_devices.

Parameters:
  • block_devices - list of tuples (cfdev, rldev):
    • cfdev: dict containing ganeti config disk part
    • rldev: ganeti.block.bdev.BlockDev object
  • blockdev_prefix - a string containing blockdevice prefix, e.g. "sd" for /dev/sda
Returns:
string containing disk directive for xen instance config file

_QuoteCpuidField(data)

source code 

Add quotes around the CPUID field only if necessary.

Xen CPUID fields come in two shapes: LIBXL strings, which need quotes around them, and lists of XEND strings, which don't.

Parameters:
  • data - Either type of parameter.
Returns:
The quoted version thereof.

_ConfigureNIC(instance, seq, nic, tap)

source code 

Run the network configuration script for a specified NIC

See hv_base.ConfigureNIC.

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

Variables Details [hide private]

XEND_CONFIG_FILE

Value:
utils.PathJoin(pathutils.XEN_CONFIG_DIR, "xend-config.sxp")

XL_CONFIG_FILE

Value:
utils.PathJoin(pathutils.XEN_CONFIG_DIR, "xen/xl.conf")

VIF_BRIDGE_SCRIPT

Value:
utils.PathJoin(pathutils.XEN_CONFIG_DIR, "scripts/vif-bridge")

_FILE_DRIVER_MAP

Value:
{constants.FD_LOOP: "file", constants.FD_BLKTAP: "tap:aio", constants.\
FD_BLKTAP2: "tap2:tapdisk:aio",}