module documentation

Logical units dealing with storage of instances.

Class LUInstanceActivateDisks Bring up an instance's disks.
Class LUInstanceDeactivateDisks Shutdown an instance's disks.
Class LUInstanceGrowDisk Grow a disk of an instance.
Class LUInstanceRecreateDisks Recreate an instance's missing disks.
Class LUInstanceReplaceDisks Replace the disks of an instance.
Class TemporaryDisk Creates a new temporary bootable disk, and makes sure it is destroyed.
Class TLReplaceDisks Replaces disks for an instance.
Function AssembleInstanceDisks Prepare the block devices for an instance.
Function CalculateFileStorageDir Calculate final instance file storage dir.
Function CheckDiskConsistency Wrapper around _CheckDiskConsistencyInner.
Function CheckDiskExtProvider Check that the given disk should or should not have the provider param.
Function CheckNodesFreeDiskPerVG Checks if nodes have enough free disk space in all the VGs.
Function CheckRADOSFreeSpace Compute disk size requirements inside the RADOS cluster.
Function CheckSpindlesExclusiveStorage Check the presence of the spindle options with exclusive_storage.
Function CommitDisks Recursively remove the forthcoming flag
Function ComputeDisks Computes the instance disks.
Function ComputeDisksInfo Computes the new instance's disks for the template conversion.
Function ComputeDiskSizePerVG Compute disk size requirements in the volume group
Function CreateDisks Create all disks for an instance.
Function CreateSingleBlockDev Create a single block device on a given node.
Function ExpandCheckDisks Return the instance disks selected by the disks list
Function GenerateDiskTemplate Generate the entire disk layout for a given template type.
Function ImageDisks Dumps an image onto an instance disk.
Function IsExclusiveStorageEnabledNodeUuid Whether exclusive_storage is in effect for the given node.
Function ShutdownInstanceDisks Shutdown block devices of an instance.
Function StartInstanceDisks Start the disks of an instance.
Function WaitForSync Sleep and poll for an instance's disk to sync.
Function WipeDisks Wipes instance disks.
Function WipeOrCleanupDisks Wrapper for WipeDisks that handles errors.
Function _BlockdevFind Wrapper around call_blockdev_find to annotate diskparams.
Function _CalcEta Calculates the ETA based on size written and total size.
Function _CheckDiskConsistencyInner Check that mirrors are not degraded.
Function _CheckNodesFreeDiskOnVG Checks if nodes have enough free disk space in the specified VG.
Function _CheckVgCapacityForNode Checks the vg capacity for a given node.
Function _CreateBlockDev Wrapper around _CreateBlockDevInner.
Function _CreateBlockDevInner Create a tree of block devices on a given node.
Function _DiskSizeInBytesToMebibytes Converts a disk size in bytes to mebibytes.
Function _GenerateDRBD8Branch Generate a drbd8 device complete with its children.
Function _GenerateUniqueNames Generate a suitable LV name.
Function _PerformNodeInfoCall Prepares the input and performs a node info call.
Function _SafeShutdownInstanceDisks Shutdown block devices of an instance.
Function _UndoCreateDisks Undo the work performed by CreateDisks.
Constant _DISK_TEMPLATE_NAME_PREFIX Undocumented
def AssembleInstanceDisks(lu, instance, disks=None, ignore_secondaries=False, ignore_size=False):

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:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance for whose disks we assemble
disks:list of objects.Disk or Nonewhich disks to assemble (or all, if None)
ignore_secondaries:booleanif true, errors on secondary nodes won't result in an error return from the function
ignore_size:booleanif 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
def CalculateFileStorageDir(disk_type, cfg, instance_name, file_storage_dir=None):

Calculate final instance file storage dir.

Parameters
disk_type:disk templateconstants.DT_FILE, constants.DT_SHARED_FILE, or constants.DT_GLUSTER
cfg:ConfigWriterthe configuration that is to be used.
instance_name:stringname of the instance this disk is for.
file_storage_dir:paththe path below the configured base.
Returns
stringThe file storage directory for the instance
def CheckDiskConsistency(lu, instance, dev, node_uuid, on_primary, ldisk=False):
def CheckDiskExtProvider(diskdict, disk_template):

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

Parameters
diskdict:dictdisk parameters
disk_template:stringthe desired template of this disk
Raises
errors.OpPrereqErrorwhen the parameter is used in the wrong way
def CheckNodesFreeDiskPerVG(lu, node_uuids, req_sizes):

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:LogicalUnita logical unit from which we get configuration data
node_uuids:listthe list of node UUIDs to check
req_sizes:dictthe hash of vg and corresponding amount of disk in MiB to check for
Raises
errors.OpPrereqErrorif the node doesn't have enough disk, or we cannot check the node
def CheckRADOSFreeSpace():

Compute disk size requirements inside the RADOS cluster.

def CheckSpindlesExclusiveStorage(diskdict, es_flag, required):

Check the presence of the spindle options with exclusive_storage.

Parameters
diskdict:dictdisk parameters
es_flag:boolthe effective value of the exlusive_storage flag
required:boolwhether spindles are required or just optional @raise errors.OpPrereqError when spindles are given and they should not
def CommitDisks(disks):

Recursively remove the forthcoming flag

def ComputeDisks(disks, disk_template, default_vg):

Computes the instance disks.

Parameters
disks:list of dictionariesThe disks' input dictionary
disk_template:stringThe disk template of the instance
default_vg:stringThe default_vg to assume
Returns
The computed disks
def ComputeDisksInfo(disks, disk_template, default_vg, ext_params):

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:stringThe disk template of the instance
default_vg:stringThe default volume group to assume
ext_params:dictThe extstorage parameters
Returns
list of dictionariesThe computed disks' information for the new template
def ComputeDiskSizePerVG(disk_template, disks):

Compute disk size requirements in the volume group

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

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:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance whose disks we should create
disk_template:stringif provided, overrides the instance's disk_template
to_skip:listlist of indices to skip
target_node_uuid:stringif 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
errors.OpPrereqErrorin case of error
def CreateSingleBlockDev(lu, node_uuid, instance, device, info, force_open, excl_stor):

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
luthe lu on whose behalf we execute
node_uuidthe node on which to create the device
instance:objects.Instancethe instance which owns the device
device:objects.Diskthe device to create
infothe extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
force_open:booleanthis 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:booleanWhether exclusive_storage is active for the node
def ExpandCheckDisks(instance_disks, disks):

Return the instance disks selected by the disks list

Parameters
instance_disksUndocumented
disks:list of objects.Disk or Noneselected disks
Returns
list of objects.Diskselected instance disks to act on
def 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.

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

Dumps an image onto an instance disk.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance whose disks we should create
image:stringthe image whose disks we should create
disks:None or list of intsdisk indices
def IsExclusiveStorageEnabledNodeUuid(cfg, node_uuid):

Whether exclusive_storage is in effect for the given node.

Parameters
cfg:config.ConfigWriterThe cluster configuration
node_uuid:stringThe node UUID
Returns
boolThe effective value of exclusive_storage
Raises
errors.OpPrereqErrorif no node exists with the given name
def ShutdownInstanceDisks(lu, instance, disks=None, ignore_primary=False):

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.

def StartInstanceDisks(lu, instance, force):

Start the disks of an instance.

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

def WaitForSync(lu, instance, disks=None, oneshot=False):

Sleep and poll for an instance's disk to sync.

def WipeDisks(lu, instance, disks=None):

Wipes instance disks.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe 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
def WipeOrCleanupDisks(lu, instance, disks=None, cleanup=None):

Wrapper for WipeDisks that handles errors.

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
instance:objects.Instancethe instance whose disks we should wipe
diskssee WipeDisks
cleanupthe result returned by CreateDisks, used for cleanup in case of error
Raises
errors.OpPrereqErrorin case of failure
def _BlockdevFind(lu, node_uuid, dev, instance):

Wrapper around call_blockdev_find to annotate diskparams.

Parameters
luA reference to the lu object
node_uuidThe node to call out
devThe device to find
instanceThe instance object the device belongs to @returns The result of the rpc call
def _CalcEta(time_taken, written, total_size):

Calculates the ETA based on size written and total size.

Parameters
time_takenThe time taken so far
writtenamount written so far
total_sizeThe total size of data to be written
Returns
The remaining time in seconds
def _CheckDiskConsistencyInner(lu, instance, dev, node_uuid, on_primary, ldisk=False):

Check that mirrors are not degraded.

Unknown Field: 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).

def _CheckNodesFreeDiskOnVG(lu, node_uuids, vg, requested):

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:LogicalUnita logical unit from which we get configuration data
node_uuids:listthe list of node UUIDs to check
vg:strthe volume group to check
requested:intthe amount of disk in MiB to check for
Raises
errors.OpPrereqErrorif the node doesn't have enough disk, or we cannot check the node
def _CheckVgCapacityForNode(node_name, node_info, vg, requested):

Checks the vg capacity for a given node.

Parameters
node_name:stringthe name of the node
node_info:tuple (_, list of dicts, _)the result of the node info call for one node
vg:stringvolume group name
requested:intthe amount of disk in MiB to check for
Raises
errors.OpPrereqErrorif the node doesn't have enough disk, or we cannot check the node
def _CreateBlockDev(lu, node_uuid, instance, device, force_create, info, force_open):

Wrapper around _CreateBlockDevInner.

This method annotates the root device first.

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

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
luthe lu on whose behalf we execute
node_uuidthe node on which to create the device
instance:objects.Instancethe instance which owns the device
device:objects.Diskthe device to create
force_create:booleanwhether to force creation of this device; this will be change to True whenever we find a device which has CreateOnSecondary() attribute
infothe extra 'metadata' we should attach to the device (this will be represented as a LVM tag)
force_open:booleanthis 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:booleanWhether exclusive_storage is active for the node
Returns
list of created devices
Unknown Field: attention
The device has to be annotated already.
def _DiskSizeInBytesToMebibytes(lu, size):

Converts a disk size in bytes to mebibytes.

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

def _GenerateDRBD8Branch(lu, primary_uuid, secondary_uuid, size, vgnames, names, iv_name, forthcoming=False):

Generate a drbd8 device complete with its children.

def _GenerateUniqueNames(lu, exts):

Generate a suitable LV name.

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

def _PerformNodeInfoCall(lu, node_uuids, vg):

Prepares the input and performs a node info call.

Parameters
lu:LogicalUnita logical unit from which we get configuration data
node_uuids:list of stringlist of node UUIDs to perform the call for
vg:stringthe volume group's name
def _SafeShutdownInstanceDisks(lu, instance, disks=None, req_states=None):

Shutdown block devices of an instance.

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

def _UndoCreateDisks(lu, disks_created, instance):

Undo the work performed by CreateDisks.

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

Parameters
lu:LogicalUnitthe logical unit on whose behalf we execute
disks_createdthe result returned by CreateDisks
instance:objects.Instancethe instance for which disks were created
_DISK_TEMPLATE_NAME_PREFIX =

Undocumented

Value
{constants.DT_PLAIN: '',
 constants.DT_RBD: '.rbd',
 constants.DT_EXT: '.ext',
 constants.DT_FILE: '.file',
 constants.DT_SHARED_FILE: '.sharedfile'}