ganeti :: hypervisor :: hv_lxc :: LXCHypervisor :: Class LXCHypervisor
[hide private]
[frames] | no frames]

Class LXCHypervisor

source code


LXC-based virtualization.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_EnsureDirectoryExistence(self)
Ensures all the directories needed for LXC use exist.
source code
 
_SaveInstanceStash(self, instance_name, data)
Save data to the instance stash file in serialized format.
source code
 
_LoadInstanceStash(self, instance_name)
Load information stashed in file which was created by _SaveInstanceStash.
source code
 
_CleanupInstance(self, instance_name, stash)
Actual implementation of the instance cleanup procedure.
source code
 
CleanupInstance(self, instance_name)
Cleanup after a stopped instance.
source code
 
ListInstances(self, hvparams=None)
Get the list of running instances.
source code
tuple of strings
GetInstanceInfo(self, instance_name, hvparams=None)
Get instance properties.
source code
tuple of strings
_GetInstanceInfoInner(self, instance_name)
Get instance properties.
source code
(string, string, int, int, HvInstanceState, int)
GetAllInstancesInfo(self, hvparams=None)
Get properties of all instances.
source code
 
_CreateConfigFile(self, instance, sda_dev_path)
Create an lxc.conf file for an instance.
source code
 
_SpawnLXC(self, instance, log_file, conf_file)
Execute lxc-start and wait until container health is confirmed.
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
 
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
 
MigrateInstance(self, cluster_name, instance, target, live)
Migrate an instance.
source code
objects.MigrationStatus
GetMigrationStatus(self, instance)
Get the migration status
source code

Inherited from hv_base.BaseHypervisor: AcceptInstance, FinalizeMigrationDst, FinalizeMigrationSource, HotAddDevice, HotDelDevice, HotModDevice, HotplugSupported, MigrationInfo, VerifyHotplugSupport

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

Class Methods [hide private]
 
_InstanceDir(cls, instance_name)
Return the root directory for an instance.
source code
 
_InstanceConfFilePath(cls, instance_name)
Return the configuration file for an instance.
source code
 
_InstanceLogFilePath(cls, instance)
Return the log file for an instance.
source code
 
_InstanceConsoleLogFilePath(cls, instance_name)
Return the console log file path for an instance.
source code
 
_InstanceStashFilePath(cls, instance_name)
Return the stash file path for an instance.
source code
 
_MountCgroupSubsystem(cls, subsystem)
Mount the cgroup subsystem fs under the cgroup root dir.
source code
 
_GetCgroupMountPoint(cls)
Return the directory that should be the base of cgroup fs.
source code
 
_GetOrPrepareCgroupSubsysMountPoint(cls, subsystem)
Prepare cgroup subsystem mount point.
source code
 
_GetCurrentCgroupSubsysGroups(cls)
Return the dict of cgroup subsystem hierarchies this process belongs to.
source code
string
_GetCgroupSubsysDir(cls, subsystem)
Return the directory of the cgroup subsystem we use.
source code
string
_GetCgroupParamPath(cls, param_name, instance_name=None)
Return the path of the specified cgroup parameter file.
source code
 
_GetCgroupInstanceValue(cls, instance_name, param_name)
Return the value of the specified cgroup parameter.
source code
 
_SetCgroupInstanceValue(cls, instance_name, param_name, param_value)
Set the value to the specified instance cgroup parameter.
source code
boolean
_IsCgroupParameterPresent(cls, parameter, hvparams=None)
Return whether a cgroup parameter can be used.
source code
 
_GetCgroupCpuList(cls, instance_name)
Return the list of CPU ids for an instance.
source code
 
_GetCgroupCpuUsage(cls, instance_name)
Return the CPU usage of an instance.
source code
 
_GetCgroupMemoryLimit(cls, instance_name)
Return the memory limit for an instance
source code
 
_IsInstanceAlive(cls, instance_name)
Return True if instance is alive.
source code
 
_ListAliveInstances(cls)
Return list of alive instances.
source code
 
_GetInstanceDropCapabilities(cls, hvparams)
Get and parse the drop capabilities list from the instance hvparams.
source code
 
_GetCgroupEnabledKernelSubsystems(cls)
Return cgroup subsystems list that are enabled in current kernel.
source code
 
_EnsureCgroupMounts(cls, hvparams=None)
Ensures all cgroup subsystems required to run LXC container are mounted.
source code
 
_PrepareInstanceRootFsBdev(cls, storage_path, stash)
Return mountable path for storage_path.
source code
 
_WaitForInstanceState(cls, instance_name, state, timeout)
Wait for an instance state transition within timeout
source code
 
_VerifyDiskRequirements(cls, block_devices)
Insures that the disks provided work with the current implementation.
source code
 
GetInstanceConsole(cls, instance, primary_node, node_group, hvparams, beparams)
Return a command for connecting to the console of an instance.
source code
LXCVersion
_GetLXCVersionFromCmd(cls, from_cmd)
Return the LXC version currently used in the system.
source code
list(str)
_VerifyLXCCommands(cls)
Verify the validity of lxc command line tools.
source code
 
PowercycleNode(cls, hvparams=None)
LXC powercycle, just a wrapper over Linux powercycle.
source code

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

Static Methods [hide private]

Inherited from hv_base.BaseHypervisor: GetLinuxNodeInfo, VersionsSafeForMigration

Inherited from hv_base.BaseHypervisor (private): _FormatVerifyResults

Class Variables [hide private]
  _ROOT_DIR = pathutils.RUN_DIR+ "/lxc"
  _LOG_DIR = pathutils.LOG_DIR+ "/lxc"
  _INSTANCE_DIR = _ROOT_DIR+ "/instance"
  _CGROUP_ROOT_DIR = _ROOT_DIR+ "/cgroup"
  _PROC_CGROUPS_FILE = "/proc/cgroups"
  _PROC_SELF_CGROUP_FILE = "/proc/self/cgroup"
  _LXC_MIN_VERSION_REQUIRED = LXCVersion("1.0.0")
  _LXC_COMMANDS_REQUIRED = ["lxc-console", "lxc-ls", "lxc-start"...
  _DIR_MODE = 0755
  _STASH_KEY_ALLOCATED_LOOP_DEV = "allocated_loopdev"
  _MEMORY_PARAMETER = "memory.limit_in_bytes"
  _MEMORY_SWAP_PARAMETER = "memory.memsw.limit_in_bytes"
  PARAMETERS = {constants.HV_CPU_MASK: hv_base.OPT_CPU_MASK_CHEC...
a dict of parameter name: check type; the check type is a five-tuple containing:
  _REBOOT_TIMEOUT = 120
  _REQUIRED_CGROUP_SUBSYSTEMS = ["cpuset", "memory", "devices", ...

Inherited from hv_base.BaseHypervisor: ANCILLARY_FILES, ANCILLARY_FILES_OPT, CAN_MIGRATE

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)

_InstanceLogFilePath(cls, instance)
Class Method

source code 

Return the log file for an instance.

Parameters:

_InstanceStashFilePath(cls, instance_name)
Class Method

source code 

Return the stash file path for an instance.

The stash file is used to keep information needed to clean up after the destruction of the instance.

_MountCgroupSubsystem(cls, subsystem)
Class Method

source code 

Mount the cgroup subsystem fs under the cgroup root dir.

Parameters:
  • subsystem (string) - cgroup subsystem name to mount @rtype string @return path of subsystem mount point

_CleanupInstance(self, instance_name, stash)

source code 

Actual implementation of the instance cleanup procedure.

Parameters:
  • instance_name (string) - instance name
  • stash (dict(string:any)) - dict that contains desired information for instance cleanup

CleanupInstance(self, instance_name)

source code 

Cleanup after a stopped instance.

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

_GetOrPrepareCgroupSubsysMountPoint(cls, subsystem)
Class Method

source code 

Prepare cgroup subsystem mount point.

Parameters:
  • subsystem (string) - cgroup subsystem name to mount @rtype string @return path of subsystem mount point

_GetCurrentCgroupSubsysGroups(cls)
Class Method

source code 

Return the dict of cgroup subsystem hierarchies this process belongs to.

The dictionary has the cgroup subsystem as a key and its hierarchy as a value. Information is read from /proc/self/cgroup.

_GetCgroupSubsysDir(cls, subsystem)
Class Method

source code 

Return the directory of the cgroup subsystem we use.

Parameters:
  • subsystem (string) - cgroup subsystem name
Returns: string
path of the hierarchy directory for the subsystem

_GetCgroupParamPath(cls, param_name, instance_name=None)
Class Method

source code 

Return the path of the specified cgroup parameter file.

Parameters:
  • param_name (string) - cgroup subsystem parameter name
Returns: string
path of the cgroup subsystem parameter file

_GetCgroupInstanceValue(cls, instance_name, param_name)
Class Method

source code 

Return the value of the specified cgroup parameter.

Parameters:
  • instance_name (string) - instance name
  • param_name (string) - cgroup subsystem parameter name @rtype string @return value read from cgroup subsystem fs

_SetCgroupInstanceValue(cls, instance_name, param_name, param_value)
Class Method

source code 

Set the value to the specified instance cgroup parameter.

Parameters:
  • instance_name (string) - instance name
  • param_name (string) - cgroup subsystem parameter name
  • param_value (string) - cgroup subsystem parameter value to be set

_IsCgroupParameterPresent(cls, parameter, hvparams=None)
Class Method

source code 

Return whether a cgroup parameter can be used.

This is checked by seeing whether there is a file representation of the parameter in the location where the cgroup is mounted.

Parameters:
  • parameter (string) - The name of the parameter.
  • hvparams - dict
  • hvparams - The hypervisor parameters, optional.
Returns: boolean

ListInstances(self, hvparams=None)

source code 

Get the list 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) - hvparams to be used with this instance
Returns: tuple of strings
(name, id, memory, vcpus, stat, times)
Overrides: hv_base.BaseHypervisor.GetInstanceInfo

_GetInstanceInfoInner(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)

GetAllInstancesInfo(self, hvparams=None)

source code 

Get properties of all instances.

Parameters:
  • hvparams (dict of strings) - hypervisor parameter
Returns: (string, string, int, int, HvInstanceState, int)
[(name, id, memory, vcpus, stat, times),...]
Overrides: hv_base.BaseHypervisor.GetAllInstancesInfo

_GetInstanceDropCapabilities(cls, hvparams)
Class Method

source code 

Get and parse the drop capabilities list from the instance hvparams.

Parameters:
  • hvparams (dict of strings) - instance hvparams @rtype list(string) @return list of drop capabilities

_PrepareInstanceRootFsBdev(cls, storage_path, stash)
Class Method

source code 

Return mountable path for storage_path.

This function creates a partition mapping for storage_path and returns the first partition device path as a rootfs partition, and stashes the loopback device path. If storage_path is not a multi-partition block device, just return storage_path.

_WaitForInstanceState(cls, instance_name, state, timeout)
Class Method

source code 

Wait for an instance state transition within timeout

Return True if an instance state changed to the desired state within timeout secs.

StartInstance(self, instance, block_devices, startup_paused)

source code 

Start an instance.

For LXC, we try to mount the block device and execute 'lxc-start'. We use volatile containers.

Overrides: hv_base.BaseHypervisor.StartInstance

StopInstance(self, instance, force=False, retry=False, name=None, timeout=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
  • 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

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.

See BaseHypervisor.GetLinuxNodeInfo.

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

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

_GetLXCVersionFromCmd(cls, from_cmd)
Class Method

source code 

Return the LXC version currently used in the system.

Version information will be retrieved by command specified by from_cmd.

Parameters:
  • from_cmd (string) - the lxc command used to retrieve version information
Returns: LXCVersion
a version object which represents the version retrieved from the command

_VerifyLXCCommands(cls)
Class Method

source code 

Verify the validity of lxc command line tools.

Returns: list(str)
list of problem descriptions. the blank list will be returned if there is no problem.

Verify(self, hvparams=None)

source code 

Verify the hypervisor.

For the LXC manager, it just checks the existence of the base dir.

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

PowercycleNode(cls, hvparams=None)
Class Method

source code 

LXC powercycle, just a wrapper over Linux powercycle.

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

MigrateInstance(self, cluster_name, instance, target, live)

source code 

Migrate an instance.

Parameters:
  • cluster_name (string) - name of the cluster
  • instance (objects.Instance) - the instance to be migrated
  • target (string) - hostname (usually ip) of the target node
  • live (boolean) - whether to do a live or non-live migration
Overrides: hv_base.BaseHypervisor.MigrateInstance

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

Class Variable Details [hide private]

_LXC_COMMANDS_REQUIRED

Value:
["lxc-console", "lxc-ls", "lxc-start", "lxc-stop", "lxc-wait",]

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_CPU_MASK: hv_base.OPT_CPU_MASK_CHECK, constants.HV_LXC_D\
EVICES: hv_base.NO_CHECK, constants.HV_LXC_DROP_CAPABILITIES: hv_base.\
NO_CHECK, constants.HV_LXC_EXTRA_CGROUPS: hv_base.NO_CHECK, constants.\
HV_LXC_EXTRA_CONFIG: hv_base.NO_CHECK, constants.HV_LXC_NUM_TTYS: hv_b\
ase.REQ_NONNEGATIVE_INT_CHECK, constants.HV_LXC_STARTUP_TIMEOUT: hv_ba\
se.OPT_NONNEGATIVE_INT_CHECK,}

_REQUIRED_CGROUP_SUBSYSTEMS

Value:
["cpuset", "memory", "devices", "cpuacct",]