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.
  Tasklet
Tasklet base class.
  LUPostInitCluster
Logical unit for running hooks after cluster initialization.
  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).
  LUQueryNodeStorage
Logical unit for getting information on storage units on node(s).
  LUModifyNodeStorage
Logical unit for modifying a storage volume on a node.
  LUAddNode
Logical unit for adding node to the cluster.
  LUSetNodeParams
Modifies the parameters of a node.
  LUPowercycleNode
Powercycles 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.
  LURecreateInstanceDisks
Recreate an instance's missing disks.
  LURenameInstance
Rename an instance.
  LURemoveInstance
Remove an instance.
  LUQueryInstances
Logical unit for querying instances.
  LUFailoverInstance
Failover an instance.
  LUMigrateInstance
Migrate an instance.
  LUMoveInstance
Move an instance by data-copying.
  LUMigrateNode
Migrate all instances from a node.
  TLMigrateInstance
Tasklet class for instance migration.
  LUCreateInstance
Create an instance.
  LUConnectConsole
Connect to an instance's console.
  LUReplaceDisks
Replace the disks of an instance.
  TLReplaceDisks
Replaces disks for an instance.
  LURepairNodeStorage
Repairs the volume group on a node.
  LUNodeEvacuationStrategy
Computes the node evacuation strategy.
  LUGrowDisk
Grow a disk of an instance.
  LUQueryInstanceData
Query runtime instance data.
  LUSetInstanceParams
Modifies an instances's parameters.
  LUQueryExports
Query the exports list
  LUPrepareExport
Prepares an instance for an export and returns useful information.
  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.
  LUTestJobqueue
Utility LU to test some aspects of the job queue.
  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
dict
_GetUpdatedParams(old_params, update_dict, use_default=True, use_none=False)
Return the new version of a parameter dictionary.
source code
 
_CheckOutputFields(static, dynamic, selected)
Checks whether all selected fields are valid.
source code
 
_CheckGlobalHvParams(params)
Validates that given hypervisor params are not global ones.
source code
 
_CheckNodeOnline(lu, node, msg=None)
Ensure that a given node is online.
source code
 
_CheckNodeNotDrained(lu, node)
Ensure that a given node is not drained.
source code
 
_CheckNodeVmCapable(lu, node)
Ensure that a given node is vm capable.
source code
 
_CheckNodeHasOS(lu, node, os_name, force_variant)
Ensure that a node supports a given OS.
source code
 
_CheckNodeHasSecondaryIP(lu, node, secondary_ip, prereq)
Ensure that a node has the given secondary ip.
source code
 
_RequireFileStorage()
Checks that file storage is enabled.
source code
 
_CheckDiskTemplate(template)
Ensure a given disk template is valid.
source code
 
_CheckStorageType(storage_type)
Ensure a given storage type is valid.
source code
 
_GetClusterDomainSecret()
Reads the cluster domain secret.
source code
 
_CheckInstanceDown(lu, instance, reason)
Ensure that an instance is not running.
source code
 
_ExpandItemName(fn, name, kind)
Expand an item name.
source code
 
_ExpandNodeName(cfg, name)
Wrapper over _ExpandItemName for nodes.
source code
 
_ExpandInstanceName(cfg, name)
Wrapper over _ExpandItemName for instance.
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
 
_NICListToTuple(lu, nics)
Build a list of nic information tuples.
source code
dict
_BuildInstanceHookEnvByObject(lu, instance, override=None)
Builds instance related env variables for hooks from an object.
source code
 
_AdjustCandidatePool(lu, exceptions)
Adjust the candidate pool after node operations.
source code
 
_DecideSelfPromotion(lu, exceptions=None)
Decide whether I should promote myself as a master candidate.
source code
 
_CheckNicsBridgesExist(lu, target_nics, target_node)
Check that the brigdes needed by a list of nics exist.
source code
 
_CheckInstanceBridgesExist(lu, instance, node=None)
Check that the brigdes needed by an instance exist.
source code
 
_CheckOSVariant(os_obj, name)
Check whether an OS name conforms to the os variants specification.
source code
 
_GetNodeInstancesInner(cfg, fn) source code
 
_GetNodeInstances(cfg, node_name)
Returns a list of all primary and secondary instances on a node.
source code
 
_GetNodePrimaryInstances(cfg, node_name)
Returns primary instances on a node.
source code
 
_GetNodeSecondaryInstances(cfg, node_name)
Returns secondary instances on a node.
source code
 
_GetStorageTypeArgs(cfg, storage_type)
Returns the arguments for a storage type.
source code
 
_FindFaultyInstanceDisks(cfg, rpc, instance, node_name, prereq) source code
 
_CheckIAllocatorOrNode(lu, iallocator_slot, node_slot)
Check the sanity of iallocator and node arguments and use the cluster-wide iallocator if appropriate.
source code
 
_VerifyCertificate(filename)
Verifies a certificate for LUVerifyCluster.
source code
 
_UploadHelper(lu, nodes, fname)
Helper for uploading a file and showing warnings.
source code
 
_RedistributeAncillaryFiles(lu, additional_nodes=None, additional_vm=True)
Distribute additional files which are part of the cluster configuration.
source code
 
_WaitForSync(lu, instance, disks=None, oneshot=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, disks=None, 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, disks=None)
Shutdown block devices of an instance.
source code
list of objects.Disk
_ExpandCheckDisks(instance, disks)
Return the instance disks selected by the disks list
source code
 
_ShutdownInstanceDisks(lu, instance, disks=None, 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
 
_CheckNodesFreeDisk(lu, nodenames, requested)
Checks if nodes have enough free disk space in the default VG.
source code
 
_RemoveInstance(lu, feedback_fn, instance, ignore_failures)
Utility function to remove an instance.
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
 
_CalcEta(time_taken, written, total_size)
Calculates the ETA based on size written and total size.
source code
 
_WipeDisks(lu, instance)
Wipes instance disks.
source code
boolean
_CreateDisks(lu, instance, to_skip=None, target_node=None)
Create all disks for an instance.
source code
boolean
_RemoveDisks(lu, instance, target_node=None)
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
 
_CheckOSParams(lu, required, nodenames, osname, osparams)
OS parameters validation.
source code
Variables [hide private]
  _POutputFields = "output_fields", ht.NoDefault, ht.TListOf(ht....
output fields for a query operation
  _PShutdownTimeout = "shutdown_timeout", constants.DEFAULT_SHUT...
the shutdown timeout
  _PForce = "force", False, ht.TBool
the force parameter
  _PInstanceName = "instance_name", ht.NoDefault, ht.TNonEmptySt...
a required instance name (for single-instance LUs)
  _PIgnoreOfflineNodes = "ignore_offline_nodes", False, ht.TBool
Whether to ignore offline nodes
  _PNodeName = "node_name", ht.NoDefault, ht.TNonEmptyString
a required node name (for single-node LUs)
  _PMigrationMode = "mode", None, ht.TOr(ht.TNone, ht.TElemOf(co...
the migration type (live/non-live)
  _PMigrationLive = "live", None, ht.TMaybeBool
the obsolete 'live' mode (boolean)

Imports: os, time, re, platform, logging, copy, OpenSSL, socket, tempfile, shutil, ssh, utils, errors, hypervisor, locking, constants, objects, serializer, ssconf, uidpool, compat, masterd, netutils, ht, ganeti


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:

_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:

_GetUpdatedParams(old_params, update_dict, use_default=True, use_none=False)

source code 

Return the new version of a parameter dictionary.

Parameters:
  • old_params (dict) - old parameters
  • update_dict (dict) - dict containing new parameter values, or constants.VALUE_DEFAULT to reset the parameter to its default value
  • use_default (whether to recognise constants.VALUE_DEFAULT values as 'to be deleted' values) - boolean
  • use_none (whether to recognise None values as 'to be deleted' values) - boolean
Returns: dict
the new parameter dictionary

_CheckOutputFields(static, dynamic, selected)

source code 

Checks whether all selected fields are valid.

Parameters:

_CheckGlobalHvParams(params)

source code 

Validates that given hypervisor params are not global ones.

This will ensure that instances don't get customised versions of global params.

_CheckNodeOnline(lu, node, msg=None)

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
  • msg - if passed, should be a message to replace the default one
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:

_CheckNodeVmCapable(lu, node)

source code 

Ensure that a given node is vm capable.

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

_CheckNodeHasOS(lu, node, os_name, force_variant)

source code 

Ensure that a node supports a given OS.

Parameters:
  • lu - the LU on behalf of which we make the check
  • node - the node to check
  • os_name - the OS to query about
  • force_variant - whether to ignore variant errors
Raises:

_CheckNodeHasSecondaryIP(lu, node, secondary_ip, prereq)

source code 

Ensure that a node has the given secondary ip.

Parameters:
  • lu (LogicalUnit) - the LU on behalf of which we make the check
  • node (string) - the node to check
  • secondary_ip (string) - the ip to check
  • prereq (boolean) - whether to throw a prerequisite or an execute error
Raises:

_RequireFileStorage()

source code 

Checks that file storage is enabled.

Raises:

_ExpandItemName(fn, name, kind)

source code 

Expand an item name.

Parameters:
  • fn - the function to use for expansion
  • name - requested item name
  • kind - text description ('Node' or 'Instance')
Returns:
the resolved (full) name
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, mac, mode, link) 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

_NICListToTuple(lu, nics)

source code 

Build a list of nic information tuples.

This list is suitable to be passed to _BuildInstanceHookEnv or as a return value in LUQueryInstanceData.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • nics (list of objects.NIC) - list of nics to convert to hooks tuples

_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

_CheckOSVariant(os_obj, name)

source code 

Check whether an OS name conforms to the os variants specification.

Parameters:
  • os_obj (objects.OS) - OS object to check
  • name (string) - OS name passed by the user, to check for validity

_CheckIAllocatorOrNode(lu, iallocator_slot, node_slot)

source code 

Check the sanity of iallocator and node arguments and use the cluster-wide iallocator if appropriate.

Check that at most one of (iallocator, node) is specified. If none is specified, then the LU's opcode's iallocator slot is filled with the cluster-wide default iallocator.

Parameters:
  • iallocator_slot (string) - the name of the opcode iallocator slot
  • node_slot (string) - the name of the opcode target node slot

_VerifyCertificate(filename)

source code 

Verifies a certificate for LUVerifyCluster.

Parameters:
  • filename (string) - Path to PEM file

_RedistributeAncillaryFiles(lu, additional_nodes=None, additional_vm=True)

source code 

Distribute additional files which are part of the cluster configuration.

ConfigWriter takes care of distributing the config and ssconf files, but there are more files which should be distributed to all nodes. This function makes sure those are copied.

Parameters:
  • lu - calling logical unit
  • additional_nodes - list of nodes not in the config to distribute to
  • additional_vm (boolean) - whether the additional nodes are vm-capable 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, disks=None, 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
  • disks (list of objects.Disk or None) - which disks to assemble (or all, if None)
  • 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, disks=None)

source code 

Shutdown block devices of an instance.

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

_ExpandCheckDisks(instance, disks)

source code 

Return the instance disks selected by the disks list

Parameters:
Returns: list of objects.Disk
selected instance disks to act on

_ShutdownInstanceDisks(lu, instance, disks=None, 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:

_CheckNodesFreeDisk(lu, nodenames, requested)

source code 

Checks if nodes have enough free disk space in the default VG.

This function check if all given nodes have the needed amount of free disk. In case any node has less disk 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
  • nodenames (list) - the list of node names to check
  • requested (int) - the amount of disk in MiB to check for
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.

_CalcEta(time_taken, written, total_size)

source code 

Calculates the ETA based on size written and total size.

Parameters:
  • time_taken - The time taken so far
  • written - amount written so far
  • total_size - The total size of data to be written
Returns:
The remaining time in seconds

_WipeDisks(lu, instance)

source code 

Wipes instance disks.

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

_CreateDisks(lu, instance, to_skip=None, target_node=None)

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
  • to_skip (list) - list of indices to skip
  • target_node (string) - if passed, overrides the target node for creation
Returns: boolean
the success of the creation

_RemoveDisks(lu, instance, target_node=None)

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
  • target_node (string) - used to override the node on which to remove the disks
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:

_CheckOSParams(lu, required, nodenames, osname, osparams)

source code 

OS parameters validation.

Parameters:
  • lu (LogicalUnit) - the logical unit for which we check
  • required (boolean) - whether the validation should fail if the OS is not found
  • nodenames (list) - the list of nodes on which we should check
  • osname (string) - the name of the hypervisor we should use
  • osparams (dict) - the parameters which we need to check
Raises:

Variables Details [hide private]

_POutputFields

output fields for a query operation

Value:
"output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)

_PShutdownTimeout

the shutdown timeout

Value:
"shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveIn\
t

_PInstanceName

a required instance name (for single-instance LUs)

Value:
"instance_name", ht.NoDefault, ht.TNonEmptyString

_PMigrationMode

the migration type (live/non-live)

Value:
"mode", None, ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES\
))