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

Module instance_utils

source code

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

Functions [hide private]
dict
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
source code
dict
BuildInstanceHookEnvByObject(lu, instance, secondary_nodes=None, disks=None, override=None)
Builds instance related env variables for hooks from an object.
source code
 
GetClusterDomainSecret()
Reads the cluster domain secret.
source code
 
CheckNodeNotDrained(lu, node_uuid)
Ensure that a given node is not drained.
source code
 
CheckNodeVmCapable(lu, node_uuid)
Ensure that a given node is vm capable.
source code
 
RemoveInstance(lu, feedback_fn, instance, ignore_failures)
Utility function to remove an instance.
source code
boolean
RemoveDisks(lu, instance, target_node_uuid=None, ignore_failures=False)
Remove all disks for an instance.
source code
 
NICToTuple(lu, nic)
Build a tupple of nic information.
source code
 
NICListToTuple(lu, nics)
Build a list of nic information tuples.
source code
 
CopyLockList(names)
Makes a copy of a list of lock names.
source code
 
ReleaseLocks(lu, level, names=None, keep=None)
Releases locks owned by an LU.
source code
 
_ComputeIPolicyNodeViolation(ipolicy, instance, current_group, target_group, cfg, _compute_fn=ComputeIPolicyInstanceViolation)
Compute if instance meets the specs of the new target group.
source code
 
CheckTargetNodeIPolicy(lu, ipolicy, instance, node, cfg, ignore=False, _compute_fn=_ComputeIPolicyNodeViolation)
Checks that the target node is correct in terms of instance policy.
source code
 
GetInstanceInfoText(instance)
Compute that text that should be added to the disk's metadata.
source code
integer
CheckNodeFreeMemory(lu, node_uuid, reason, requested, hvname, hvparams)
Checks if a node has enough free memory.
source code
 
CheckInstanceBridgesExist(lu, instance, node_uuid=None)
Check that the brigdes needed by an instance exist.
source code
 
CheckNicsBridgesExist(lu, nics, node_uuid)
Check that the brigdes needed by a list of nics exist.
source code
NoneType
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.
source code
NoneType
CheckCompressionTool(lu, compression_tool)
Checks if the provided compression tool is allowed to be used.
source code
 
CheckInstanceExistence(lu, instance_name)
Raises an error if an instance with the given name exists already.
source code

Imports: logging, os, constants, errors, locking, network, objects, pathutils, utils, AnnotateDiskParams, ComputeIPolicyInstanceViolation, CheckDiskTemplateEnabled


Function Details [hide private]

BuildInstanceHookEnv(name, primary_node_name, secondary_node_names, os_type, status, minmem, maxmem, vcpus, nics, disk_template, disks, bep, hvp, hypervisor_name, tags)

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_name (string) - the name of the instance's primary node
  • secondary_node_names (list) - list of secondary nodes as strings
  • os_type (string) - the name of the instance's OS
  • status (string) - the desired status of the instance
  • minmem (string) - the minimum memory size of the instance
  • maxmem (string) - the maximum memory size of the instance
  • vcpus (string) - the count of VCPUs the instance has
  • nics (list) - list of tuples (name, uuid, ip, mac, mode, link, vlan, net, netinfo) representing the NICs the instance has
  • disk_template (string) - the disk template of the instance
  • disks (list) - list of tuples (name, uuid, size, mode)
  • bep (dict) - the backend parameters for the instance
  • hvp (dict) - the hypervisor parameters for the instance
  • hypervisor_name (string) - the hypervisor for the instance
  • tags (list) - list of instance tags as strings
Returns: dict
the hook environment for this instance

BuildInstanceHookEnvByObject(lu, instance, secondary_nodes=None, disks=None, 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

CheckNodeNotDrained(lu, node_uuid)

source code 

Ensure that a given node is not drained.

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

CheckNodeVmCapable(lu, node_uuid)

source code 

Ensure that a given node is vm capable.

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

RemoveDisks(lu, instance, target_node_uuid=None, ignore_failures=False)

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.

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

NICToTuple(lu, nic)

source code 

Build a tupple of nic information.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • nic (objects.NIC) - nic to convert to hooks tuple

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 LUInstanceQueryData.

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

CopyLockList(names)

source code 

Makes a copy of a list of lock names.

Handles locking.ALL_SET correctly.

ReleaseLocks(lu, level, names=None, keep=None)

source code 

Releases locks owned by an LU.

Parameters:
  • level - Lock level
  • names (list or None) - Names of locks to release
  • keep (list or None) - Names of locks to retain
  • lu (LogicalUnit)

_ComputeIPolicyNodeViolation(ipolicy, instance, current_group, target_group, cfg, _compute_fn=ComputeIPolicyInstanceViolation)

source code 

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

Parameters:
  • ipolicy - The ipolicy to verify
  • instance - The instance object to verify
  • current_group - The current group of the instance
  • target_group - The new group of the instance
  • cfg (config.ConfigWriter) - Cluster configuration
  • _compute_fn - The function to verify ipolicy (unittest only)

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

source code 

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

Parameters:
  • ipolicy - The ipolicy to verify
  • instance - The instance object to verify
  • node - The new node to relocate
  • cfg (config.ConfigWriter) - Cluster configuration
  • ignore - Ignore violations of the ipolicy
  • _compute_fn - The function to verify ipolicy (unittest only)

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

source code 

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 (LogicalUnit) - a logical unit from which we get configuration data
  • node_uuid (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
  • hvname (string) - the hypervisor's name
  • hvparams (dict of strings) - the hypervisor's parameters
Returns: integer
node current free memory
Raises:

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

source code 

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 (callable) - function used send feedback back to the caller
  • rpc (rpc.node.RpcRunner) - RPC runner
  • instance (objects.Instance) - instance for which the metadata should be updated
  • osparams_public (NoneType or dict) - public OS parameters used to override those defined in instance
  • osparams_private (NoneType or dict) - private OS parameters used to override those defined in instance
  • osparams_secret (NoneType or dict) - secret OS parameters used to override those defined in instance
Returns: NoneType
None

CheckCompressionTool(lu, compression_tool)

source code 

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

Parameters:
  • compression_tool (string) - Compression tool to use for importing or exporting the instance
Returns: NoneType
None
Raises:

CheckInstanceExistence(lu, instance_name)

source code 

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

Parameters:
  • instance_name (string) - The name of the instance.

    To be used in the locking phase.