From d9b77dfca6707ebd5bb732451730b955775eeebb Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Wed, 15 Mar 2023 11:36:34 +0530 Subject: [PATCH] cephfs/admin: Add API to fetch volume info Signed-off-by: Anoop C S --- cephfs/admin/volume_info.go | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cephfs/admin/volume_info.go diff --git a/cephfs/admin/volume_info.go b/cephfs/admin/volume_info.go new file mode 100644 index 0000000..039a8f7 --- /dev/null +++ b/cephfs/admin/volume_info.go @@ -0,0 +1,48 @@ +//go:build !(nautilus || octopus) && ceph_preview +// +build !nautilus,!octopus,ceph_preview + +package admin + +// PoolInfo reports various properties of a pool. +type PoolInfo struct { + Available int `json:"avail"` + Name string `json:"name"` + Used int `json:"used"` +} + +// PoolType indicates the type of pool related to a volume. +type PoolType struct { + DataPool []PoolInfo `json:"data"` + MetadataPool []PoolInfo `json:"metadata"` +} + +// VolInfo holds various informational values about a volume. +type VolInfo struct { + MonAddrs []string `json:"mon_addrs"` + PendingSubvolDels int `json:"pending_subvolume_deletions"` + Pools PoolType `json:"pools"` + UsedSize int `json:"used_size"` +} + +func parseVolumeInfo(res response) (*VolInfo, error) { + var info VolInfo + if err := res.NoStatus().Unmarshal(&info).End(); err != nil { + return nil, err + } + return &info, nil +} + +// FetchVolumeInfo fetches the information of a CephFS volume. +// +// Similar To: +// +// ceph fs volume info +func (fsa *FSAdmin) FetchVolumeInfo(volume string) (*VolInfo, error) { + m := map[string]string{ + "prefix": "fs volume info", + "vol_name": volume, + "format": "json", + } + + return parseVolumeInfo(fsa.marshalMgrCommand(m)) +}