Common functions

Common storage functionality.

lmi.scripts.storage.common.escape_cql(s)

Escape potentially unsafe string for CQL.

It is generally not possible to do anything really harmful in CQL (there is no DELETE nor DROP TABLE), but just to be nice, all strings passed to CQL should escape backslash ‘’ and double quote ‘”’.

Parameters:s (string) – String to escape.
Return type:string
lmi.scripts.storage.common.get_children(ns, obj, deep=False)

Return list of all children of given LMIInstance.

For example:

  • If obj is LMIInstance/LMI_VGStoragePool (=Volume Group), it returns all its Logical Volumes (=LMIInstance/LMI_LVStorageExtent).
  • If obj is LMIInstance/LMI_StorageExtent of a disk, it returns all its partitions (=LMIInstance/CIM_GenericDiskPartition).
  • If obj is LMIInstance/LMI_DiskPartition and the partition is Physical Volume of a Volume Group,, it returns the pool (LMIInstance/LMI_VGStoragePool).
Parameters:
  • obj (LMIInstance/CIM_StorageExtent or LMIInstance/LMI_VGStoragePool or string) – Object to find children of.
  • deep (Boolean) – Whether all children of the object should be returned or only immediate ones.
lmi.scripts.storage.common.get_devices(ns, devices=None)

Returns list of block devices. If no devices are given, all block devices on the system are returned.

This functions just converts list of strings to list of appropriate LMIInstances.

Parameters:devices (list of LMIInstance/CIM_StorageExtent or list of strings) – Devices to list.
Return type:list of LMIInstance/CIM_StorageExtent.
lmi.scripts.storage.common.get_parents(ns, obj, deep=False)

Return list of all parents of given LMIInstance.

For example:

  • If obj is LMIInstance/LMI_LVStorageExtent (=Logical Volume), it returns LMIInstance/LMI_VGStoragePool (=Volume Group).
  • If obj is LMIInstance/LMI_VGStoragePool (=Volume Group), it returns all its Physical Volumes (=LMIInstance/CIM_StorageExtent).
Parameters:
  • obj (LMIInstance/CIM_StorageExtent or LMIInstance/LMI_VGStoragePool or string) – Object to find parents of.
  • deep (Boolean) – Whether all parents of the object should be returned or only immediate ones.
lmi.scripts.storage.common.size2str(size, human_friendly)

Convert size (in bytes) to string.

Parameters:
  • size (int) – Size of something in bytes.
  • human_friendly (bool) – If True, the returned string is returned in human-friendly units (KB, MB, ...).
Return type:

string

lmi.scripts.storage.common.str2device(ns, device)

Convert string with name of device to LMIInstance of the device. If LMIInstance is provided, nothing is done and the instance is just returned. If string is given, appropriate LMIInstance is looked up and returned. This functions throws an error when the device cannot be found.

The main purpose of this function is to convert parameters in functions, where both string and LMIInstance is allowed.

Parameters:device (LMIInstance/CIM_StorageExtent or string with name of device) – Device to convert.
Return type:LMIInstance/CIM_StorageExtent
lmi.scripts.storage.common.str2obj(ns, obj)

Convert string with name of device or volume group to LMIInstance of the device or the volume group.

If LMIInstance is provided, nothing is done and the instance is just returned. If string is given, appropriate LMIInstance is looked up and returned. This functions throws an error when the device or volume group cannot be found.

The main purpose of this function is to convert parameters in functions, where both string and LMIInstance is allowed.

Parameters:obj (LMIInstance/CIM_StorageExtent or LMIInstance/LMI_VGStoragePool or string with name of device or pool) – Object to convert.
Return type:LMIInstance/CIM_StorageExtent or LMIInstance/LMI_VGStoragePool
lmi.scripts.storage.common.str2size(size, additional_unit_size=None, additional_unit_suffix=None)

Convert string from human-friendly size to bytes. The string is expected to be integer number, optionally with on of these suffixes:

  • k, K - kilobytes, 1024 bytes,
  • m, M - megabytes, 1024 * 1024 bytes,
  • g, G - gigabytes, 1024 * 1024 * 1024 bytes,
  • t, T - terabytes, 1024 * 1024 * 1024 * 1024 bytes,
Parameters:
  • size (string) – The size to convert.
  • additional_unit_size (int) – Additional unit size for additional_unit_suffix, e.g. 4 * 1024*1024 for extent size.
  • additional_unit_suffix (string) – Additional suffix, e.g. ‘E’ for extents.
Return type:

int

lmi.scripts.storage.common.str2vg(ns, vg)

Convert string with name of volume group to LMIInstance of the LMI_VGStoragePool.

If LMIInstance is provided, nothing is done and the instance is just returned. If string is provided, appropriate LMIInstance is looked up and returned.

This functions throws an error when the device cannot be found.

The main purpose of this function is to convert parameters in functions, where both string and LMIInstance is allowed.

Parameters:vg (LMIInstance/LMI_VGStoragePool or string) – VG to retrieve.
Return type:LMIInstance/LMI_VGStoragePool