module documentation

Common functions used by multiple logical units.

Function AddInstanceCommunicationNetworkOp Create an OpCode that adds the instance communication network.
Function AddMasterCandidateSshKey Undocumented
Function AddNodeCertToCandidateCerts Add the node's client SSL certificate digest to the candidate certs.
Function AdjustCandidatePool Adjust the candidate pool after node operations.
Function AnnotateDiskParams Little helper wrapper to the rpc annotation method.
Function CheckDiskAccessModeConsistency Checks if the access param is consistent with the cluster configuration.
Function CheckDiskAccessModeValidity Checks if the access parameter is legal.
Function CheckDiskTemplateEnabled Helper function to check if a disk template is enabled.
Function CheckHVParams Hypervisor parameter validation.
Function CheckIAllocatorOrNode Check the sanity of iallocator and node arguments and use the cluster-wide iallocator if appropriate.
Function CheckImageValidity Checks if a given image description is either a valid file path or a URL.
Function CheckInstanceNodeGroups Checks if the owned node groups are still correct for an instance.
Function CheckInstancesNodeGroups Checks if node groups for locked instances are still correct.
Function CheckInstanceState Ensure that an instance is in one of the required states.
Function CheckIpolicyVsDiskTemplates Checks ipolicy disk templates against enabled disk tempaltes.
Function CheckNodeGroupInstances Checks if the instances in a node group are still correct.
Function CheckNodeOnline Ensure that a given node is online.
Function CheckNodePVs Check node PVs.
Function CheckOSImage Checks if the OS image in the OS parameters of an opcode is valid.
Function CheckOSParams OS parameters validation.
Function CheckParamsNotGlobal Make sure that none of the given paramters is global.
Function CheckStorageTypeEnabled Helper function to check if a storage type is enabled.
Function ComputeAncillaryFiles Compute files external to Ganeti which need to be consistent.
Function ComputeIPolicyDiskSizesViolation Verifies ipolicy against provided disk sizes.
Function ComputeIPolicyInstanceViolation Compute if instance meets the specs of ipolicy.
Function ComputeIPolicySpecViolation Verifies ipolicy against provided specs.
Function ComputeNewInstanceViolations Computes a set of any instances that would violate the new ipolicy.
Function ConnectInstanceCommunicationNetworkOp Create an OpCode that connects a group to the instance communication network.
Function DetermineImageSize Determines the size of the specified image.
Function EnsureKvmdOnNodes Ensure KVM daemon is running on nodes with KVM instances.
Function ExpandInstanceUuidAndName Wrapper over _ExpandItemName for instance.
Function ExpandNodeUuidAndName Expand a short node name into the node UUID and full name.
Function FindFaultyInstanceDisks Undocumented
Function GetClientCertDigest Get the client SSL certificate digest for the node.
Function GetDefaultIAllocator Decides on which iallocator to use.
Function GetUpdatedIPolicy Return the new version of an instance policy.
Function GetUpdatedParams Return the new version of a parameter dictionary.
Function GetWantedInstances Returns list of checked and expanded instance names.
Function GetWantedNodes Returns list of checked and expanded node names.
Function IsExclusiveStorageEnabledNode Whether exclusive_storage is in effect for the given node.
Function IsInstanceRunning Given an instance object, checks if the instance is running.
Function IsValidDiskAccessModeCombination Checks if an hypervisor can read a disk template with given mode.
Function LoadNodeEvacResult Unpacks the result of change-group and node-evacuate iallocator requests.
Function MapInstanceLvsToNodes Creates a map from (node, volume) to instance name.
Function MergeAndVerifyDiskState Combines the disk state from an opcode with the one of the object
Function MergeAndVerifyHvState Combines the hv state from an opcode with the one of the object
Function RedistributeAncillaryFiles Distribute additional files which are part of the cluster configuration.
Function RemoveNodeCertFromCandidateCerts Removes the node's certificate from the candidate certificates list.
Function RunPostHook Runs the post-hook for an opcode on a single node.
Function ShareAll Returns a dict declaring all lock levels shared.
Function SupportsOob Tells if node supports OOB.
Function UploadHelper Helper for uploading a file and showing warnings.
Function WarnAboutFailedSshUpdates Undocumented
Constant INSTANCE_DOWN Undocumented
Constant INSTANCE_NOT_RUNNING Undocumented
Constant INSTANCE_ONLINE Undocumented
Function _ComputeMinMaxSpec Computes if value is in the desired range.
Function _ComputeViolatingInstances Computes a set of instances who violates given ipolicy.
Function _ExpandItemName Expand an item name.
Function _FilterVmNodes Filters out non-vm_capable nodes from a list.
Function _NodeEvacDest Returns group or nodes depending on caller's choice.
Function _SetOpEarlyRelease Sets early_release flag on opcodes if available.
Function _UpdateAndVerifySubDict Updates and verifies a dict with sub dicts of the same type.
def AddInstanceCommunicationNetworkOp(network):

Create an OpCode that adds the instance communication network.

This OpCode contains the configuration necessary for the instance communication network.

Parameters
network:stringname or UUID of the instance communication network
Returns
ganeti.opcodes.OpCodeOpCode that creates the instance communication network
def AddMasterCandidateSshKey(lu, master_node, node, potential_master_candidates, feedback_fn):

Undocumented

def AddNodeCertToCandidateCerts(lu, cfg, node_uuid):

Add the node's client SSL certificate digest to the candidate certs.

Parameters
lu:LogicalUnitthe logical unit
cfg:ConfigWriterthe configuration client to use
node_uuid:stringthe node's UUID
def AdjustCandidatePool(lu, exceptions, master_node, potential_master_candidates, feedback_fn, modify_ssh_setup):

Adjust the candidate pool after node operations.

Parameters
luUndocumented
exceptionsUndocumented
master_node:stringname of the master node
potential_master_candidates:list of stringlist of node names of potential master candidates
feedback_fn:functionfunction emitting user-visible output
modify_ssh_setup:booleanwhether or not the ssh setup can be modified.
def AnnotateDiskParams(instance, devs, cfg):

Little helper wrapper to the rpc annotation method.

Parameters
instanceThe instance object
devs:List of objects.DiskThe root devices (not any of its children!)
cfgThe config object @returns The annotated disk copies @see ganeti.rpc.node.AnnotateDiskParams
def CheckDiskAccessModeConsistency(parameters, cfg, group=None):

Checks if the access param is consistent with the cluster configuration.

Parameters
parametersthe parameters to validate
cfgthe cfg object of the cluster
groupif set, only check for consistency within this group.
Raises
errors.OpPrereqErrorif the LU attempts to change the access parameter to an invalid value, such as "pink bunny".
errors.OpPrereqErrorif the LU attempts to change the access parameter to an inconsistent value, such as asking for RBD userspace access to the chroot hypervisor.
Note
requires a configuration lock to run.
def CheckDiskAccessModeValidity(parameters):

Checks if the access parameter is legal.

Raises
errors.OpPrereqErrorif the check fails.
See Also
CheckDiskAccessModeConsistency for cluster consistency checks.
def CheckDiskTemplateEnabled(cluster, disk_template):

Helper function to check if a disk template is enabled.

Parameters
cluster:objects.Clusterthe cluster's configuration
disk_template:strthe disk template to be checked
def CheckHVParams(lu, node_uuids, hvname, hvparams):

Hypervisor parameter validation.

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

Parameters
lu:LogicalUnitthe logical unit for which we check
node_uuids:listthe list of nodes on which we should check
hvname:stringthe name of the hypervisor we should use
hvparams:dictthe parameters which we need to check
Raises
errors.OpPrereqErrorif the parameters are not valid
def CheckIAllocatorOrNode(lu, iallocator_slot, node_slot):

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, or the iallocator is constants.DEFAULT_IALLOCATOR_SHORTCUT, then the LU's opcode's iallocator slot is filled with the cluster-wide default iallocator.

Parameters
luUndocumented
iallocator_slot:stringthe name of the opcode iallocator slot
node_slot:stringthe name of the opcode target node slot
def CheckImageValidity(image, error_message):

Checks if a given image description is either a valid file path or a URL.

Parameters
image:stringAn absolute path or URL, the assumed location of a disk image.
error_message:stringThe error message to show if the image is not valid.
Raises
errors.OpPrereqErrorIf the validation fails.
def CheckInstanceNodeGroups(cfg, inst_uuid, owned_groups, primary_only=False):

Checks if the owned node groups are still correct for an instance.

Parameters
cfg:config.ConfigWriterThe cluster configuration
inst_uuid:stringInstance UUID
owned_groups:set or frozensetList of currently owned node groups
primary_only:booleanWhether to check node groups for only the primary node
def CheckInstancesNodeGroups(cfg, instances, owned_groups, owned_node_uuids, cur_group_uuid):

Checks if node groups for locked instances are still correct.

Parameters
cfg:config.ConfigWriterCluster configuration
instances:dict; string as key, objects.Instance as valueDictionary, instance UUID as key, instance object as value
owned_groups:iterable of stringList of owned groups
owned_node_uuids:iterable of stringList of owned nodes
cur_group_uuid:string or NoneOptional group UUID to check against instance's groups
def CheckInstanceState(lu, instance, req_states, msg=None):

Ensure that an instance is in one of the required states.

Parameters
luthe LU on behalf of which we make the check
instancethe instance to check
req_statesUndocumented
msgif passed, should be a message to replace the default one
Raises
errors.OpPrereqErrorif the instance is not in the required state
def CheckIpolicyVsDiskTemplates(ipolicy, enabled_disk_templates):

Checks ipolicy disk templates against enabled disk tempaltes.

Parameters
ipolicy:dictthe new ipolicy
enabled_disk_templates:list of stringlist of enabled disk templates on the cluster
Raises
errors.OpPrereqErrorif there is at least one allowed disk template that is not also enabled.
def CheckNodeGroupInstances(cfg, group_uuid, owned_instance_names):

Checks if the instances in a node group are still correct.

Parameters
cfg:config.ConfigWriterThe cluster configuration
group_uuid:stringNode group UUID
owned_instance_names:set or frozensetList of currently owned instances
def CheckNodeOnline(lu, node_uuid, msg=None):

Ensure that a given node is online.

Parameters
luthe LU on behalf of which we make the check
node_uuidthe node to check
msgif passed, should be a message to replace the default one
Raises
errors.OpPrereqErrorif the node is offline
def CheckNodePVs(nresult, exclusive_storage):

Check node PVs.

def CheckOSImage(op):

Checks if the OS image in the OS parameters of an opcode is valid.

This function can also be used in LUs as they carry an opcode.

Parameters
op:opcodes.OpCodeopcode containing the OS params
Returns
string or NoneTypeNone if the OS parameters in the opcode do not contain the OS image, otherwise the OS image value contained in the OS parameters
Raises
errors.OpPrereqErrorif OS image is not a URL or an absolute path
def CheckOSParams(lu, required, node_uuids, osname, osparams, force_variant):

OS parameters validation.

Parameters
lu:LogicalUnitthe logical unit for which we check
required:booleanwhether the validation should fail if the OS is not found
node_uuids:listthe list of nodes on which we should check
osname:stringthe name of the OS we should use
osparams:dictthe parameters which we need to check
force_variantUndocumented
Raises
errors.OpPrereqErrorif the parameters are not valid
def CheckParamsNotGlobal(params, glob_pars, kind, bad_levels, good_levels):

Make sure that none of the given paramters is global.

If a global parameter is found, an errors.OpPrereqError exception is raised. This is used to avoid setting global parameters for individual nodes.

Parameters
params:dictionaryParameters to check
glob_pars:dictionaryForbidden parameters
kind:stringKind of parameters (e.g. "node")
bad_levels:stringLevel(s) at which the parameters are forbidden (e.g. "instance")
good_levels:stringsLevel(s) at which the parameters are allowed (e.g. "cluster or group")
def CheckStorageTypeEnabled(cluster, storage_type):

Helper function to check if a storage type is enabled.

Parameters
cluster:objects.Clusterthe cluster's configuration
storage_type:strthe storage type to be checked
def ComputeAncillaryFiles(cluster, redist):

Compute files external to Ganeti which need to be consistent.

Parameters
clusterUndocumented
redist:booleanWhether to include files which need to be redistributed
def ComputeIPolicyDiskSizesViolation(ipolicy, disk_sizes, disks, _compute_fn=_ComputeMinMaxSpec):

Verifies ipolicy against provided disk sizes.

No other specs except the disk sizes, the number of disks and the disk template are checked.

Parameters
ipolicy:dictThe ipolicy
disk_sizes:list of intsDisk sizes of used disk (len must match disk_count)
disks:list of DiskThe Disk objects of the instance
_compute_fnThe compute function (unittest only)
Returns
A list of violations, or an empty list of no violations are found
def ComputeIPolicyInstanceViolation(ipolicy, instance, cfg, _compute_fn=ComputeIPolicySpecViolation):

Compute if instance meets the specs of ipolicy.

Parameters
ipolicy:dictThe ipolicy to verify against
instance:objects.InstanceThe instance to verify
cfg:config.ConfigWriterCluster configuration
_compute_fnThe function to verify ipolicy (unittest only)
See Also
ComputeIPolicySpecViolation
def ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, nic_count, disk_sizes, spindle_use, disk_types, _compute_fn=_ComputeMinMaxSpec):

Verifies ipolicy against provided specs.

Parameters
ipolicy:dictThe ipolicy
mem_size:intThe memory size
cpu_count:intUsed cpu cores
disk_count:intNumber of disks used
nic_count:intNumber of nics used
disk_sizes:list of intsDisk sizes of used disk (len must match disk_count)
spindle_use:intThe number of spindles this instance uses
disk_types:list of stringsThe disk template of the instance
_compute_fnThe compute function (unittest only)
Returns
A list of violations, or an empty list of no violations are found
def ComputeNewInstanceViolations(old_ipolicy, new_ipolicy, instances, cfg):

Computes a set of any instances that would violate the new ipolicy.

Parameters
old_ipolicyThe current (still in-place) ipolicy
new_ipolicyThe new (to become) ipolicy
instancesList of instances to verify
cfg:config.ConfigWriterCluster configuration
Returns
A list of instances which violates the new ipolicy but did not before
def ConnectInstanceCommunicationNetworkOp(group_uuid, network):

Create an OpCode that connects a group to the instance communication network.

This OpCode contains the configuration necessary for the instance communication network.

Parameters
group_uuid:stringUUID of the group to connect
network:stringname or UUID of the network to connect to, i.e., the instance communication network
Returns
ganeti.opcodes.OpCodeOpCode that connects the group to the instance communication network
def DetermineImageSize(lu, image, node_uuid):

Determines the size of the specified image.

Parameters
luUndocumented
image:stringabsolute filepath or URL of the image
node_uuid:stringif image is a filepath, this is the UUID of the node where the image is located
Returns
intsize of the image in MB, rounded up
Raises
OpExecErrorif the image does not exist
def EnsureKvmdOnNodes(lu, feedback_fn, nodes=None, silent_stop=False):

Ensure KVM daemon is running on nodes with KVM instances.

If user shutdown is enabled in the cluster:

  • The KVM daemon will be started on VM capable nodes containing KVM instances.
  • The KVM daemon will be stopped on non VM capable nodes.

If user shutdown is disabled in the cluster:

  • The KVM daemon will be stopped on all nodes

Issues a warning for each failed RPC call.

Parameters
lu:LogicalUnitlogical unit on whose behalf we execute
feedback_fn:callablefeedback function
nodes:list of stringif supplied, it overrides the node uuids to start/stop; this is used mainly for optimization
silent_stop:boolif we should suppress warnings in case KVM daemon is already stopped
def ExpandInstanceUuidAndName(cfg, expected_uuid, name):

Wrapper over _ExpandItemName for instance.

def ExpandNodeUuidAndName(cfg, expected_uuid, name):

Expand a short node name into the node UUID and full name.

Parameters
cfg:config.ConfigWriterThe cluster configuration
expected_uuid:stringexpected UUID for the node (or None if there is no expectation). If it does not match, a errors.OpPrereqError is raised.
name:stringthe short node name
def FindFaultyInstanceDisks(cfg, rpc_runner, instance, node_uuid, prereq):

Undocumented

def GetClientCertDigest(lu, node_uuid, filename=None):

Get the client SSL certificate digest for the node.

Parameters
luUndocumented
node_uuid:stringthe node's UUID
filename:stringthe certificate's filename
Returns
stringthe digest of the newly created certificate
def GetDefaultIAllocator(cfg, ialloc):

Decides on which iallocator to use.

Parameters
cfg:config.ConfigWriterCluster configuration object
ialloc:string or NoneIallocator specified in opcode
Returns
stringIallocator name
def GetUpdatedIPolicy(old_ipolicy, new_ipolicy, group_policy=False):

Return the new version of an instance policy.

Parameters
old_ipolicyUndocumented
new_ipolicyUndocumented
group_policywhether this policy applies to a group and thus we should support removal of policy entries
def GetUpdatedParams(old_params, update_dict, use_default=True, use_none=False):

Return the new version of a parameter dictionary.

Parameters
old_params:dictold parameters
update_dict:dictdict 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' valuesboolean
use_none:whether to recognise None values as 'to be deleted' valuesboolean
Returns
dictthe new parameter dictionary
def GetWantedInstances(lu, short_inst_names):

Returns list of checked and expanded instance names.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
short_inst_names:listlist of instance names or None for all instances
Returns
tuple of liststuple of (instance UUIDs, instance names)
Raises
errors.OpPrereqErrorif the instances parameter is wrong type
errors.OpPrereqErrorif any of the passed instances is not found
def GetWantedNodes(lu, short_node_names):

Returns list of checked and expanded node names.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
short_node_names:listlist of node names or None for all nodes
Returns
tuple of liststupe with (list of node UUIDs, list of node names)
Raises
errors.ProgrammerErrorif the nodes parameter is wrong type
def IsExclusiveStorageEnabledNode(cfg, node):

Whether exclusive_storage is in effect for the given node.

Parameters
cfg:config.ConfigWriterThe cluster configuration
node:objects.NodeThe node
Returns
boolThe effective value of exclusive_storage
def IsInstanceRunning(lu, instance, prereq=True):

Given an instance object, checks if the instance is running.

This function asks the backend whether the instance is running and user shutdown instances are considered not to be running.

Parameters
lu:LogicalUnitLU on behalf of which we make the check
instance:objects.Instanceinstance to check whether it is running
prereqUndocumented
Returns
bool'True' if the instance is running, 'False' otherwise
def IsValidDiskAccessModeCombination(hv, disk_template, mode):

Checks if an hypervisor can read a disk template with given mode.

Parameters
hvthe hypervisor that will access the data
disk_templatethe disk template the data is stored as
modehow the hypervisor should access the data
Returns
True if the hypervisor can read a given read disk_template in the specified mode.
def LoadNodeEvacResult(lu, alloc_result, early_release, use_nodes):

Unpacks the result of change-group and node-evacuate iallocator requests.

Iallocator modes constants.IALLOCATOR_MODE_NODE_EVAC and constants.IALLOCATOR_MODE_CHG_GROUP.

Parameters
lu:LogicalUnitLogical unit instance
alloc_result:tuple/listResult from iallocator
early_release:boolWhether to release locks early if possible
use_nodes:boolWhether to display node names instead of groups
def MapInstanceLvsToNodes(cfg, instances):

Creates a map from (node, volume) to instance name.

Parameters
cfg:config.ConfigWriterThe cluster configuration
instances:list of objects.InstanceUndocumented
Returns
dict; tuple of (node uuid, volume name) as key, objects.Instance object as valueUndocumented
def MergeAndVerifyDiskState(op_input, obj_input):

Combines the disk state from an opcode with the one of the object

Parameters
op_inputThe input dict from the opcode
obj_inputThe input dict from the objects
Returns
The verified and updated dict
def MergeAndVerifyHvState(op_input, obj_input):

Combines the hv state from an opcode with the one of the object

Parameters
op_inputThe input dict from the opcode
obj_inputThe input dict from the objects
Returns
The verified and updated dict
def RedistributeAncillaryFiles(lu):

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.

def RemoveNodeCertFromCandidateCerts(cfg, node_uuid):

Removes the node's certificate from the candidate certificates list.

Parameters
cfg:config.ConfigWriterthe cluster's configuration
node_uuid:stringthe node's UUID
def RunPostHook(lu, node_name):

Runs the post-hook for an opcode on a single node.

def ShareAll():

Returns a dict declaring all lock levels shared.

def SupportsOob(cfg, node):

Tells if node supports OOB.

Parameters
cfg:config.ConfigWriterThe cluster configuration
node:objects.NodeThe node
Returns
The OOB script if supported or an empty string otherwise
def UploadHelper(lu, node_uuids, fname):

Helper for uploading a file and showing warnings.

def WarnAboutFailedSshUpdates(result, master_uuid, feedback_fn):

Undocumented

INSTANCE_DOWN =

Undocumented

Value
[constants.ADMINST_DOWN]
INSTANCE_NOT_RUNNING =
INSTANCE_ONLINE =
def _ComputeMinMaxSpec(name, qualifier, ispecs, value):

Computes if value is in the desired range.

Parameters
namename of the parameter for which we perform the check
qualifiera qualifier used in the error message (e.g. 'disk/1', not just 'disk')
ispecsdictionary containing min and max values
valueactual value that we want to use
Returns
None or an error string
def _ComputeViolatingInstances(ipolicy, instances, cfg):

Computes a set of instances who violates given ipolicy.

Parameters
ipolicyThe ipolicy to verify
instances:objects.InstanceList of instances to verify
cfg:config.ConfigWriterCluster configuration
Returns
A frozenset of instance names violating the ipolicy
def _ExpandItemName(expand_fn, name, kind):

Expand an item name.

Parameters
expand_fnthe function to use for expansion
namerequested item name
kindtext description ('Node' or 'Instance')
Returns
the result of the expand_fn, if successful
Raises
errors.OpPrereqErrorif the item is not found
def _FilterVmNodes(lu, node_uuids):

Filters out non-vm_capable nodes from a list.

Parameters
lu:LogicalUnitthe logical unit for which we check
node_uuids:listthe list of nodes on which we should check
Returns
listthe list of vm-capable nodes
def _NodeEvacDest(use_nodes, group, node_names):

Returns group or nodes depending on caller's choice.

def _SetOpEarlyRelease(early_release, op):

Sets early_release flag on opcodes if available.

def _UpdateAndVerifySubDict(base, updates, type_check):

Updates and verifies a dict with sub dicts of the same type.

Parameters
baseThe dict with the old data
updatesThe dict with the new data
type_checkDict suitable to ForceDictType to verify correct types
Returns
A new dict with updated and verified values