From: Neeraj Pratap Singh Date: Wed, 21 Sep 2022 06:28:29 +0000 (+0530) Subject: mgr/volumes: Add human-readable flag to volume info command X-Git-Tag: v17.2.6~97^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a896e5ba2d9e171212576d4c6563ec776094ddd8;p=ceph.git mgr/volumes: Add human-readable flag to volume info command This PR intends to add a human-readable flag to the volume info command so that the used and avail size can be shown with units according to the size. Fixes: https://tracker.ceph.com/issues/57620 Signed-off-by: Neeraj Pratap Singh (cherry picked from commit 535b86ac94ae84cf651d5710ba3150ed9b30dbd4) --- diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index 335d76a809a..6d465febc5e 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -2,6 +2,7 @@ import json import errno import logging import os +import mgr_util from typing import TYPE_CHECKING import cephfs @@ -152,6 +153,7 @@ class VolumeClient(CephfsClient["Module"]): def volume_info(self, **kwargs): ret = None volname = kwargs['vol_name'] + human_readable = kwargs['human_readable'] try: with open_volume(self, volname) as fs_handle: @@ -163,7 +165,10 @@ class VolumeClient(CephfsClient["Module"]): usedbytes = st['size'] vol_info_dict = get_pending_subvol_deletions_count(path) - vol_info_dict['used_size'] = int(usedbytes) + if human_readable: + vol_info_dict['used_size'] = mgr_util.format_bytes(int(usedbytes), 5) + else: + vol_info_dict['used_size'] = int(usedbytes) except cephfs.Error as e: if e.args[0] == errno.ENOENT: pass @@ -178,10 +183,16 @@ class VolumeClient(CephfsClient["Module"]): pool_type = "metadata" else: pool_type = "data" - vol_info_dict["pools"][pool_type].append({ - 'name': pools[pool_id]['pool_name'], - 'used': pool_stats[pool_id]['bytes_used'], - 'avail': pool_stats[pool_id]['max_avail']}) + if human_readable: + vol_info_dict["pools"][pool_type].append({ + 'name': pools[pool_id]['pool_name'], + 'used': mgr_util.format_bytes(pool_stats[pool_id]['bytes_used'], 5), + 'avail': mgr_util.format_bytes(pool_stats[pool_id]['max_avail'], 5)}) + else: + vol_info_dict["pools"][pool_type].append({ + 'name': pools[pool_id]['pool_name'], + 'used': pool_stats[pool_id]['bytes_used'], + 'avail': pool_stats[pool_id]['max_avail']}) mon_addr_lst = [] mon_map_mons = self.mgr.get('mon_map')['mons'] diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 752dde33e3e..b9c8e789343 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -70,7 +70,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): }, { 'cmd': 'fs volume info ' - 'name=vol_name,type=CephString ', + 'name=vol_name,type=CephString ' + 'name=human_readable,type=CephBool,req=false ', 'desc': "Get the information of a CephFS volume", 'perm': 'r' }, @@ -555,7 +556,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): @mgr_cmd_wrap def _cmd_fs_volume_info(self, inbuf, cmd): - return self.vc.volume_info(vol_name=cmd['vol_name']) + return self.vc.volume_info(vol_name=cmd['vol_name'], + human_readable=cmd.get('human_readable', False)) @mgr_cmd_wrap def _cmd_fs_subvolumegroup_create(self, inbuf, cmd):