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

Module common

source code

Common functions used by multiple logical units.

Functions [hide private]
 
_ExpandItemName(expand_fn, name, kind)
Expand an item name.
source code
 
ExpandInstanceUuidAndName(cfg, expected_uuid, name)
Wrapper over _ExpandItemName for instance.
source code
 
ExpandNodeUuidAndName(cfg, expected_uuid, name)
Expand a short node name into the node UUID and full name.
source code
 
ShareAll()
Returns a dict declaring all lock levels shared.
source code
 
CheckNodeGroupInstances(cfg, group_uuid, owned_instance_names)
Checks if the instances in a node group are still correct.
source code
tuple of lists
GetWantedNodes(lu, short_node_names)
Returns list of checked and expanded node names.
source code
tuple of lists
GetWantedInstances(lu, short_inst_names)
Returns list of checked and expanded instance names.
source code
 
RunPostHook(lu, node_name)
Runs the post-hook for an opcode on a single node.
source code
 
RedistributeAncillaryFiles(lu)
Distribute additional files which are part of the cluster configuration.
source code
 
ComputeAncillaryFiles(cluster, redist)
Compute files external to Ganeti which need to be consistent.
source code
 
UploadHelper(lu, node_uuids, fname)
Helper for uploading a file and showing warnings.
source code
 
MergeAndVerifyHvState(op_input, obj_input)
Combines the hv state from an opcode with the one of the object
source code
 
MergeAndVerifyDiskState(op_input, obj_input)
Combines the disk state from an opcode with the one of the object
source code
 
CheckOSParams(lu, required, node_uuids, osname, osparams, force_variant)
OS parameters validation.
source code
 
CheckImageValidity(image, error_message)
Checks if a given image description is either a valid file path or a URL.
source code
string or NoneType
CheckOSImage(op)
Checks if the OS image in the OS parameters of an opcode is valid.
source code
 
CheckHVParams(lu, node_uuids, hvname, hvparams)
Hypervisor parameter validation.
source code
 
AdjustCandidatePool(lu, exceptions)
Adjust the candidate pool after node operations.
source code
 
CheckNodePVs(nresult, exclusive_storage)
Check node PVs.
source code
 
_ComputeMinMaxSpec(name, qualifier, ispecs, value)
Computes if value is in the desired range.
source code
 
ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, nic_count, disk_sizes, spindle_use, disk_template, _compute_fn=_ComputeMinMaxSpec)
Verifies ipolicy against provided specs.
source code
 
ComputeIPolicyDiskSizesViolation(ipolicy, disk_sizes, disk_template, _compute_fn=_ComputeMinMaxSpec)
Verifies ipolicy against provided disk sizes.
source code
 
ComputeIPolicyInstanceViolation(ipolicy, instance, cfg, _compute_fn=ComputeIPolicySpecViolation)
Compute if instance meets the specs of ipolicy.
source code
 
_ComputeViolatingInstances(ipolicy, instances, cfg)
Computes a set of instances who violates given ipolicy.
source code
 
ComputeNewInstanceViolations(old_ipolicy, new_ipolicy, instances, cfg)
Computes a set of any instances that would violate the new ipolicy.
source code
dict
GetUpdatedParams(old_params, update_dict, use_default=True, use_none=False)
Return the new version of a parameter dictionary.
source code
 
GetUpdatedIPolicy(old_ipolicy, new_ipolicy, group_policy=False)
Return the new version of an instance policy.
source code
 
AnnotateDiskParams(instance, devs, cfg)
Little helper wrapper to the rpc annotation method.
source code
 
SupportsOob(cfg, node)
Tells if node supports OOB.
source code
 
_UpdateAndVerifySubDict(base, updates, type_check)
Updates and verifies a dict with sub dicts of the same type.
source code
list
_FilterVmNodes(lu, node_uuids)
Filters out non-vm_capable nodes from a list.
source code
string
GetDefaultIAllocator(cfg, ialloc)
Decides on which iallocator to use.
source code
 
CheckInstancesNodeGroups(cfg, instances, owned_groups, owned_node_uuids, cur_group_uuid)
Checks if node groups for locked instances are still correct.
source code
 
CheckInstanceNodeGroups(cfg, inst_uuid, owned_groups, primary_only=False)
Checks if the owned node groups are still correct for an instance.
source code
 
LoadNodeEvacResult(lu, alloc_result, early_release, use_nodes)
Unpacks the result of change-group and node-evacuate iallocator requests.
source code
 
_NodeEvacDest(use_nodes, group, node_names)
Returns group or nodes depending on caller's choice.
source code
 
_SetOpEarlyRelease(early_release, op)
Sets early_release flag on opcodes if available.
source code
dict; tuple of (node uuid, volume name) as key, objects.Instance object as value
MapInstanceLvsToNodes(cfg, instances)
Creates a map from (node, volume) to instance name.
source code
 
CheckParamsNotGlobal(params, glob_pars, kind, bad_levels, good_levels)
Make sure that none of the given paramters is global.
source code
bool
IsExclusiveStorageEnabledNode(cfg, node)
Whether exclusive_storage is in effect for the given node.
source code
bool
IsInstanceRunning(lu, instance, prereq=True)
Given an instance object, checks if the instance is running.
source code
 
CheckInstanceState(lu, instance, req_states, msg=None)
Ensure that an instance is in one of the required states.
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
 
FindFaultyInstanceDisks(cfg, rpc_runner, instance, node_uuid, prereq) source code
 
CheckNodeOnline(lu, node_uuid, msg=None)
Ensure that a given node is online.
source code
 
CheckDiskTemplateEnabled(cluster, disk_template)
Helper function to check if a disk template is enabled.
source code
 
CheckStorageTypeEnabled(cluster, storage_type)
Helper function to check if a storage type is enabled.
source code
 
CheckIpolicyVsDiskTemplates(ipolicy, enabled_disk_templates)
Checks ipolicy disk templates against enabled disk tempaltes.
source code
 
CheckDiskAccessModeValidity(parameters)
Checks if the access parameter is legal.
source code
 
CheckDiskAccessModeConsistency(parameters, cfg, group=None)
Checks if the access param is consistent with the cluster configuration.
source code
 
IsValidDiskAccessModeCombination(hv, disk_template, mode)
Checks if an hypervisor can read a disk template with given mode.
source code
 
AddNodeCertToCandidateCerts(lu, cfg, node_uuid)
Add the node's client SSL certificate digest to the candidate certs.
source code
 
RemoveNodeCertFromCandidateCerts(cfg, node_uuid)
Removes the node's certificate from the candidate certificates list.
source code
string
GetClientCertDigest(lu, node_uuid, filename=None)
Get the client SSL certificate digest for the node.
source code
ganeti.opcodes.OpCode
AddInstanceCommunicationNetworkOp(network)
Create an OpCode that adds the instance communication network.
source code
ganeti.opcodes.OpCode
ConnectInstanceCommunicationNetworkOp(group_uuid, network)
Create an OpCode that connects a group to the instance communication network.
source code
int
DetermineImageSize(lu, image, node_uuid)
Determines the size of the specified image.
source code
 
EnsureKvmdOnNodes(lu, feedback_fn, nodes=None)
Ensure KVM daemon is running on nodes with KVM instances.
source code
Variables [hide private]
  INSTANCE_DOWN = [constants.ADMINST_DOWN]
  INSTANCE_ONLINE = [constants.ADMINST_DOWN, constants.ADMINST_UP]
  INSTANCE_NOT_RUNNING = [constants.ADMINST_DOWN, constants.ADMI...

Imports: copy, math, os, urllib2, compat, constants, errors, hypervisor, locking, objects, opcodes, pathutils, rpc, Private, ssconf, utils


Function Details [hide private]

_ExpandItemName(expand_fn, name, kind)

source code 

Expand an item name.

Parameters:
  • expand_fn - the function to use for expansion
  • name - requested item name
  • kind - text description ('Node' or 'Instance')
Returns:
the result of the expand_fn, if successful
Raises:

ExpandNodeUuidAndName(cfg, expected_uuid, name)

source code 

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

Parameters:
  • cfg (config.ConfigWriter) - The cluster configuration
  • expected_uuid (string) - expected UUID for the node (or None if there is no expectation). If it does not match, a errors.OpPrereqError is raised.
  • name (string) - the short node name

CheckNodeGroupInstances(cfg, group_uuid, owned_instance_names)

source code 

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

Parameters:
  • cfg (config.ConfigWriter) - The cluster configuration
  • group_uuid (string) - Node group UUID
  • owned_instance_names (set or frozenset) - List of currently owned instances

GetWantedNodes(lu, short_node_names)

source code 

Returns list of checked and expanded node names.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • short_node_names (list) - list of node names or None for all nodes
Returns: tuple of lists
tupe with (list of node UUIDs, list of node names)
Raises:

GetWantedInstances(lu, short_inst_names)

source code 

Returns list of checked and expanded instance names.

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

RedistributeAncillaryFiles(lu)

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.

ComputeAncillaryFiles(cluster, redist)

source code 

Compute files external to Ganeti which need to be consistent.

Parameters:
  • redist (boolean) - Whether to include files which need to be redistributed

MergeAndVerifyHvState(op_input, obj_input)

source code 

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

Parameters:
  • op_input - The input dict from the opcode
  • obj_input - The input dict from the objects
Returns:
The verified and updated dict

MergeAndVerifyDiskState(op_input, obj_input)

source code 

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

Parameters:
  • op_input - The input dict from the opcode
  • obj_input - The input dict from the objects
Returns:
The verified and updated dict

CheckOSParams(lu, required, node_uuids, osname, osparams, force_variant)

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
  • node_uuids (list) - the list of nodes on which we should check
  • osname (string) - the name of the OS we should use
  • osparams (dict) - the parameters which we need to check
Raises:

CheckImageValidity(image, error_message)

source code 

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

Parameters:
  • image (string) - An absolute path or URL, the assumed location of a disk image.
  • error_message (string) - The error message to show if the image is not valid.
Raises:

CheckOSImage(op)

source code 

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:
Returns: string or NoneType
None if the OS parameters in the opcode do not contain the OS image, otherwise the OS image value contained in the OS parameters
Raises:

CheckHVParams(lu, node_uuids, hvname, hvparams)

source code 

Hypervisor parameter validation.

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

Parameters:
  • lu (LogicalUnit) - the logical unit for which we check
  • node_uuids (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:

_ComputeMinMaxSpec(name, qualifier, ispecs, value)

source code 

Computes if value is in the desired range.

Parameters:
  • name - name of the parameter for which we perform the check
  • qualifier - a qualifier used in the error message (e.g. 'disk/1', not just 'disk')
  • ispecs - dictionary containing min and max values
  • value - actual value that we want to use
Returns:
None or an error string

ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, nic_count, disk_sizes, spindle_use, disk_template, _compute_fn=_ComputeMinMaxSpec)

source code 

Verifies ipolicy against provided specs.

Parameters:
  • ipolicy (dict) - The ipolicy
  • mem_size (int) - The memory size
  • cpu_count (int) - Used cpu cores
  • disk_count (int) - Number of disks used
  • nic_count (int) - Number of nics used
  • disk_sizes (list of ints) - Disk sizes of used disk (len must match disk_count)
  • spindle_use (int) - The number of spindles this instance uses
  • disk_template (string) - The disk template of the instance
  • _compute_fn - The compute function (unittest only)
Returns:
A list of violations, or an empty list of no violations are found

ComputeIPolicyDiskSizesViolation(ipolicy, disk_sizes, disk_template, _compute_fn=_ComputeMinMaxSpec)

source code 

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 (dict) - The ipolicy
  • disk_sizes (list of ints) - Disk sizes of used disk (len must match disk_count)
  • disk_template (string) - The disk template of the instance
  • _compute_fn - The compute function (unittest only)
Returns:
A list of violations, or an empty list of no violations are found

ComputeIPolicyInstanceViolation(ipolicy, instance, cfg, _compute_fn=ComputeIPolicySpecViolation)

source code 

Compute if instance meets the specs of ipolicy.

Parameters:
  • ipolicy (dict) - The ipolicy to verify against
  • instance (objects.Instance) - The instance to verify
  • cfg (config.ConfigWriter) - Cluster configuration
  • _compute_fn - The function to verify ipolicy (unittest only)

_ComputeViolatingInstances(ipolicy, instances, cfg)

source code 

Computes a set of instances who violates given ipolicy.

Parameters:
Returns:
A frozenset of instance names violating the ipolicy

ComputeNewInstanceViolations(old_ipolicy, new_ipolicy, instances, cfg)

source code 

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

Parameters:
  • old_ipolicy - The current (still in-place) ipolicy
  • new_ipolicy - The new (to become) ipolicy
  • instances - List of instances to verify
  • cfg (config.ConfigWriter) - Cluster configuration
Returns:
A list of instances which violates the new ipolicy but did not before

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

GetUpdatedIPolicy(old_ipolicy, new_ipolicy, group_policy=False)

source code 

Return the new version of an instance policy.

Parameters:
  • group_policy - whether this policy applies to a group and thus we should support removal of policy entries

AnnotateDiskParams(instance, devs, cfg)

source code 

Little helper wrapper to the rpc annotation method.

Parameters:

SupportsOob(cfg, node)

source code 

Tells if node supports OOB.

Parameters:
Returns:
The OOB script if supported or an empty string otherwise

_UpdateAndVerifySubDict(base, updates, type_check)

source code 

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

Parameters:
  • base - The dict with the old data
  • updates - The dict with the new data
  • type_check - Dict suitable to ForceDictType to verify correct types
Returns:
A new dict with updated and verified values

_FilterVmNodes(lu, node_uuids)

source code 

Filters out non-vm_capable nodes from a list.

Parameters:
  • lu (LogicalUnit) - the logical unit for which we check
  • node_uuids (list) - the list of nodes on which we should check
Returns: list
the list of vm-capable nodes

GetDefaultIAllocator(cfg, ialloc)

source code 

Decides on which iallocator to use.

Parameters:
  • cfg (config.ConfigWriter) - Cluster configuration object
  • ialloc (string or None) - Iallocator specified in opcode
Returns: string
Iallocator name

CheckInstancesNodeGroups(cfg, instances, owned_groups, owned_node_uuids, cur_group_uuid)

source code 

Checks if node groups for locked instances are still correct.

Parameters:
  • cfg (config.ConfigWriter) - Cluster configuration
  • instances (dict; string as key, objects.Instance as value) - Dictionary, instance UUID as key, instance object as value
  • owned_groups (iterable of string) - List of owned groups
  • owned_node_uuids (iterable of string) - List of owned nodes
  • cur_group_uuid (string or None) - Optional group UUID to check against instance's groups

CheckInstanceNodeGroups(cfg, inst_uuid, owned_groups, primary_only=False)

source code 

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

Parameters:
  • cfg (config.ConfigWriter) - The cluster configuration
  • inst_uuid (string) - Instance UUID
  • owned_groups (set or frozenset) - List of currently owned node groups
  • primary_only (boolean) - Whether to check node groups for only the primary node

LoadNodeEvacResult(lu, alloc_result, early_release, use_nodes)

source code 

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 (LogicalUnit) - Logical unit instance
  • alloc_result (tuple/list) - Result from iallocator
  • early_release (bool) - Whether to release locks early if possible
  • use_nodes (bool) - Whether to display node names instead of groups

MapInstanceLvsToNodes(cfg, instances)

source code 

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

Parameters:
Returns: dict; tuple of (node uuid, volume name) as key, objects.Instance object as value

CheckParamsNotGlobal(params, glob_pars, kind, bad_levels, good_levels)

source code 

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 (dictionary) - Parameters to check
  • glob_pars (dictionary) - Forbidden parameters
  • kind (string) - Kind of parameters (e.g. "node")
  • bad_levels (string) - Level(s) at which the parameters are forbidden (e.g. "instance")
  • good_levels (strings) - Level(s) at which the parameters are allowed (e.g. "cluster or group")

IsExclusiveStorageEnabledNode(cfg, node)

source code 

Whether exclusive_storage is in effect for the given node.

Parameters:
Returns: bool
The effective value of exclusive_storage

IsInstanceRunning(lu, instance, prereq=True)

source code 

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:
Returns: bool
'True' if the instance is running, 'False' otherwise

CheckInstanceState(lu, instance, req_states, msg=None)

source code 

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

Parameters:
  • lu - the LU on behalf of which we make the check
  • instance - the instance to check
  • msg - if passed, should be a message to replace the default one
Raises:

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, 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:
  • iallocator_slot (string) - the name of the opcode iallocator slot
  • node_slot (string) - the name of the opcode target node slot

CheckNodeOnline(lu, node_uuid, msg=None)

source code 

Ensure that a given node is online.

Parameters:
  • lu - the LU on behalf of which we make the check
  • node_uuid - the node to check
  • msg - if passed, should be a message to replace the default one
Raises:

CheckDiskTemplateEnabled(cluster, disk_template)

source code 

Helper function to check if a disk template is enabled.

Parameters:
  • cluster (objects.Cluster) - the cluster's configuration
  • disk_template (str) - the disk template to be checked

CheckStorageTypeEnabled(cluster, storage_type)

source code 

Helper function to check if a storage type is enabled.

Parameters:
  • cluster (objects.Cluster) - the cluster's configuration
  • storage_type (str) - the storage type to be checked

CheckIpolicyVsDiskTemplates(ipolicy, enabled_disk_templates)

source code 

Checks ipolicy disk templates against enabled disk tempaltes.

Parameters:
  • ipolicy (dict) - the new ipolicy
  • enabled_disk_templates (list of string) - list of enabled disk templates on the cluster
Raises:

CheckDiskAccessModeValidity(parameters)

source code 

Checks if the access parameter is legal.

Raises:

See Also: CheckDiskAccessModeConsistency for cluster consistency checks.

CheckDiskAccessModeConsistency(parameters, cfg, group=None)

source code 

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

Parameters:
  • parameters - the parameters to validate
  • cfg - the cfg object of the cluster
  • group - if set, only check for consistency within this group.
Raises:
  • errors.OpPrereqError - if the LU attempts to change the access parameter to an invalid value, such as "pink bunny".
  • errors.OpPrereqError - if 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.

IsValidDiskAccessModeCombination(hv, disk_template, mode)

source code 

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

Parameters:
  • hv - the hypervisor that will access the data
  • disk_template - the disk template the data is stored as
  • mode - how the hypervisor should access the data
Returns:
True if the hypervisor can read a given read disk_template in the specified mode.

AddNodeCertToCandidateCerts(lu, cfg, node_uuid)

source code 

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

Parameters:
  • lu (LogicalUnit) - the logical unit
  • cfg (ConfigWriter) - the configuration client to use
  • node_uuid (string) - the node's UUID

RemoveNodeCertFromCandidateCerts(cfg, node_uuid)

source code 

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

Parameters:
  • cfg (config.ConfigWriter) - the cluster's configuration
  • node_uuid (string) - the node's UUID

GetClientCertDigest(lu, node_uuid, filename=None)

source code 

Get the client SSL certificate digest for the node.

Parameters:
  • node_uuid (string) - the node's UUID
  • filename (string) - the certificate's filename
Returns: string
the digest of the newly created certificate

AddInstanceCommunicationNetworkOp(network)

source code 

Create an OpCode that adds the instance communication network.

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

Parameters:
  • network (string) - name or UUID of the instance communication network
Returns: ganeti.opcodes.OpCode
OpCode that creates the instance communication network

ConnectInstanceCommunicationNetworkOp(group_uuid, network)

source code 

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 (string) - UUID of the group to connect
  • network (string) - name or UUID of the network to connect to, i.e., the instance communication network
Returns: ganeti.opcodes.OpCode
OpCode that connects the group to the instance communication network

DetermineImageSize(lu, image, node_uuid)

source code 

Determines the size of the specified image.

Parameters:
  • image (string) - absolute filepath or URL of the image
  • node_uuid (string) - if image is a filepath, this is the UUID of the node where the image is located
Returns: int
size of the image in MB, rounded up
Raises:

EnsureKvmdOnNodes(lu, feedback_fn, nodes=None)

source code 

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 (LogicalUnit) - logical unit on whose behalf we execute
  • feedback_fn (callable) - feedback function
  • nodes (list of string) - if supplied, it overrides the node uuids to start/stop; this is used mainly for optimization

Variables Details [hide private]

INSTANCE_NOT_RUNNING

Value:
[constants.ADMINST_DOWN, constants.ADMINST_OFFLINE]