module documentation

Utility function mainly, but not only used by instance LU's.

Function ApplyContainerMods Applies descriptions in mods to container.
Function BuildDiskEnv Helper method to create disk's hooks env
Function BuildDiskLogicalIDEnv Helper method to create hooks env related to disk's logical_id
Function BuildInstanceHookEnv Builds instance related env variables for hooks
Function BuildInstanceHookEnvByObject Builds instance related env variables for hooks from an object.
Function CheckCompressionTool Checks if the provided compression tool is allowed to be used.
Function CheckForConflictingIp In case of conflicting IP address raise error.
Function CheckHostnameSane Ensures that a given hostname resolves to a 'sane' name.
Function CheckInstanceBridgesExist Check that the brigdes needed by an instance exist.
Function CheckInstanceExistence Raises an error if an instance with the given name exists already.
Function CheckNicsBridgesExist Check that the brigdes needed by a list of nics exist.
Function CheckNodeFreeMemory Checks if a node has enough free memory.
Function CheckNodeNotDrained Ensure that a given node is not drained.
Function CheckNodesPhysicalCPUs Checks if nodes have enough physical CPUs
Function CheckNodeVmCapable Ensure that a given node is vm capable.
Function CheckOpportunisticLocking Generate error if opportunistic locking is not possible.
Function CheckTargetNodeIPolicy Checks that the target node is correct in terms of instance policy.
Function ComputeFullBeParams Computes the full beparams.
Function ComputeInstanceCommunicationNIC Compute the name of the instance NIC used by instance communication.
Function ComputeIPolicyInstanceSpecViolation Compute if instance specs meets the specs of ipolicy.
Function ComputeNics Computes the nics.
Function CopyLockList Makes a copy of a list of lock names.
Function CreateInstanceAllocRequest Wrapper around IAReqInstanceAlloc.
Function GetClusterDomainSecret Reads the cluster domain secret.
Function GetIndexFromIdentifier Check if the identifier represents a valid container index and return it.
Function GetInstanceInfoText Compute that text that should be added to the disk's metadata.
Function GetItemFromContainer Return the item refered by the identifier.
Function InsertItemToIndex Insert an item to the provided index of a container.
Function NICListToTuple Build a list of nic information tuples.
Function NICToTuple Build a tupple of nic information.
Function PrepareContainerMods Prepares a list of container modifications by adding a private data field.
Function ReleaseLocks Releases locks owned by an LU.
Function RemoveDisks Remove all or a subset of disks for an instance.
Function RemoveInstance Utility function to remove an instance.
Function UpdateMetadata Updates instance metadata on the metadata daemon on the instance's primary node.
Function _ComputeIPolicyNodeViolation Compute if instance meets the specs of the new target group.
Function _StoragePathsRemoved Returns an iterable of all storage paths to be removed.
Variable _TApplyContModsCbChanges Undocumented
def ApplyContainerMods(kind, container, chgdesc, mods, create_fn, attach_fn, modify_fn, remove_fn, detach_fn, post_add_fn=None):

Applies descriptions in mods to container.

Parameters
kind:stringOne-word item description
container:listContainer to modify
chgdesc:None or listList of applied changes
mods:listModifications as returned by PrepareContainerMods
create_fn:callableCallback for creating a new item (constants.DDM_ADD); receives absolute item index, parameters and private data object as added by PrepareContainerMods, returns tuple containing new item and changes as list
attach_fn:callableCallback for attaching an existing item to a container (constants.DDM_ATTACH); receives absolute item index and item UUID or name, returns tuple containing new item and changes as list
modify_fn:callableCallback for modifying an existing item (constants.DDM_MODIFY); receives absolute item index, item, parameters and private data object as added by PrepareContainerMods, returns changes as list
remove_fn:callableCallback on removing item; receives absolute item index, item and private data object as added by PrepareContainerMods
detach_fn:callableCallback on detaching item; receives absolute item index, item and private data object as added by PrepareContainerMods
post_add_fn:callableCallable for post-processing a newly created item after it has been put into the container. It receives the index of the new item and the new item as parameters.
def BuildDiskEnv(idx, disk):

Helper method to create disk's hooks env

Parameters
idx:integerThe index of the disk
disk:objects.Disk or dictThe disk object or a simple dict in case of LUInstanceCreate
def BuildDiskLogicalIDEnv(idx, disk):

Helper method to create hooks env related to disk's logical_id

Parameters
idx:integerThe index of the disk
disk:objects.DiskThe disk object
def BuildInstanceHookEnv(name, primary_node_name, secondary_node_names, os_type, status, minmem, maxmem, vcpus, nics, disk_template, disks, bep, hvp, hypervisor_name, tags):

Builds instance related env variables for hooks

This builds the hook environment from individual variables.

Parameters
name:stringthe name of the instance
primary_node_name:stringthe name of the instance's primary node
secondary_node_names:listlist of secondary nodes as strings
os_type:stringthe name of the instance's OS
status:stringthe desired status of the instance
minmem:stringthe minimum memory size of the instance
maxmem:stringthe maximum memory size of the instance
vcpus:stringthe count of VCPUs the instance has
nics:listlist of tuples (name, uuid, ip, mac, mode, link, vlan, net, netinfo) representing the NICs the instance has
disk_template:stringthe disk template of the instance
disks:listlist of disks (either objects.Disk or dict)
bep:dictthe backend parameters for the instance
hvp:dictthe hypervisor parameters for the instance
hypervisor_name:stringthe hypervisor for the instance
tags:listlist of instance tags as strings
Returns
dictthe hook environment for this instance
def BuildInstanceHookEnvByObject(lu, instance, secondary_nodes=None, disks=None, override=None):

Builds instance related env variables for hooks from an object.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance for which we should build the environment
secondary_nodesUndocumented
disksUndocumented
override:dictdictionary with key/values that will override our values
Returns
dictthe hook environment dictionary
def CheckCompressionTool(lu, compression_tool):

Checks if the provided compression tool is allowed to be used.

Parameters
luUndocumented
compression_tool:stringCompression tool to use for importing or exporting the instance
Returns
NoneTypeNone
Raises
errors.OpPrereqErrorIf the tool is not enabled by Ganeti or whitelisted
def CheckForConflictingIp(lu, ip, node_uuid):

In case of conflicting IP address raise error.

Parameters
luUndocumented
ip:stringIP address
node_uuid:stringnode UUID
def CheckHostnameSane(lu, name):

Ensures that a given hostname resolves to a 'sane' name.

The given name is required to be a prefix of the resolved hostname, to prevent accidental mismatches.

Parameters
luthe logical unit on behalf of which we're checking
namethe name we should resolve and check
Returns
the resolved hostname object
def CheckInstanceBridgesExist(lu, instance, node_uuid=None):

Check that the brigdes needed by an instance exist.

def CheckInstanceExistence(lu, instance_name):

Raises an error if an instance with the given name exists already.

Parameters
luUndocumented
instance_name:string

The name of the instance.

To be used in the locking phase.

def CheckNicsBridgesExist(lu, nics, node_uuid):

Check that the brigdes needed by a list of nics exist.

def CheckNodeFreeMemory(lu, node_uuid, reason, requested, hvname, hvparams):

Checks if a node has enough free memory.

This function checks 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 raises an OpPrereqError exception.

Parameters
lu:LogicalUnita logical unit from which we get configuration data
node_uuid:strthe node to check
reason:strstring to use in the error message
requested:intthe amount of memory in MiB to check for
hvname:stringthe hypervisor's name
hvparams:dict of stringsthe hypervisor's parameters
Returns
integernode current free memory
Raises
errors.OpPrereqErrorif the node doesn't have enough memory, or we cannot check the node
def CheckNodeNotDrained(lu, node_uuid):

Ensure that a given node is not drained.

Parameters
luthe LU on behalf of which we make the check
node_uuidthe node to check
Raises
errors.OpPrereqErrorif the node is drained
def CheckNodesPhysicalCPUs(lu, node_uuids, requested, hypervisor_specs):

Checks if nodes have enough physical CPUs

This function checks if all given nodes have the needed number of physical CPUs. In case any node has less CPUs or we cannot get the information from the node, this function raises an OpPrereqError exception.

Parameters
lu:LogicalUnita logical unit from which we get configuration data
node_uuids:listthe list of node UUIDs to check
requested:intthe minimum acceptable number of physical CPUs
hypervisor_specs:list of pairs (string, dict of strings)list of hypervisor specifications in pairs (hypervisor_name, hvparams)
Raises
errors.OpPrereqErrorif the node doesn't have enough CPUs, or we cannot check the node
def CheckNodeVmCapable(lu, node_uuid):

Ensure that a given node is vm capable.

Parameters
luthe LU on behalf of which we make the check
node_uuidthe node to check
Raises
errors.OpPrereqErrorif the node is not vm capable
def CheckOpportunisticLocking(op):

Generate error if opportunistic locking is not possible.

def CheckTargetNodeIPolicy(lu, ipolicy, instance, node, cfg, ignore=False, _compute_fn=_ComputeIPolicyNodeViolation):

Checks that the target node is correct in terms of instance policy.

Parameters
luUndocumented
ipolicyThe ipolicy to verify
instanceThe instance object to verify
nodeThe new node to relocate
cfg:config.ConfigWriterCluster configuration
ignoreIgnore violations of the ipolicy
_compute_fnThe function to verify ipolicy (unittest only)
See Also
ganeti.cmdlib.common.ComputeIPolicySpecViolation
def ComputeFullBeParams(op, cluster):

Computes the full beparams.

Parameters
opThe instance opcode
clusterThe cluster config object
Returns
The fully filled beparams
def ComputeInstanceCommunicationNIC(instance_name):

Compute the name of the instance NIC used by instance communication.

With instance communication, a new NIC is added to the instance. This NIC has a special name that identities it as being part of instance communication, and not just a normal NIC. This function generates the name of the NIC based on a prefix and the instance name

Parameters
instance_name:stringname of the instance the NIC belongs to
Returns
stringname of the NIC
def ComputeIPolicyInstanceSpecViolation(ipolicy, instance_spec, disk_types, _compute_fn=ComputeIPolicySpecViolation):

Compute if instance specs meets the specs of ipolicy.

Parameters
ipolicy:dictThe ipolicy to verify against
instance_specThe instance spec to verify
disk_types:list of stringsthe disk templates of the instance
_compute_fnThe function to verify ipolicy (unittest only)
See Also
ComputeIPolicySpecViolation
def ComputeNics(op, cluster, default_ip, cfg, ec_id):

Computes the nics.

Parameters
opThe instance opcode
clusterCluster configuration object
default_ipThe default ip to assign
cfgAn instance of the configuration object
ec_idExecution context ID
Returns
The build up nics
def CopyLockList(names):

Makes a copy of a list of lock names.

Handles locking.ALL_SET correctly.

def CreateInstanceAllocRequest(op, disks, nics, beparams, node_name_whitelist):

Wrapper around IAReqInstanceAlloc.

Parameters
opThe instance opcode
disksThe computed disks
nicsThe computed nics
beparamsThe full filled beparams
node_name_whitelistList of nodes which should appear as online to the allocator (unless the node is already marked offline)
Returns
A filled iallocator.IAReqInstanceAlloc
def GetClusterDomainSecret():

Reads the cluster domain secret.

def GetIndexFromIdentifier(identifier, kind, container):

Check if the identifier represents a valid container index and return it.

Used in "add" and "attach" actions.

Parameters
identifier:stringItem index or name or UUID
kind:stringType of item, e.g. "disk", "nic"
container:listContainer to calculate the index from
def GetInstanceInfoText(instance):

Compute that text that should be added to the disk's metadata.

def GetItemFromContainer(identifier, kind, container):

Return the item refered by the identifier.

Parameters
identifier:stringItem index or name or UUID
kind:stringOne-word item description
container:listContainer to get the item from
def InsertItemToIndex(identifier, item, container):

Insert an item to the provided index of a container.

Used in "add" and "attach" actions.

Parameters
identifier:stringItem index
item:objectThe item to be inserted
container:listContainer to insert the item to
def NICListToTuple(lu, nics):

Build a list of nic information tuples.

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

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
nics:list of objects.NIClist of nics to convert to hooks tuples
def NICToTuple(lu, nic):

Build a tupple of nic information.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
nic:objects.NICnic to convert to hooks tuple
def PrepareContainerMods(mods, private_fn):

Prepares a list of container modifications by adding a private data field.

Parameters
mods:list of tuples; (operation, index, parameters)List of modifications
private_fn:callable or NoneCallable for constructing a private data field for a modification
Returns
listUndocumented
def ReleaseLocks(lu, level, names=None, keep=None):

Releases locks owned by an LU.

Parameters
lu:LogicalUnitUndocumented
levelLock level
names:list or NoneNames of locks to release
keep:list or NoneNames of locks to retain
def RemoveDisks(lu, instance, disks=None, target_node_uuid=None, ignore_failures=False):

Remove all or a subset of 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.

This function is also used by the disk template conversion mechanism to remove the old block devices of the instance. Since the instance has changed its template at the time we remove the original disks, we must specify the template of the disks we are about to remove as an argument.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance whose disks we should remove
disks:list of objects.Diskthe disks to remove; if not specified, all the disks of the instance are removed
target_node_uuid:stringused to override the node on which to remove the disks
ignore_failuresUndocumented
Returns
booleanthe success of the removal
def RemoveInstance(lu, feedback_fn, instance, ignore_failures):

Utility function to remove an instance.

def UpdateMetadata(feedback_fn, rpc, instance, osparams_public=None, osparams_private=None, osparams_secret=None):

Updates instance metadata on the metadata daemon on the instance's primary node.

If the daemon isn't available (not compiled), do nothing.

In case the RPC fails, this function simply issues a warning and proceeds normally.

Parameters
feedback_fn:callablefunction used send feedback back to the caller
rpc:rpc.node.RpcRunnerRPC runner
instance:objects.Instanceinstance for which the metadata should be updated
osparams_public:NoneType or dictpublic OS parameters used to override those defined in instance
osparams_private:NoneType or dictprivate OS parameters used to override those defined in instance
osparams_secret:NoneType or dictsecret OS parameters used to override those defined in instance
Returns
NoneTypeNone
def _ComputeIPolicyNodeViolation(ipolicy, instance, current_group, target_group, cfg, _compute_fn=ComputeIPolicyInstanceViolation):

Compute if instance meets the specs of the new target group.

Parameters
ipolicyThe ipolicy to verify
instanceThe instance object to verify
current_groupThe current group of the instance
target_groupThe new group of the instance
cfg:config.ConfigWriterCluster configuration
_compute_fnThe function to verify ipolicy (unittest only)
See Also
ganeti.cmdlib.common.ComputeIPolicySpecViolation
def _StoragePathsRemoved(removed, disks):

Returns an iterable of all storage paths to be removed.

A storage path is removed if no disks are contained in it anymore.

Parameters
removed:list of objects.DiskThe disks that are being removed
disks:list of objects.DiskAll disks attached to the instance
Returns
list of file pathsthe storage directories that need to be removed
_TApplyContModsCbChanges =

Undocumented