We add a new field storage_ids to the RAPI output of basic instance information. This information is retrieved from the instance disks' logical ids, so that for each disk it is either a part of the storage path or a unique name used for external storage. Note that there will be no value returned for DRBD disks.
Signed-off-by: Lisa Velden <[email protected]> --- lib/query.py | 3 +++ lib/rapi/rlib2.py | 2 +- src/Ganeti/Objects/Disk.hs | 14 ++++++++++++++ src/Ganeti/Query/Instance.hs | 12 ++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/query.py b/lib/query.py index 085a60d..36f35eb 100644 --- a/lib/query.py +++ b/lib/query.py @@ -2008,6 +2008,9 @@ def _GetInstanceDiskFields(): IQ_CONFIG, 0, lambda ctx, inst: [disk.name for disk in inst.disks]), (_MakeField("disk.uuids", "Disk_UUIDs", QFT_OTHER, "List of disk UUIDs"), IQ_CONFIG, 0, lambda ctx, inst: [disk.uuid for disk in inst.disks]), + (_MakeField("disk.storage_ids", "Disk_storage_ids", QFT_OTHER, + "List of disk storage ids"), + IQ_CONFIG, 0, lambda ctx, inst: [disk.storage_id for disk in inst.disks]), ] # Disks by number diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index 8b624d4..baec638 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -83,7 +83,7 @@ I_FIELDS = ["name", "admin_state", "os", "nic.links", "nic.networks", "nic.networks.names", "nic.bridges", "network_port", "disk.sizes", "disk.spindles", "disk_usage", "disk.uuids", - "disk.names", + "disk.names", "disk.storage_ids", "beparams", "hvparams", "oper_state", "oper_ram", "oper_vcpus", "status", "custom_hvparams", "custom_beparams", "custom_nicparams", diff --git a/src/Ganeti/Objects/Disk.hs b/src/Ganeti/Objects/Disk.hs index 4e95749..f402d7c 100644 --- a/src/Ganeti/Objects/Disk.hs +++ b/src/Ganeti/Objects/Disk.hs @@ -152,6 +152,20 @@ lidDiskType (LIDExt {}) = DTExt lidEncodeType :: DiskLogicalId -> [(String, JSValue)] lidEncodeType v = [(devType, showJSON . lidDiskType $ v)] +-- | Returns the storage path or the unique name for a given logical id if +-- present +getStorageId :: DiskLogicalId -> Maybe String +getStorageId dlid = + case dlid of + LIDPlain lv -> Just $ lvGroup lv ++ "/" ++ lvVolume lv + LIDDrbd8 {} -> Nothing + LIDFile _ path -> Just path + LIDSharedFile _ path -> Just path + LIDGluster _ path -> Just path + LIDBlockDev _ path -> Just path + LIDRados _ path -> Just path + LIDExt _ uniqueName -> Just uniqueName + -- | Custom encoder for DiskLogicalId (logical id only). encodeDLId :: DiskLogicalId -> JSValue encodeDLId (LIDPlain (LogicalVolume vg lv)) = diff --git a/src/Ganeti/Query/Instance.hs b/src/Ganeti/Query/Instance.hs index 4d2e660..9a7378a 100644 --- a/src/Ganeti/Query/Instance.hs +++ b/src/Ganeti/Query/Instance.hs @@ -207,6 +207,9 @@ instanceFields = , (FieldDefinition "disk.uuids" "Disk_UUIDs" QFTOther "List of disk UUIDs", FieldConfig getDiskUuids, QffNormal) + , (FieldDefinition "disk.storage_ids" "Disk_storage_ids" QFTOther + "List of disk storage ids", + FieldConfig getStorageIds, QffNormal) -- For pre-2.14 backwards compatibility , (FieldDefinition "disk_template" "Disk_template" QFTText "Instance disk template", @@ -416,6 +419,15 @@ getDiskUuids :: ConfigData -> Instance -> ResultEntry getDiskUuids cfg = rsErrorNoData . liftA (map uuidOf) . getInstDisksFromObj cfg +-- | Get a list of disk storage ids for an instance. Note that for DRBD the list +-- will be empty. +getStorageIds :: ConfigData -> Instance -> ResultEntry +getStorageIds cfg = rsErrorNoData . + liftA (map MaybeForJSON . filter isJust . mapMaybe storageId) . + getInstDisksFromObj cfg + where + storageId x = getStorageId <$> diskLogicalId x + -- | Creates a functions which produces a FieldConfig 'FieldGetter' when fed -- an index. Works for fields that may not return a value, expressed through -- the Maybe monad. -- 2.6.0.rc2.230.g3dd15c0
