cloudstack-cloudmonkey icon indicating copy to clipboard operation
cloudstack-cloudmonkey copied to clipboard

add human readable output

Open pdion891 opened this issue 4 years ago • 7 comments

when displaying volume info, it would be great if we could see the size attribute in human readable form instead of scientific, example:

current output:

> list volumes type=DATADISK filter=size
count = 1
volume:
+-----------------+
|      SIZE       |
+-----------------+
| 5.36870912e+10  |
+-----------------+

new output:

> list volumes type=DATADISK filter=size
count = 1
volume:
+-----------------+
|      SIZE       |
+-----------------+
|      50 GB      |
+-----------------+

Maybe we could have a configuration humanformat=true in the config file too ?

pdion891 avatar Aug 26 '21 18:08 pdion891

Good idea, I think it's sort of a regression - we shouldn't round of to the x.xeY format. This only happens for the text output, does not happy for the json output. The immediate fix we can attempt is to output the same number (as-is) than change the format cc @Pearl1594

rohityadavcloud avatar Aug 27 '21 08:08 rohityadavcloud

The linked PR fixes the formatting issue, however it doesn't do what @pdion891 has asked - PL please check if the PR is sufficient to close the ticket as ideally the human readable change should come from API key so the CLI shouldn't alter the response too much.

rohityadavcloud avatar Aug 31 '21 05:08 rohityadavcloud

The #95 make reading better than before but I think it would be cleaner if we could get a more human interpreted version.

is such code could help ?

func convert(i int64) string {
	v := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
	l := 0
	for ; i > 1024; i = i / 1024 {
		l++
	}
	return fmt.Sprintf("%d %s", i, v[l])
}

This could work for any field that are size or memory, but cannot be use for all integer type because that would not make sense for cpu count as example.

pdion891 avatar Sep 01 '21 16:09 pdion891

That looks good - but then the issue is on which int64 inputs (i.e. response keys) should we apply this logic? (probably anything with size in the substring? however it may fail if it's not storage related key)

rohityadavcloud avatar Sep 01 '21 16:09 rohityadavcloud

int64 in that snippet can be changed.

pdion891 avatar Sep 01 '21 16:09 pdion891

It does look better with the approach you've mentioned @pdion891. However, this may not work for fields like cpunumber, cpuspeed, bits, count, etc - but it's worth exploring!

Pearl1594 avatar Sep 02 '21 12:09 Pearl1594

@Pearl1594 for sur this kind of output is only valid for Size type of attribute.

Would there be a way to know if an attribute name contain size and if it does the value would be process to have GB output style ?

pdion891 avatar Sep 02 '21 12:09 pdion891

@Pearl1594 are you still looking to work on this issue?

borisstoyanov avatar Feb 09 '23 07:02 borisstoyanov

I don't think the fix should be in cmk, cmk is a simple tool that displays whatever the api response has. If anywhere the fix should be in the API response. There was a PR back in the days for 'human readable' output that went through most parts in cloudstack and made all these size/volumes into more sensible units. I think we should close this

borisstoyanov avatar Mar 07 '23 08:03 borisstoyanov

I agree, if cloudstack api output can be in human readable format, this feature request in cmk is not valid anymore.

Closing it

Thank you!

pdion891 avatar Mar 07 '23 13:03 pdion891