From 31b4dd9aed5b7932fecba265ac565548d2feecad Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 8 Jul 2019 10:56:33 -0400 Subject: [PATCH] Show radosdf output in clients --- client-api/api_lib/pvcapi.py | 14 ++++++++++++++ client-api/pvc-api.py | 11 ++++++++++- client-cli/pvc.py | 19 ++++++++++++++++++- client-common/ceph.py | 21 +++++++++++++++++---- docs/manuals/api.md | 18 ++++++++++++++++++ 5 files changed, 77 insertions(+), 6 deletions(-) diff --git a/client-api/api_lib/pvcapi.py b/client-api/api_lib/pvcapi.py index e4083d03..5a13c329 100755 --- a/client-api/api_lib/pvcapi.py +++ b/client-api/api_lib/pvcapi.py @@ -537,6 +537,20 @@ def ceph_status(): pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode +def ceph_radosdf(): + """ + Get the current Ceph cluster utilization. + """ + zk_conn = pvc_common.startZKConnection(config['coordinators']) + retflag, retdata = pvc_ceph.get_radosdf(zk_conn) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + def ceph_osd_list(limit=None): """ Get the list of OSDs in the Ceph storage cluster. diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index f8e560e9..f625cf0f 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -700,13 +700,22 @@ def api_net_acl_remove(network, acl): # Ceph endpoints # @api.route('/api/v1/ceph', methods=['GET']) +@api.route('/api/v1/ceph/status', methods=['GET']) @authenticator -def api_ceph(): +def api_ceph_status(): """ Get the current Ceph cluster status. """ return pvcapi.ceph_status() +@api.route('/api/v1/ceph/df', methods=['GET']) +@authenticator +def api_ceph_radosdf(): + """ + Get the current Ceph cluster utilization. + """ + return pvcapi.ceph_radosdf() + @api.route('/api/v1/ceph/osd', methods=['GET']) @authenticator def api_ceph_osd(): diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 4ecd0daf..56d337fa 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -1145,7 +1145,23 @@ def ceph_status(): zk_conn = pvc_common.startZKConnection(zk_host) retcode, retdata = pvc_ceph.get_status(zk_conn) if retcode: - pvc_ceph.format_status(retdata) + pvc_ceph.format_raw_output(retdata) + retdata = '' + cleanup(retcode, retdata, zk_conn) + +############################################################################### +# pvc ceph df +############################################################################### +@click.command(name='df', short_help='Show storage cluster utilization.') +def ceph_radosdf(): + """ + Show utilization of the storage cluster. + """ + + zk_conn = pvc_common.startZKConnection(zk_host) + retcode, retdata = pvc_ceph.get_radosdf(zk_conn) + if retcode: + pvc_ceph.format_raw_output(retdata) retdata = '' cleanup(retcode, retdata, zk_conn) @@ -1748,6 +1764,7 @@ ceph_volume_snapshot.add_command(ceph_volume_snapshot_remove) ceph_volume_snapshot.add_command(ceph_volume_snapshot_list) cli_ceph.add_command(ceph_status) +cli_ceph.add_command(ceph_radosdf) cli_ceph.add_command(ceph_osd) cli_ceph.add_command(ceph_pool) cli_ceph.add_command(ceph_volume) diff --git a/client-common/ceph.py b/client-common/ceph.py index 77a0e206..7efb8d67 100644 --- a/client-common/ceph.py +++ b/client-common/ceph.py @@ -109,14 +109,27 @@ def get_status(zk_conn): # Create a data structure for the information status_data = { + 'type': 'status', 'primary_node': primary_node, - 'ceph_status': ceph_status + 'ceph_data': ceph_status + } + return True, status_data + +def get_radosdf(zk_conn): + primary_node = zkhandler.readdata(zk_conn, '/primary_node') + ceph_df = zkhandler.readdata(zk_conn, '/ceph/radosdf').rstrip() + + # Create a data structure for the information + status_data = { + 'type': 'utilization', + 'primary_node': primary_node, + 'ceph_data': ceph_df } return True, status_data -def format_status(status_data): - click.echo('{bold}Ceph cluster status (primary node {end}{blue}{primary}{end}{bold}){end}\n'.format(bold=ansiprint.bold(), end=ansiprint.end(), blue=ansiprint.blue(), primary=status_data['primary_node'])) - click.echo(status_data['ceph_status']) +def format_raw_output(status_data): + click.echo('{bold}Ceph cluster {stype} (primary node {end}{blue}{primary}{end}{bold}){end}\n'.format(bold=ansiprint.bold(), end=ansiprint.end(), blue=ansiprint.blue(), stype=status_data['type'], primary=status_data['primary_node'])) + click.echo(status_data['ceph_data']) click.echo('') # diff --git a/docs/manuals/api.md b/docs/manuals/api.md index 1c330d29..e1a42e8c 100644 --- a/docs/manuals/api.md +++ b/docs/manuals/api.md @@ -422,6 +422,24 @@ These endpoints manage PVC Ceph storage cluster state and operation. Return a JSON document containing information about the current Ceph cluster status. +The JSON element `ceph_data` contains the raw output of a `ceph status` command. + +#### `/api/v1/ceph/status` + * Methods: `GET` + * Mandatory values: N/A + * Optional values: N/A + +This endpoint is an alias for `/api/v1/ceph`. + +#### `/api/v1/ceph/df` + * Methods: `GET` + * Mandatory values: N/A + * Optional values: N/A + +Return a JSON document containing information about the current Ceph cluster utilization. + +The JSON element `ceph_data` contains the raw output of a `rados df` command. + #### `/api/v1/ceph/osd` * Methods: `GET` * Mandatory values: N/A