Package ganeti :: Module cmdlib
[hide private]
[frames] | no frames]

Module cmdlib

source code

Module implementing the master-side code.

Classes [hide private]
  LogicalUnit
Logical Unit base class.
  NoHooksLU
Simple LU which runs no hooks.
  LUDestroyCluster
Logical unit for destroying the cluster.
  LUVerifyCluster
Verifies the cluster status.
  LUVerifyDisks
Verifies the cluster disks status.
  LURepairDiskSizes
Verifies the cluster disks sizes.
  LURenameCluster
Rename the cluster.
  LUSetClusterParams
Change the parameters of the cluster.
  LURedistributeConfig
Force the redistribution of cluster configuration.
  LUDiagnoseOS
Logical unit for OS diagnose/query.
  LURemoveNode
Logical unit for removing a node.
  LUQueryNodes
Logical unit for querying nodes.
  LUQueryNodeVolumes
Logical unit for getting volumes on node(s).
  LUAddNode
Logical unit for adding node to the cluster.
  LUSetNodeParams
Modifies the parameters of a node.
  LUQueryClusterInfo
Query cluster configuration.
  LUQueryConfigValues
Return configuration values.
  LUActivateInstanceDisks
Bring up an instance's disks.
  LUDeactivateInstanceDisks
Shutdown an instance's disks.
  LUStartupInstance
Starts an instance.
  LURebootInstance
Reboot an instance.
  LUShutdownInstance
Shutdown an instance.
  LUReinstallInstance
Reinstall an instance.
  LURenameInstance
Rename an instance.
  LURemoveInstance
Remove an instance.
  LUQueryInstances
Logical unit for querying instances.
  LUFailoverInstance
Failover an instance.
  LUMigrateInstance
Migrate an instance.
  LUCreateInstance
Create an instance.
  LUConnectConsole
Connect to an instance's console.
  LUReplaceDisks
Replace the disks of an instance.
  LUGrowDisk
Grow a disk of an instance.
  LUQueryInstanceData
Query runtime instance data.
  LUSetInstanceParams
Modifies an instances's parameters.
  LUQueryExports
Query the exports list
  LUExportInstance
Export an instance to an image in the cluster.
  LURemoveExport
Remove exports related to the named instance.
  TagsLU
Generic tags LU.
  LUGetTags
Returns the tags of a given object.
  LUSearchTags
Searches the tags for a given pattern.
  LUAddTags
Sets a tag on a given object.
  LUDelTags
Delete a list of tags from a given object.
  LUTestDelay
Sleep for a specified amount of time.
  IAllocator
IAllocator framework.
  LUTestAllocator
Run allocator tests.
Functions [hide private]
list
_GetWantedNodes(lu, nodes)
Returns list of checked and expanded node names.
source code
list
_GetWantedInstances(lu, instances)
Returns list of checked and expanded instance names.
source code
 
_CheckOutputFields(static, dynamic, selected)
Checks whether all selected fields are valid.
source code
 
_CheckBooleanOpField(op, name)
Validates boolean opcode parameters.
source code
 
_CheckNodeOnline(lu, node)
Ensure that a given node is online.
source code
 
_CheckNodeNotDrained(lu, node)
Ensure that a given node is not drained.
source code
dict
_BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, memory, vcpus, nics, disk_template, disks, bep, hvp, hypervisor_name)
Builds instance related env variables for hooks
source code
dict
_BuildInstanceHookEnvByObject(lu, instance, override=None)
Builds instance related env variables for hooks from an object.
source code
 
_AdjustCandidatePool(lu)
Adjust the candidate pool after node operations.
source code
 
_CheckInstanceBridgesExist(lu, instance)
Check that the bridges needed by an instance exist.
source code
boolean
_RecursiveCheckIfLVMBased(disk)
Check if the given disk or its children are lvm-based.
source code
 
_WaitForSync(lu, instance, oneshot=False, unlock=False)
Sleep and poll for an instance's disk to sync.
source code
 
_CheckDiskConsistency(lu, dev, node, on_primary, ldisk=False)
Check that mirrors are not degraded.
source code
 
_AssembleInstanceDisks(lu, instance, ignore_secondaries=False, ignore_size=False)
Prepare the block devices for an instance.
source code
 
_StartInstanceDisks(lu, instance, force)
Start the disks of an instance.
source code
 
_SafeShutdownInstanceDisks(lu, instance)
Shutdown block devices of an instance.
source code
 
_ShutdownInstanceDisks(lu, instance, ignore_primary=False)
Shutdown block devices of an instance.
source code
 
_CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name)
Checks if a node has enough free memory.
source code
 
_CreateBlockDev(lu, node, instance, device, force_create, info, force_open)
Create a tree of block devices on a given node.
source code
 
_CreateSingleBlockDev(lu, node, instance, device, info, force_open)
Create a single block device on a given node.
source code
 
_GenerateUniqueNames(lu, exts)
Generate a suitable LV name.
source code
 
_GenerateDRBD8Branch(lu, primary, secondary, size, names, iv_name, p_minor, s_minor)
Generate a drbd8 device complete with its children.
source code
 
_GenerateDiskTemplate(lu, template_name, instance_name, primary_node, secondary_nodes, disk_info, file_storage_dir, file_driver, base_index)
Generate the entire disk layout for a given template type.
source code
 
_GetInstanceInfoText(instance)
Compute that text that should be added to the disk's metadata.
source code
boolean
_CreateDisks(lu, instance)
Create all disks for an instance.
source code
boolean
_RemoveDisks(lu, instance)
Remove all disks for an instance.
source code
 
_ComputeDiskSize(disk_template, disks)
Compute disk size requirements in the volume group
source code
 
_CheckHVParams(lu, nodenames, hvname, hvparams)
Hypervisor parameter validation.
source code

Imports: os, time, re, platform, logging, copy, ssh, utils, errors, hypervisor, locking, constants, objects, serializer, ssconf


Function Details [hide private]

_GetWantedNodes(lu, nodes)

source code 

Returns list of checked and expanded node names.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • nodes (list) - list of node names or None for all nodes
Returns: list
the list of nodes, sorted
Raises:
  • errors.OpProgrammerError - if the nodes parameter is wrong type

_GetWantedInstances(lu, instances)

source code 

Returns list of checked and expanded instance names.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instances (list) - list of instance names or None for all instances
Returns: list
the list of instances, sorted
Raises:

_CheckOutputFields(static, dynamic, selected)

source code 

Checks whether all selected fields are valid.

Parameters:

_CheckBooleanOpField(op, name)

source code 

Validates boolean opcode parameters.

This will ensure that an opcode parameter is either a boolean value, or None (but that it always exists).

_CheckNodeOnline(lu, node)

source code 

Ensure that a given node is online.

Parameters:
  • lu - the LU on behalf of which we make the check
  • node - the node to check
Raises:

_CheckNodeNotDrained(lu, node)

source code 

Ensure that a given node is not drained.

Parameters:
  • lu - the LU on behalf of which we make the check
  • node - the node to check
Raises:

_BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, memory, vcpus, nics, disk_template, disks, bep, hvp, hypervisor_name)

source code 

Builds instance related env variables for hooks

This builds the hook environment from individual variables.

Parameters:
  • name (string) - the name of the instance
  • primary_node (string) - the name of the instance's primary node
  • secondary_nodes (list) - list of secondary nodes as strings
  • os_type (string) - the name of the instance's OS
  • status (boolean) - the should_run status of the instance
  • memory (string) - the memory size of the instance
  • vcpus (string) - the count of VCPUs the instance has
  • nics (list) - list of tuples (ip, bridge, mac) representing the NICs the instance has
  • disk_template (string) - the disk template of the instance
  • disks (list) - the list of (size, mode) pairs
  • bep (dict) - the backend parameters for the instance
  • hvp (dict) - the hypervisor parameters for the instance
  • hypervisor_name (string) - the hypervisor for the instance
Returns: dict
the hook environment for this instance

_BuildInstanceHookEnvByObject(lu, instance, override=None)

source code 

Builds instance related env variables for hooks from an object.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance for which we should build the environment
  • override (dict) - dictionary with key/values that will override our values
Returns: dict
the hook environment dictionary

_RecursiveCheckIfLVMBased(disk)

source code 

Check if the given disk or its children are lvm-based.

Parameters:
Returns: boolean
boolean indicating whether a LD_LV dev_type was found or not

_CheckDiskConsistency(lu, dev, node, on_primary, ldisk=False)

source code 

Check that mirrors are not degraded.

The ldisk parameter, if True, will change the test from the is_degraded attribute (which represents overall non-ok status for the device(s)) to the ldisk (representing the local storage status).

_AssembleInstanceDisks(lu, instance, ignore_secondaries=False, ignore_size=False)

source code 

Prepare the block devices for an instance.

This sets up the block devices on all nodes.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance for whose disks we assemble
  • ignore_secondaries (boolean) - if true, errors on secondary nodes won't result in an error return from the function
  • ignore_size (boolean) - if true, the current known size of the disk will not be used during the disk activation, useful for cases when the size is wrong
Returns:
False if the operation failed, otherwise a list of (host, instance_visible_name, node_visible_name) with the mapping from node devices to instance devices

_SafeShutdownInstanceDisks(lu, instance)

source code 

Shutdown block devices of an instance.

This function checks if an instance is running, before calling _ShutdownInstanceDisks.

_ShutdownInstanceDisks(lu, instance, ignore_primary=False)

source code 

Shutdown block devices of an instance.

This does the shutdown on all nodes of the instance.

If the ignore_primary is false, errors on the primary node are ignored.

_CheckNodeFreeMemory(lu, node, reason, requested, hypervisor_name)

source code 

Checks if a node has enough free memory.

This function check if a given node has the needed amount of free memory. In case the node has less memory or we cannot get the information from the node, this function raise an OpPrereqError exception.

Parameters:
  • lu (LogicalUnit) - a logical unit from which we get configuration data
  • node (str) - the node to check
  • reason (str) - string to use in the error message
  • requested (int) - the amount of memory in MiB to check for
  • hypervisor_name (str) - the hypervisor to ask for memory stats
Raises:

_CreateBlockDev(lu, node, instance, device, force_create, info, force_open)

source code 

Create a tree of block devices on a given node.

If this device type has to be created on secondaries, create it and all its children.

If not, just recurse to children keeping the same 'force' value.

Parameters:
  • lu - the lu on whose behalf we execute
  • node - the node on which to create the device
  • instance (objects.Instance) - the instance which owns the device
  • device (objects.Disk) - the device to create
  • force_create (boolean) - whether to force creation of this device; this will be change to True whenever we find a device which has CreateOnSecondary() attribute
  • info - the extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
  • force_open (boolean) - this parameter will be passes to the backend.BlockdevCreate function where it specifies whether we run on primary or not, and it affects both the child assembly and the device own Open() execution

_CreateSingleBlockDev(lu, node, instance, device, info, force_open)

source code 

Create a single block device on a given node.

This will not recurse over children of the device, so they must be created in advance.

Parameters:
  • lu - the lu on whose behalf we execute
  • node - the node on which to create the device
  • instance (objects.Instance) - the instance which owns the device
  • device (objects.Disk) - the device to create
  • info - the extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
  • force_open (boolean) - this parameter will be passes to the backend.BlockdevCreate function where it specifies whether we run on primary or not, and it affects both the child assembly and the device own Open() execution

_GenerateUniqueNames(lu, exts)

source code 

Generate a suitable LV name.

This will generate a logical volume name for the given instance.

_CreateDisks(lu, instance)

source code 

Create all disks for an instance.

This abstracts away some work from AddInstance.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should create
Returns: boolean
the success of the creation

_RemoveDisks(lu, instance)

source code 

Remove all disks for an instance.

This abstracts away some work from `AddInstance()` and `RemoveInstance()`. Note that in case some of the devices couldn't be removed, the removal will continue with the other ones (compare with `_CreateDisks()`).

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should remove
Returns: boolean
the success of the removal

_CheckHVParams(lu, nodenames, hvname, hvparams)

source code 

Hypervisor parameter validation.

This function abstract the hypervisor parameter validation to be used in both instance create and instance modify.

Parameters:
  • lu (LogicalUnit) - the logical unit for which we check
  • nodenames (list) - the list of nodes on which we should check
  • hvname (string) - the name of the hypervisor we should use
  • hvparams (dict) - the parameters which we need to check
Raises: