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

Module instance_storage

source code

Logical units dealing with storage of instances.

Classes [hide private]
  LUInstanceRecreateDisks
Recreate an instance's missing disks.
  LUInstanceGrowDisk
Grow a disk of an instance.
  LUInstanceReplaceDisks
Replace the disks of an instance.
  LUInstanceActivateDisks
Bring up an instance's disks.
  LUInstanceDeactivateDisks
Shutdown an instance's disks.
  TLReplaceDisks
Replaces disks for an instance.
  TemporaryDisk
Creates a new temporary bootable disk, and makes sure it is destroyed.
Functions [hide private]
 
CreateSingleBlockDev(lu, node_uuid, instance, device, info, force_open, excl_stor)
Create a single block device on a given node.
source code
 
_CreateBlockDevInner(lu, node_uuid, instance, device, force_create, info, force_open, excl_stor)
Create a tree of block devices on a given node.
source code
bool
IsExclusiveStorageEnabledNodeUuid(cfg, node_uuid)
Whether exclusive_storage is in effect for the given node.
source code
 
_CreateBlockDev(lu, node_uuid, instance, device, force_create, info, force_open)
Wrapper around _CreateBlockDevInner.
source code
 
_UndoCreateDisks(lu, disks_created, instance)
Undo the work performed by CreateDisks.
source code
 
CreateDisks(lu, instance, disk_template=None, to_skip=None, target_node_uuid=None, disks=None)
Create all disks for an instance.
source code
 
ComputeDiskSizePerVG(disk_template, disks)
Compute disk size requirements in the volume group
source code
 
ComputeDisks(disks, disk_template, default_vg)
Computes the instance disks.
source code
list of dictionaries
ComputeDisksInfo(disks, disk_template, default_vg, ext_params)
Computes the new instance's disks for the template conversion.
source code
string
CalculateFileStorageDir(disk_type, cfg, instance_name, file_storage_dir=None)
Calculate final instance file storage dir.
source code
 
CheckRADOSFreeSpace()
Compute disk size requirements inside the RADOS cluster.
source code
 
_GenerateDRBD8Branch(lu, primary_uuid, secondary_uuid, size, vgnames, names, iv_name, forthcoming=False)
Generate a drbd8 device complete with its children.
source code
 
GenerateDiskTemplate(lu, template_name, instance_uuid, primary_node_uuid, secondary_node_uuids, disk_info, file_storage_dir, file_driver, base_index, feedback_fn, full_disk_params, forthcoming=False)
Generate the entire disk layout for a given template type.
source code
 
CommitDisks(disks)
Recursively remove the forthcoming flag
source code
 
CheckSpindlesExclusiveStorage(diskdict, es_flag, required)
Check the presence of the spindle options with exclusive_storage.
source code
 
CheckDiskExtProvider(diskdict, disk_template)
Check that the given disk should or should not have the provider param.
source code
 
_PerformNodeInfoCall(lu, node_uuids, vg)
Prepares the input and performs a node info call.
source code
 
_CheckVgCapacityForNode(node_name, node_info, vg, requested)
Checks the vg capacity for a given node.
source code
 
_CheckNodesFreeDiskOnVG(lu, node_uuids, vg, requested)
Checks if nodes have enough free disk space in the specified VG.
source code
 
CheckNodesFreeDiskPerVG(lu, node_uuids, req_sizes)
Checks if nodes have enough free disk space in all the VGs.
source code
 
_DiskSizeInBytesToMebibytes(lu, size)
Converts a disk size in bytes to mebibytes.
source code
 
_CalcEta(time_taken, written, total_size)
Calculates the ETA based on size written and total size.
source code
 
WipeDisks(lu, instance, disks=None)
Wipes instance disks.
source code
 
ImageDisks(lu, instance, image, disks=None)
Dumps an image onto an instance disk.
source code
 
WipeOrCleanupDisks(lu, instance, disks=None, cleanup=None)
Wrapper for WipeDisks that handles errors.
source code
list of objects.Disk
ExpandCheckDisks(instance_disks, disks)
Return the instance disks selected by the disks list
source code
 
WaitForSync(lu, instance, disks=None, oneshot=False)
Sleep and poll for an instance's disk to sync.
source code
 
ShutdownInstanceDisks(lu, instance, disks=None, ignore_primary=False)
Shutdown block devices of an instance.
source code
 
_SafeShutdownInstanceDisks(lu, instance, disks=None, req_states=None)
Shutdown block devices of an instance.
source code
 
AssembleInstanceDisks(lu, instance, disks=None, ignore_secondaries=False, ignore_size=False)
Prepare the block devices for an instance.
source code
 
StartInstanceDisks(lu, instance, force)
Start the disks of an instance.
source code
 
_CheckDiskConsistencyInner(lu, instance, dev, node_uuid, on_primary, ldisk=False)
Check that mirrors are not degraded.
source code
 
CheckDiskConsistency(lu, instance, dev, node_uuid, on_primary, ldisk=False)
Wrapper around _CheckDiskConsistencyInner.
source code
 
_BlockdevFind(lu, node_uuid, dev, instance)
Wrapper around call_blockdev_find to annotate diskparams.
source code
 
_GenerateUniqueNames(lu, exts)
Generate a suitable LV name.
source code
Variables [hide private]
  _DISK_TEMPLATE_NAME_PREFIX = {constants.DT_PLAIN: "", constant...

Imports: itertools, logging, os, time, compat, constants, errors, ht, locking, iallocator, objects, utils, rpc, LogicalUnit, NoHooksLU, Tasklet, INSTANCE_DOWN, INSTANCE_NOT_RUNNING, AnnotateDiskParams, CheckIAllocatorOrNode, ExpandNodeUuidAndName, ComputeIPolicyDiskSizesViolation, CheckNodeOnline, CheckInstanceNodeGroups, CheckInstanceState, IsExclusiveStorageEnabledNode, FindFaultyInstanceDisks, GetWantedNodes, CheckDiskTemplateEnabled, GetInstanceInfoText, CopyLockList, ReleaseLocks, CheckNodeVmCapable, BuildInstanceHookEnvByObject, CheckNodeNotDrained, CheckTargetNodeIPolicy, ganeti


Function Details [hide private]

CreateSingleBlockDev(lu, node_uuid, instance, device, info, force_open, excl_stor)

source code 

Create a single block device on a given node.

This will not recurse over children of the device, so they must be created in advance.

Parameters:
  • lu - the lu on whose behalf we execute
  • node_uuid - the node on which to create the device
  • instance (objects.Instance) - the instance which owns the device
  • device (objects.Disk) - the device to create
  • info - the extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
  • force_open (boolean) - this parameter will be passes to the backend.BlockdevCreate function where it specifies whether we run on primary or not, and it affects both the child assembly and the device own Open() execution
  • excl_stor (boolean) - Whether exclusive_storage is active for the node

_CreateBlockDevInner(lu, node_uuid, instance, device, force_create, info, force_open, excl_stor)

source code 

Create a tree of block devices on a given node.

If this device type has to be created on secondaries, create it and all its children.

If not, just recurse to children keeping the same 'force' value.

Parameters:
  • lu - the lu on whose behalf we execute
  • node_uuid - the node on which to create the device
  • instance (objects.Instance) - the instance which owns the device
  • device (objects.Disk) - the device to create
  • force_create (boolean) - whether to force creation of this device; this will be change to True whenever we find a device which has CreateOnSecondary() attribute
  • info - the extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
  • force_open (boolean) - this parameter will be passes to the backend.BlockdevCreate function where it specifies whether we run on primary or not, and it affects both the child assembly and the device own Open() execution
  • excl_stor (boolean) - Whether exclusive_storage is active for the node
Returns:
list of created devices

Attention: The device has to be annotated already.

IsExclusiveStorageEnabledNodeUuid(cfg, node_uuid)

source code 

Whether exclusive_storage is in effect for the given node.

Parameters:
Returns: bool
The effective value of exclusive_storage
Raises:

_CreateBlockDev(lu, node_uuid, instance, device, force_create, info, force_open)

source code 

Wrapper around _CreateBlockDevInner.

This method annotates the root device first.

_UndoCreateDisks(lu, disks_created, instance)

source code 

Undo the work performed by CreateDisks.

This function is called in case of an error to undo the work of CreateDisks.

Parameters:

CreateDisks(lu, instance, disk_template=None, to_skip=None, target_node_uuid=None, disks=None)

source code 

Create all disks for an instance.

This abstracts away some work from AddInstance.

Since the instance may not have been saved to the config file yet, this function can not query the config file for the instance's disks; in that case they need to be passed as an argument.

This function is also used by the disk template conversion mechanism to create the new disks of the instance. Since the instance will have the old template at the time we create the new disks, the new template must be passed as an extra argument.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should create
  • disk_template (string) - if provided, overrides the instance's disk_template
  • to_skip (list) - list of indices to skip
  • target_node_uuid (string) - if passed, overrides the target node for creation
  • disks (list of {objects.Disk}) - the disks to create; if not specified, all the disks of the instance are created
Returns:
information about the created disks, to be used to call _UndoCreateDisks
Raises:

ComputeDisks(disks, disk_template, default_vg)

source code 

Computes the instance disks.

Parameters:
  • disks (list of dictionaries) - The disks' input dictionary
  • disk_template (string) - The disk template of the instance
  • default_vg (string) - The default_vg to assume
Returns:
The computed disks

ComputeDisksInfo(disks, disk_template, default_vg, ext_params)

source code 

Computes the new instance's disks for the template conversion.

This method is used by the disks template conversion mechanism. Using the 'ComputeDisks' method as an auxiliary method computes the disks that will be used for generating the new disk template of the instance. It computes the size, mode, and name parameters from the instance's current disks, such as the volume group and the access parameters for the templates that support them. For conversions targeting an extstorage template, the mandatory provider's name or any user-provided extstorage parameters will also be included in the result.

Parameters:
  • disks (list of {objects.Disk}) - The current disks of the instance
  • disk_template (string) - The disk template of the instance
  • default_vg (string) - The default volume group to assume
  • ext_params (dict) - The extstorage parameters
Returns: list of dictionaries
The computed disks' information for the new template

CalculateFileStorageDir(disk_type, cfg, instance_name, file_storage_dir=None)

source code 

Calculate final instance file storage dir.

Parameters:
  • disk_type (disk template) - constants.DT_FILE, constants.DT_SHARED_FILE, or constants.DT_GLUSTER
  • cfg (ConfigWriter) - the configuration that is to be used.
  • file_storage_dir (path) - the path below the configured base.
  • instance_name (string) - name of the instance this disk is for.
Returns: string
The file storage directory for the instance

CheckSpindlesExclusiveStorage(diskdict, es_flag, required)

source code 

Check the presence of the spindle options with exclusive_storage.

Parameters:
  • diskdict (dict) - disk parameters
  • es_flag (bool) - the effective value of the exlusive_storage flag
  • required (bool) - whether spindles are required or just optional @raise errors.OpPrereqError when spindles are given and they should not

CheckDiskExtProvider(diskdict, disk_template)

source code 

Check that the given disk should or should not have the provider param.

Parameters:
  • diskdict (dict) - disk parameters
  • disk_template (string) - the desired template of this disk
Raises:

_PerformNodeInfoCall(lu, node_uuids, vg)

source code 

Prepares the input and performs a node info call.

Parameters:
  • lu (LogicalUnit) - a logical unit from which we get configuration data
  • node_uuids (list of string) - list of node UUIDs to perform the call for
  • vg (string) - the volume group's name

_CheckVgCapacityForNode(node_name, node_info, vg, requested)

source code 

Checks the vg capacity for a given node.

Parameters:
  • node_info (tuple (_, list of dicts, _)) - the result of the node info call for one node
  • node_name (string) - the name of the node
  • vg (string) - volume group name
  • requested (int) - the amount of disk in MiB to check for
Raises:

_CheckNodesFreeDiskOnVG(lu, node_uuids, vg, requested)

source code 

Checks if nodes have enough free disk space in the specified VG.

This function checks if all given nodes have the needed amount of free disk. In case any node has less disk 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_uuids (list) - the list of node UUIDs to check
  • vg (str) - the volume group to check
  • requested (int) - the amount of disk in MiB to check for
Raises:

CheckNodesFreeDiskPerVG(lu, node_uuids, req_sizes)

source code 

Checks if nodes have enough free disk space in all the VGs.

This function checks if all given nodes have the needed amount of free disk. In case any node has less disk 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_uuids (list) - the list of node UUIDs to check
  • req_sizes (dict) - the hash of vg and corresponding amount of disk in MiB to check for
Raises:

_DiskSizeInBytesToMebibytes(lu, size)

source code 

Converts a disk size in bytes to mebibytes.

Warns and rounds up if the size isn't an even multiple of 1 MiB.

_CalcEta(time_taken, written, total_size)

source code 

Calculates the ETA based on size written and total size.

Parameters:
  • time_taken - The time taken so far
  • written - amount written so far
  • total_size - The total size of data to be written
Returns:
The remaining time in seconds

WipeDisks(lu, instance, disks=None)

source code 

Wipes instance disks.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should create
  • disks (None or list of tuple of (number, objects.Disk, number)) - Disk details; tuple contains disk index, disk object and the start offset

ImageDisks(lu, instance, image, disks=None)

source code 

Dumps an image onto an instance disk.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should create
  • image (string) - the image whose disks we should create
  • disks (None or list of ints) - disk indices

WipeOrCleanupDisks(lu, instance, disks=None, cleanup=None)

source code 

Wrapper for WipeDisks that handles errors.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance whose disks we should wipe
  • disks - see WipeDisks
  • cleanup - the result returned by CreateDisks, used for cleanup in case of error
Raises:

ExpandCheckDisks(instance_disks, disks)

source code 

Return the instance disks selected by the disks list

Parameters:
Returns: list of objects.Disk
selected instance disks to act on

ShutdownInstanceDisks(lu, instance, disks=None, ignore_primary=False)

source code 

Shutdown block devices of an instance.

This does the shutdown on all nodes of the instance.

If the ignore_primary is false, errors on the primary node are ignored.

Modifies the configuration of the instance, so the caller should re-read the instance configuration, if needed.

_SafeShutdownInstanceDisks(lu, instance, disks=None, req_states=None)

source code 

Shutdown block devices of an instance.

This function checks if an instance is running, before calling _ShutdownInstanceDisks.

AssembleInstanceDisks(lu, instance, disks=None, ignore_secondaries=False, ignore_size=False)

source code 

Prepare the block devices for an instance.

This sets up the block devices on all nodes.

Modifies the configuration of the instance, so the caller should re-read the instance configuration, if needed.

Parameters:
  • lu (LogicalUnit) - the logical unit on whose behalf we execute
  • instance (objects.Instance) - the instance for whose disks we assemble
  • disks (list of objects.Disk or None) - which disks to assemble (or all, if None)
  • ignore_secondaries (boolean) - if true, errors on secondary nodes won't result in an error return from the function
  • ignore_size (boolean) - if true, the current known size of the disk will not be used during the disk activation, useful for cases when the size is wrong
Returns:
False if the operation failed, otherwise a list of (host, instance_visible_name, node_visible_name) with the mapping from node devices to instance devices, as well as the payloads of the RPC calls

StartInstanceDisks(lu, instance, force)

source code 

Start the disks of an instance.

Modifies the configuration of the instance, so the caller should re-read the instance configuration, if needed.

_CheckDiskConsistencyInner(lu, instance, dev, node_uuid, on_primary, ldisk=False)

source code 

Check that mirrors are not degraded.

Attention: The device has to be annotated already.

The ldisk parameter, if True, will change the test from the is_degraded attribute (which represents overall non-ok status for the device(s)) to the ldisk (representing the local storage status).

_BlockdevFind(lu, node_uuid, dev, instance)

source code 

Wrapper around call_blockdev_find to annotate diskparams.

Parameters:
  • lu - A reference to the lu object
  • node_uuid - The node to call out
  • dev - The device to find
  • instance - The instance object the device belongs to @returns The result of the rpc call

_GenerateUniqueNames(lu, exts)

source code 

Generate a suitable LV name.

This will generate a logical volume name for the given instance.


Variables Details [hide private]

_DISK_TEMPLATE_NAME_PREFIX

Value:
{constants.DT_PLAIN: "", constants.DT_RBD: ".rbd", constants.DT_EXT: "\
.ext", constants.DT_FILE: ".file", constants.DT_SHARED_FILE: ".sharedf\
ile",}