From 58f174b87b8550ff8a7e02d60601d2d6d37a852e Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 2 Oct 2021 01:13:50 -0400 Subject: [PATCH] Add format option to benchmark info Allows specifying of raw json or json-pretty formats in addition to the "pretty" formatted option. --- client-cli/pvc/cli_lib/ceph.py | 11 +++++++++-- client-cli/pvc/pvc.py | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client-cli/pvc/cli_lib/ceph.py b/client-cli/pvc/cli_lib/ceph.py index b8e6ce33..829a4ff4 100644 --- a/client-cli/pvc/cli_lib/ceph.py +++ b/client-cli/pvc/cli_lib/ceph.py @@ -21,6 +21,7 @@ import math +from json import dumps from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor import pvc.cli_lib.ansiprint as ansiprint @@ -1601,7 +1602,7 @@ def format_list_benchmark_legacy(config, benchmark_information): return '\n'.join(benchmark_list_output) -def format_info_benchmark(config, benchmark_information): +def format_info_benchmark(config, oformat, benchmark_information): # This matrix is a list of the possible format functions for a benchmark result # It is extensable in the future should newer formats be required. benchmark_matrix = { @@ -1609,7 +1610,13 @@ def format_info_benchmark(config, benchmark_information): } benchmark_version = benchmark_information['test_format'] - return benchmark_matrix.get(benchmark_version, lambda: 'Invalid format function')(config, benchmark_information) + + if oformat == 'json-pretty': + return dumps(benchmark_information, indent=4) + elif oformat == 'json': + return dumps(benchmark_information) + else: + return benchmark_matrix.get(benchmark_version, lambda: 'Invalid format function')(config, benchmark_information) def format_info_benchmark_legacy(config, benchmark_information): diff --git a/client-cli/pvc/pvc.py b/client-cli/pvc/pvc.py index 297eb6f4..a382187e 100755 --- a/client-cli/pvc/pvc.py +++ b/client-cli/pvc/pvc.py @@ -2541,15 +2541,20 @@ def ceph_benchmark_run(pool): @click.argument( 'job', required=True ) +@click.option( + '-f', '--format', 'oformat', default='pretty', show_default=True, + type=click.Choice(['pretty', 'json', 'json-pretty']), + help='Output format of benchmark information.' +) @cluster_req -def ceph_benchmark_info(job): +def ceph_benchmark_info(job, oformat): """ Show full details of storage benchmark JOB. """ retcode, retdata = pvc_ceph.ceph_benchmark_list(config, job) if retcode: - retdata = pvc_ceph.format_info_benchmark(config, retdata) + retdata = pvc_ceph.format_info_benchmark(config, oformat, retdata) cleanup(retcode, retdata)