module documentation

Utility functions for storage.

Function CreateBdevPartitionMapping Create dm device for each partition of disk image.
Function DiskTemplateSupportsSpaceReporting Check whether the disk template supports storage space reporting.
Function GetDiskLabels Generate disk labels for a number of disks
Function GetDiskTemplatesOfStorageTypes Given the storage type, returns a list of disk templates based on that storage type.
Function GetStorageUnits Get the cluster's storage units for the given disk templates.
Function IsDiskTemplateEnabled Checks if a particular disk template is enabled.
Function IsFileStorageEnabled Checks if file storage is enabled.
Function IsLvmEnabled Check whether or not any lvm-based disk templates are enabled.
Function IsSharedFileStorageEnabled Checks if shared file storage is enabled.
Function LookupSpaceInfoByDiskTemplate Looks up the storage space info for a given disk template.
Function LookupSpaceInfoByStorageType Looks up the storage space info for a given storage type.
Function LvmGetsEnabled Checks whether lvm was not enabled before, but will be enabled after the operation.
Function osminor Return the device minor number from a raw device number.
Function ReleaseBdevPartitionMapping Release allocated dm devices and loopback devices.
Function _GetDefaultStorageUnitForDiskTemplate Retrieves the identifier of the default storage entity for the given storage type.
def CreateBdevPartitionMapping(image_path):

Create dm device for each partition of disk image.

This operation will allocate a loopback and a device-mapper device to map partitions. You must call ReleaseBdevPartitionMapping to clean up resources allocated by this function call.

Parameters
image_path:stringpath of multi-partition disk image
Returns
tuple(string, list(string)) or NoneTypereturns the tuple(loopback_device, list(device_mapper_files)) if image_path is a multi-partition disk image. otherwise, returns None.
def DiskTemplateSupportsSpaceReporting(disk_template):

Check whether the disk template supports storage space reporting.

def GetDiskLabels(prefix, num_disks, start=0):

Generate disk labels for a number of disks

Note that disk labels are generated in the range [start..num_disks[ (e.g., as in range(start, num_disks))

Parameters
prefix:stringdisk label prefix (e.g., "/dev/sd")
num_disks:intnumber of disks (i.e., disk labels)
start:intoptional start index
Returns
generatorgenerator for the disk labels
def GetDiskTemplatesOfStorageTypes(*storage_types):

Given the storage type, returns a list of disk templates based on that storage type.

def GetStorageUnits(cfg, disk_templates):

Get the cluster's storage units for the given disk templates.

If any lvm-based disk template is requested, spindle information is added to the request.

Parameters
cfg:config.ConfigWriterCluster configuration
disk_templates:list of stringlist of disk templates for which the storage units will be computed
Returns
list of tuples (string, string)list of storage units, each storage unit being a tuple of (storage_type, storage_key); storage_type is in constants.STORAGE_TYPES and the storage_key a string to identify an entity of that storage type, for example a volume group name for LVM storage or a file for file storage.
def IsDiskTemplateEnabled(disk_template, enabled_disk_templates):

Checks if a particular disk template is enabled.

def IsFileStorageEnabled(enabled_disk_templates):

Checks if file storage is enabled.

def IsLvmEnabled(enabled_disk_templates):

Check whether or not any lvm-based disk templates are enabled.

def IsSharedFileStorageEnabled(enabled_disk_templates):

Checks if shared file storage is enabled.

def LookupSpaceInfoByDiskTemplate(storage_space_info, disk_template):

Looks up the storage space info for a given disk template.

Parameters
storage_space_info:list of dictsresult of GetNodeInfo
disk_template:stringdisk template to get storage space info
Returns
tuplereturns the element of storage_space_info that matches the given disk template
def LookupSpaceInfoByStorageType(storage_space_info, storage_type):

Looks up the storage space info for a given storage type.

Note that this lookup can be ambiguous if storage space reporting for several units of the same storage type was requested. This function is only supposed to be used for legacy code in situations where it actually is unambiguous.

Parameters
storage_space_info:list of dictsresult of GetNodeInfo
storage_type:stringa storage type, which is included in the storage_units list
Returns
tuplereturns the element of storage_space_info that matches the given storage type
def LvmGetsEnabled(enabled_disk_templates, new_enabled_disk_templates):

Checks whether lvm was not enabled before, but will be enabled after the operation.

def osminor(dev):

Return the device minor number from a raw device number.

This is a replacement for os.minor working around the issue that Python's os.minor still has the old definition. See Ganeti issue 1058 for more details.

def ReleaseBdevPartitionMapping(loop_dev_path):

Release allocated dm devices and loopback devices.

Parameters
loop_dev_path:stringpath of loopback device returned by CreateBdevPartitionMapping
def _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template):

Retrieves the identifier of the default storage entity for the given storage type.

Parameters
cfg:objects.ConfigDatathe configuration data
disk_template:stringa disk template, for example 'drbd'
Returns
stringidentifier for a storage unit, for example the vg_name for lvm storage