From 17b463afd433c2fda4ed07a32b72e135a70ed160 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 26 Jul 2019 11:23:19 -0400 Subject: [PATCH] Replace retcodes with 400; implement OSD status --- client-api/api_lib/pvcapi.py | 103 ++++++++++++++++++++--------------- client-api/pvc-api.py | 19 ++++--- docs/manuals/api.md | 16 +++++- 3 files changed, 84 insertions(+), 54 deletions(-) diff --git a/client-api/api_lib/pvcapi.py b/client-api/api_lib/pvcapi.py index 7ddaf084..08d8e017 100755 --- a/client-api/api_lib/pvcapi.py +++ b/client-api/api_lib/pvcapi.py @@ -41,7 +41,7 @@ def node_list(limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -55,7 +55,7 @@ def node_secondary(node): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -72,7 +72,7 @@ def node_primary(node): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -89,7 +89,7 @@ def node_flush(node): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -106,7 +106,7 @@ def node_ready(node): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -139,7 +139,7 @@ def vm_list(node=None, state=None, limit=None, is_fuzzy=True): 'message': 'VM not found.' } else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -160,7 +160,7 @@ def vm_define(name, xml, node, selector): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -177,7 +177,7 @@ def vm_modify(name, restart, xml): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -194,7 +194,7 @@ def vm_undefine(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -211,7 +211,7 @@ def vm_remove(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -228,7 +228,7 @@ def vm_start(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -245,7 +245,7 @@ def vm_restart(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -262,7 +262,7 @@ def vm_shutdown(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -279,7 +279,7 @@ def vm_stop(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -296,7 +296,7 @@ def vm_move(name, node, selector): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -313,7 +313,7 @@ def vm_migrate(name, node, selector, flag_force): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -330,7 +330,7 @@ def vm_unmigrate(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -350,7 +350,7 @@ def net_list(limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -368,7 +368,7 @@ def net_add(vni, description, nettype, domain, if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -390,7 +390,7 @@ def net_modify(vni, description, domain, if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -407,7 +407,7 @@ def net_remove(network): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -424,7 +424,7 @@ def net_dhcp_list(network, limit=None, static=False): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -438,7 +438,7 @@ def net_dhcp_add(network, ipaddress, macaddress, hostname): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -455,7 +455,7 @@ def net_dhcp_remove(network, macaddress): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -472,7 +472,7 @@ def net_acl_list(network, limit=None, direction=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -489,7 +489,7 @@ def net_acl_add(network, direction, description, rule, order): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -506,7 +506,7 @@ def net_acl_remove(network, direction, description): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -526,7 +526,7 @@ def ceph_status(): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -540,7 +540,7 @@ def ceph_radosdf(): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -554,11 +554,24 @@ def ceph_osd_list(limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode +def ceph_osd_state(osd): + zk_conn = pvc_common.startZKConnection(config['coordinators']) + retflag, retdata = pvc_ceph.get_list_osd(zk_conn, osd) + if retflag: + retcode = 200 + else: + retcode = 400 + + in_state = retdata['stats']['in'] + up_state = retdata['stats']['up'] + + return flask.jsonify([{ "id": osd, "in": in_state, "up": up_state }]), retcode + def ceph_osd_add(node, device, weight): """ Add a Ceph OSD to the PVC Ceph storage cluster. @@ -568,7 +581,7 @@ def ceph_osd_add(node, device, weight): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -585,7 +598,7 @@ def ceph_osd_remove(osd_id): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -602,7 +615,7 @@ def ceph_osd_in(osd_id): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -619,7 +632,7 @@ def ceph_osd_out(osd_id): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -636,7 +649,7 @@ def ceph_osd_set(option): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -653,7 +666,7 @@ def ceph_osd_unset(option): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -670,7 +683,7 @@ def ceph_pool_list(limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -684,7 +697,7 @@ def ceph_pool_add(name, pgs): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -701,7 +714,7 @@ def ceph_pool_remove(name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -718,7 +731,7 @@ def ceph_volume_list(pool=None, limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -732,7 +745,7 @@ def ceph_volume_add(pool, name, size): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -749,7 +762,7 @@ def ceph_volume_remove(pool, name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -766,7 +779,7 @@ def ceph_volume_snapshot_list(pool=None, volume=None, limit=None): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode @@ -781,7 +794,7 @@ def ceph_volume_snapshot_add(pool, volume, name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { @@ -798,7 +811,7 @@ def ceph_volume_snapshot_remove(pool, volume, name): if retflag: retcode = 200 else: - retcode = 510 + retcode = 400 pvc_common.stopZKConnection(zk_conn) output = { diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index 3e23913f..5825a170 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -622,12 +622,9 @@ def api_ceph_status(): def api_ceph_radosdf(): return pvcapi.ceph_radosdf() -@api.route('/api/v1/storage/ceph/cluster-option', methods=['GET', 'POST']) +@api.route('/api/v1/storage/ceph/cluster-option', methods=['POST']) @authenticator def api_ceph_cluster_option(): - if flask.request.method == 'GET': - pass - if flask.request.method == 'POST': # Get action if 'action' in flask.request.values: @@ -698,7 +695,7 @@ def api_ceph_osd_element(osd): @authenticator def api_ceph_osd_state(osd): if flask.request.method == 'GET': - pass + return pvcapi.ceph_osd_state(osd) if flask.request.method == 'POST': if 'state' in flask.request.values: @@ -794,13 +791,17 @@ def api_ceph_volume_root(): return pvcapi.ceph_volume_add(pool, volume, size) -@api.route('/api/v1/storage/ceph/volume//', methods=['GET', 'DELETE']) +@api.route('/api/v1/storage/ceph/volume//', methods=['GET', 'PUT', 'DELETE']) @authenticator def api_ceph_volume_element(pool, volume): if flask.request.method == 'GET': # Same as specifying /volume?limit=VOLUME return pvcapi.ceph_volume_list(pool, volume) + if flask.request.method == 'PUT': + # TODO: #44 + flask.abort(501) + if flask.request.method == 'DELETE': return pvcapi.ceph_volume_remove(pool, volume) @@ -850,13 +851,17 @@ def api_ceph_volume_snapshot_root(): return pvcapi.ceph_volume_snapshot_add(pool, volume, snapshot) -@api.route('/api/v1/storage/ceph/volume/snapshot///', methods=['GET', 'DELETE']) +@api.route('/api/v1/storage/ceph/volume/snapshot///', methods=['GET', 'PUT', 'DELETE']) @authenticator def api_ceph_volume_snapshot_element(pool, volume, snapshot): if flask.request.method == 'GET': # Same as specifying /snapshot?limit=VOLUME return pvcapi.ceph_volume_snapshot_list(pool, volume, snapshot) + if flask.request.method == 'PUT': + # TODO: #44 + flask.abort(501) + if flask.request.method == 'DELETE': return pvcapi.ceph_volume_snapshot_remove(pool, volume, snapshot) diff --git a/docs/manuals/api.md b/docs/manuals/api.md index bfef60a2..e07507fb 100644 --- a/docs/manuals/api.md +++ b/docs/manuals/api.md @@ -386,6 +386,8 @@ Return a JSON document containing information about the current Ceph cluster sta #### `/api/v1/storage/ceph/status` * Methods: `GET` + +###### `GET` * Mandatory values: N/A * Optional values: N/A @@ -393,13 +395,17 @@ This endpoint is an alias for `/api/v1/storage/ceph`. #### `/api/v1/storage/ceph/df` * Methods: `GET` + +###### `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/storage/ceph/cluster-option` - * Methods: `GET`, `POST` + * Methods: `POST` + +###### `POST` * Mandatory values: `action`, `option` * Optional values: N/A @@ -504,7 +510,7 @@ Return a JSON document containing information about all Ceph RBD volumes in the Add a new Ceph RBD volume `` to Ceph RBD pool ``. `size` must be a valid size, in bytes or a single-character metric prefix of bytes, e.g. `1073741824` (1GB), `4096M`, or `20G`. #### `/api/v1/storage/ceph/volume//` - * Methods: `GET`, `DELETE` + * Methods: `GET`, `PUT`, `DELETE` ###### `GET` * Mandatory values: N/A @@ -512,6 +518,12 @@ Add a new Ceph RBD volume `` to Ceph RBD pool ``. `size` must be a Return a JSON document containing information about Ceph RBD volume `` in Ceph RBD pool ``. The output is identical to `/api/v1/storage/ceph/volume?pool=&limit=` without fuzzy regex matching. +###### `PUT` + * Mandatory values: N/A + * Optional values: `name`, `size` + +Change the configuration of the volume ``. If `name` is specified, rename the volume to the specified name. If `size` is specified, resize the volume to the specified size (see `POST /api/v1/storage/ceph/volume` for restrictions). + ###### `DELETE` * Mandatory values: N/A * Optional values: N/A