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, secondary_nodes, 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, 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)
Ensure that a given node is not drained.
source code
 
CheckNodeVmCapable(lu, node)
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=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, reason, requested, hypervisor_name)
Checks if a node has enough free memory.
source code
 
CheckInstanceBridgesExist(lu, instance, node=None)
Check that the brigdes needed by an instance exist.
source code
 
CheckNicsBridgesExist(lu, target_nics, target_node)
Check that the brigdes needed by a list of nics exist.
source code
 
CheckNodeHasOS(lu, node, os_name, force_variant)
Ensure that a node supports a given OS.
source code
 
_CheckOSVariant(os_obj, name)
Check whether an OS name conforms to the os variants specification.
source code

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


Function Details [hide private]

BuildInstanceHookEnv(name, primary_node, secondary_nodes, 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 (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 (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, 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, 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)

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:

RemoveDisks(lu, instance, target_node=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 (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, reason, requested, hypervisor_name)

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 (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
Returns: integer
node current free memory
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:

_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