RESTify the remaining components

This commit is contained in:
Joshua Boniface 2019-07-26 11:00:11 -04:00
parent d43ced176f
commit 4cf3ade10a
2 changed files with 278 additions and 231 deletions

View File

@ -137,7 +137,7 @@ def api_auth_logout():
#
@api.route('/api/v1/node', methods=['GET'])
@authenticator
def api_node():
def api_node_root():
# Get name limit
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
@ -148,7 +148,7 @@ def api_node():
@api.route('/api/v1/node/<node>', methods=['GET'])
@authenticator
def api_node_root(node):
def api_node_element(node):
# Same as specifying /node?limit=NODE
return pvcapi.node_list(node)
@ -190,7 +190,7 @@ def api_node_domain_state(node):
#
@api.route('/api/v1/vm', methods=['GET', 'POST'])
@authenticator
def api_vm():
def api_vm_root():
if flask.request.method == 'GET':
# Get node limit
if 'node' in flask.request.values:
@ -235,7 +235,7 @@ def api_vm():
@api.route('/api/v1/vm/<vm>', methods=['GET', 'POST', 'PUT', 'DELETE'])
@authenticator
def api_vm_root(vm):
def api_vm_element(vm):
if flask.request.method == 'GET':
# Same as specifying /vm?limit=VM
return pvcapi.vm_list(None, None, vm, is_fuzzy=False)
@ -331,7 +331,7 @@ def api_vm_node(vm):
#
@api.route('/api/v1/network', methods=['GET', 'POST'])
@authenticator
def api_net():
def api_net_root():
if flask.request.method == 'GET':
# Get name limit
if 'limit' in flask.request.values:
@ -416,7 +416,7 @@ def api_net():
@api.route('/api/v1/network/<network>', methods=['GET', 'PUT', 'DELETE'])
@authenticator
def api_net_root(network):
def api_net_element(network):
# Same as specifying /network?limit=NETWORK
if flask.request.method == 'GET':
return pvcapi.net_list(network)
@ -486,7 +486,7 @@ def api_net_root(network):
@api.route('/api/v1/network/<network>/lease', methods=['GET', 'POST'])
@authenticator
def api_net_lease(network):
def api_net_lease_root(network):
if flask.request.method == 'GET':
# Get name limit
if 'limit' in flask.request.values:
@ -524,7 +524,7 @@ def api_net_lease(network):
@api.route('/api/v1/network/<network>/lease/<lease>', methods=['GET', 'DELETE'])
@authenticator
def api_net_lease_root(network, lease):
def api_net_lease_element(network, lease):
if flask.request.method == 'GET':
# Same as specifying /network?limit=NETWORK
return pvcapi.net_dhcp_list(network, lease, False)
@ -534,7 +534,7 @@ def api_net_lease_root(network, lease):
@api.route('/api/v1/network/<network>/acl', methods=['GET', 'POST'])
@authenticator
def api_net_acl(network):
def api_net_acl_root(network):
if flask.request.method == 'GET':
# Get name limit
if 'limit' in flask.request.values:
@ -583,7 +583,7 @@ def api_net_acl(network):
@api.route('/api/v1/network/<network>/acl/<acl>', methods=['GET', 'DELETE'])
@authenticator
def api_net_acl_info(network, acl):
def api_net_acl_element(network, acl):
if flask.request.method == 'GET':
# Same as specifying /network?limit=NETWORK
return pvcapi.net_acl_list(network, acl, None)
@ -622,9 +622,35 @@ def api_ceph_status():
def api_ceph_radosdf():
return pvcapi.ceph_radosdf()
@api.route('/api/v1/storage/ceph/osd', methods=['GET'])
@api.route('/api/v1/storage/ceph/cluster-option', methods=['GET', 'POST'])
@authenticator
def api_ceph_osd():
def api_ceph_cluster_option():
if flask.request.method == 'GET':
pass
if flask.request.method == 'POST':
# Get action
if 'action' in flask.request.values:
action = flask.request.values['action']
if not 'set' in action and not 'unset' in action:
return flask.jsonify({"message":"ERROR: Action must be one of: set, unset"}), 400
else:
return flask.jsonify({"message":"ERROR: An action must be specified."}), 400
# Get option
if 'option' in flask.request.values:
option = flask.request.values['option']
else:
return flask.jsonify({"message":"ERROR: An option must be specified."}), 400
if action == 'set':
return pvcapi.ceph_osd_set(option)
if action == 'unset':
return pvcapi.ceph_osd_unset(option)
@api.route('/api/v1/storage/ceph/osd', methods=['GET', 'POST'])
@authenticator
def api_ceph_osd_root():
if flask.request.method == 'GET':
# Get name limit
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
@ -633,73 +659,64 @@ def api_ceph_osd():
return pvcapi.ceph_osd_list(limit)
@api.route('/api/v1/storage/ceph/osd/set', methods=['POST'])
@authenticator
def api_ceph_osd_set():
# Get OSD option
if 'option' in flask.request.options:
option = flask.request.options['option']
if flask.request.method == 'POST':
# Get OSD node
if 'node' in flask.request.values:
node = flask.request.values['node']
else:
return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 400
return flask.jsonify({"message":"ERROR: A node must be specified."}), 400
return pvcapi.ceph_osd_set(option)
@api.route('/api/v1/storage/ceph/osd/unset', methods=['POST'])
@authenticator
def api_ceph_osd_unset():
# Get OSD option
if 'option' in flask.request.options:
option = flask.request.options['option']
else:
return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 400
return pvcapi.ceph_osd_unset(option)
@api.route('/api/v1/storage/ceph/osd/<osd>', methods=['GET'])
@authenticator
def api_ceph_osd_info(osd):
# Same as specifying /osd?limit=OSD
return pvcapi.ceph_osd_list(osd)
@api.route('/api/v1/storage/ceph/osd/<node>/add', methods=['POST'])
@authenticator
def api_ceph_osd_add(node):
# Get OSD device
if 'device' in flask.request.devices:
device = flask.request.devices['device']
if 'device' in flask.request.values:
device = flask.request.values['device']
else:
return flask.jsonify({"message":"ERROR: A block device must be specified."}), 400
# Get OSD weight
if 'weight' in flask.request.weights:
weight = flask.request.weights['weight']
if 'weight' in flask.request.values:
weight = flask.request.values['weight']
else:
return flask.jsonify({"message":"ERROR: An OSD weight must be specified."}), 400
return pvcapi.ceph_osd_add(node, device, weight)
@api.route('/api/v1/storage/ceph/osd/<osd>/remove', methods=['POST'])
@api.route('/api/v1/storage/ceph/osd/<osd>', methods=['GET', 'DELETE'])
@authenticator
def api_ceph_osd_remove(osd):
def api_ceph_osd_element(osd):
if flask.request.method == 'GET':
# Same as specifying /osd?limit=OSD
return pvcapi.ceph_osd_list(osd)
if flask.request.method == 'DELETE':
# Verify yes-i-really-mean-it flag
if not 'flag_yes_i_really_mean_it' in flask.request.values:
return flask.jsonify({"message":"ERROR: This command can have unintended consequences and should not be automated; if you're sure you know what you're doing, resend with the argument 'flag_yes_i_really_mean_it'."}), 599
if not 'yes_i_really_mean_it' in flask.request.values:
return flask.jsonify({"message":"ERROR: This command can have unintended consequences and should not be automated; if you're sure you know what you're doing, resend with the argument 'yes_i_really_mean_it'."}), 400
return pvcapi.ceph_osd_remove(osd)
@api.route('/api/v1/storage/ceph/osd/<osd>/in', methods=['POST'])
@api.route('/api/v1/storage/ceph/osd/<osd>/state', methods=['GET', 'POST'])
@authenticator
def api_ceph_osd_in(osd):
return pvcapi.ceph_osd_in(osd)
def api_ceph_osd_state(osd):
if flask.request.method == 'GET':
pass
@api.route('/api/v1/storage/ceph/osd/<osd>/out', methods=['POST'])
@authenticator
def api_ceph_osd_out(osd):
if flask.request.method == 'POST':
if 'state' in flask.request.values:
state = flask.request.values['state']
if not 'in' in state and not 'out' in state:
return flask.jsonify({"message":"ERROR: State must be one of: in, out."}), 400
else:
return flask.jsonify({"message":"ERROR: A state must be specified."}), 400
if state == 'in':
return pvcapi.ceph_osd_in(osd)
if state == 'out':
return pvcapi.ceph_osd_out(osd)
@api.route('/api/v1/storage/ceph/pool', methods=['GET'])
@api.route('/api/v1/storage/ceph/pool', methods=['GET', 'POST'])
@authenticator
def api_ceph_pool():
def api_ceph_pool_root():
if flask.request.method == 'GET':
# Get name limit
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
@ -708,15 +725,13 @@ def api_ceph_pool():
return pvcapi.ceph_pool_list(limit)
@api.route('/api/v1/storage/ceph/pool/<pool>', methods=['GET'])
@authenticator
def api_ceph_pool_info(pool):
# Same as specifying /pool?limit=POOL
return pvcapi.ceph_pool_list(pool)
if flask.request.method == 'POST':
# Get pool name
if 'pool' in flask.request.values:
pool = flask.request.values['pool']
else:
return flask.jsonify({"message":"ERROR: A pool name must be specified."}), 400
@api.route('/api/v1/storage/ceph/pool/<pool>/add', methods=['POST'])
@authenticator
def api_ceph_pool_add(pool):
# Get placement groups
if 'pgs' in flask.request.values:
pgs = flask.request.values['pgs']
@ -726,18 +741,24 @@ def api_ceph_pool_add(pool):
return pvcapi.ceph_pool_add(pool, pgs)
@api.route('/api/v1/storage/ceph/pool/<pool>/remove', methods=['POST'])
@api.route('/api/v1/storage/ceph/pool/<pool>', methods=['GET', 'DELETE'])
@authenticator
def api_ceph_pool_remove(pool):
def api_ceph_pool_element(pool):
if flask.request.method == 'GET':
# Same as specifying /pool?limit=POOL
return pvcapi.ceph_pool_list(pool)
if flask.request.method == 'DELETE':
# Verify yes-i-really-mean-it flag
if not 'flag_yes_i_really_mean_it' in flask.request.values:
return flask.jsonify({"message":"ERROR: This command can have unintended consequences and should not be automated; if you're sure you know what you're doing, resend with the argument 'flag_yes_i_really_mean_it'."}), 599
if not 'yes_i_really_mean_it' in flask.request.values:
return flask.jsonify({"message":"ERROR: This command can have unintended consequences and should not be automated; if you're sure you know what you're doing, resend with the argument 'yes_i_really_mean_it'."}), 400
return pvcapi.ceph_pool_remove(pool)
@api.route('/api/v1/storage/ceph/volume', methods=['GET'])
@api.route('/api/v1/storage/ceph/volume', methods=['GET', 'POST'])
@authenticator
def api_ceph_volume():
def api_ceph_volume_root():
if flask.request.method == 'GET':
# Get pool limit
if 'pool' in flask.request.values:
pool = flask.request.values['pool']
@ -752,15 +773,19 @@ def api_ceph_volume():
return pvcapi.ceph_volume_list(pool, limit)
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>', methods=['GET'])
@authenticator
def api_ceph_volume_info(pool, volume):
# Same as specifying /volume?limit=VOLUME
return pvcapi.ceph_osd_list(pool, osd)
if flask.request.method == 'POST':
# Get volume name
if 'volume' in flask.request.values:
volume = flask.request.values['volume']
else:
return flask.jsonify({"message":"ERROR: A volume name must be specified."}), 400
# Get volume pool
if 'pool' in flask.request.values:
pool = flask.request.values['pool']
else:
return flask.jsonify({"message":"ERROR: A pool name must be spcified."}), 400
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>/add', methods=['POST'])
@authenticator
def api_ceph_volume_add(pool, volume):
# Get volume size
if 'size' in flask.request.values:
size = flask.request.values['size']
@ -769,14 +794,20 @@ def api_ceph_volume_add(pool, volume):
return pvcapi.ceph_volume_add(pool, volume, size)
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>/remove', methods=['POST'])
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>', methods=['GET', 'DELETE'])
@authenticator
def api_ceph_volume_remove(pool, volume):
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 == 'DELETE':
return pvcapi.ceph_volume_remove(pool, volume)
@api.route('/api/v1/storage/ceph/volume/snapshot', methods=['GET'])
@api.route('/api/v1/storage/ceph/volume/snapshot', methods=['GET', 'POST'])
@authenticator
def api_ceph_volume_snapshot():
def api_ceph_volume_snapshot_root():
if flask.request.method == 'GET':
# Get pool limit
if 'pool' in flask.request.values:
pool = flask.request.values['pool']
@ -797,20 +828,36 @@ def api_ceph_volume_snapshot():
return pvcapi.ceph_volume_snapshot_list(pool, volume, limit)
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>', methods=['GET'])
@authenticator
def api_ceph_volume_snapshot_info(pool, volume, snapshot):
# Same as specifying /snapshot?limit=VOLUME
return pvcapi.ceph_snapshot_list(pool, volume, snapshot)
if flask.request.method == 'POST':
# Get snapshot name
if 'snapshot' in flask.request.values:
snapshot = flask.request.values['snapshot']
else:
return flask.jsonify({"message":"ERROR: A snapshot name must be specified."}), 400
# Get volume name
if 'volume' in flask.request.values:
volume = flask.request.values['volume']
else:
return flask.jsonify({"message":"ERROR: A volume name must be specified."}), 400
# Get volume pool
if 'pool' in flask.request.values:
pool = flask.request.values['pool']
else:
return flask.jsonify({"message":"ERROR: A pool name must be spcified."}), 400
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>/add', methods=['POST'])
@authenticator
def api_ceph_volume_snapshot_add(pool, volume, snapshot):
return pvcapi.ceph_volume_snapshot_add(pool, volume, snapshot)
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>/remove', methods=['POST'])
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>', methods=['GET', 'DELETE'])
@authenticator
def api_ceph_volume_snapshot_remove(pool, volume, snapshot):
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 == 'DELETE':
return pvcapi.ceph_volume_snapshot_remove(pool, volume, snapshot)
#

View File

@ -399,7 +399,7 @@ This endpoint is an alias for `/api/v1/storage/ceph`.
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: `POST`
* Methods: `GET`, `POST`
* Mandatory values: `action`, `option`
* Optional values: N/A
@ -418,7 +418,7 @@ Return a JSON document containing information about all Ceph OSDs in the storage
* Mandatory values: `node`, `device`, `weight`
* Optional values: N/A
Add a new Ceph OSD to PVC node with name `<node>`. `device` must be a valid block device on the specified `<node>`, e.g. `/dev/sdb`. `weight` must be a valid Ceph OSD weight, usually `1.0` if all OSD disks are the same size.
Add a new Ceph OSD to PVC node `<node>`. `device` must be a valid block device on the specified `<node>`, e.g. `/dev/sdb`. `weight` must be a valid Ceph OSD weight, usually `1.0` if all OSD disks are the same size.
#### `/api/v1/storage/ceph/osd/<osd>`
* Methods: `GET`, `DELETE`
@ -467,7 +467,7 @@ Return a JSON document containing information about all Ceph RBD pools in the st
* Mandatory values: `pool`, `pgs`
* Optional values: N/A
Add a new Ceph RBD pool with name `<pool>` to the storage cluster. `pgs` must be a valid number of Placement Groups for the pool, taking into account the number of OSDs and the replication of the pool (`copies=3`). `256` is a safe and sane number of PGs for 3 nodes and 2 disks per node. This value can be grown later via `ceph` commands as required.
Add a new Ceph RBD pool `<pool>` to the storage cluster. `pgs` must be a valid number of Placement Groups for the pool, taking into account the number of OSDs and the replication of the pool (`copies=3`). `256` is a safe and sane number of PGs for 3 nodes and 2 disks per node. This value can be grown later via `ceph` commands as required.
#### `/api/v1/storage/ceph/pool/<pool>`
* Methods: `GET`, `DELETE`
@ -476,13 +476,13 @@ Add a new Ceph RBD pool with name `<pool>` to the storage cluster. `pgs` must be
* Mandatory values: N/A
* Optional values: N/A
Return a JSON document containing information about Ceph RBD pool with name `<pool>`. The output is identical to `/api/v1/storage/ceph/pool?limit=<pool>` without fuzzy regex matching.
Return a JSON document containing information about Ceph RBD pool `<pool>`. The output is identical to `/api/v1/storage/ceph/pool?limit=<pool>` without fuzzy regex matching.
###### `DELETE`
* Mandatory values: `yes_i_really_mean_it`
* Optional values: N/A
Remove a Ceph RBD pool with name `<pool>` from the storage cluster.
Remove a Ceph RBD pool `<pool>` from the storage cluster.
**NOTE:** This is a command with potentially dangerous unintended consequences that should not be scripted. To acknowledge the danger, the `yes_i_really_mean_it` must be set or the endpoint will return a failure.
@ -495,13 +495,13 @@ Remove a Ceph RBD pool with name `<pool>` from the storage cluster.
* Mandatory values: N/A
* Optional values: `pool`, `limit`
Return a JSON document containing information about all Ceph RBD volumes in the storage cluster. If `pool` is specified, return a JSON document containing information about all Ceph RBD volumes in Ceph RBD pool with name `pool`. If `limit` is specified, return a JSON document containing information about all Ceph RBD volumes with names matching `limit` as fuzzy regex.
Return a JSON document containing information about all Ceph RBD volumes in the storage cluster. If `pool` is specified, return a JSON document containing information about all Ceph RBD volumes in Ceph RBD pool `pool`. If `limit` is specified, return a JSON document containing information about all Ceph RBD volumes with names matching `limit` as fuzzy regex.
###### `POST`
* Mandatory values: `pool`, `size`
* Mandatory values: `volume`, `pool`, `size`
* Optional values: N/A
Add a new Ceph RBD volume with name `<volume>` to Ceph RBD pool with name `<pool>`. `size` must be a valid size, in bytes or a single-character metric prefix of bytes, e.g. `1073741824` (1GB), `4096M`, or `20G`.
Add a new Ceph RBD volume `<volume>` to Ceph RBD pool `<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/<pool>/<volume>`
* Methods: `GET`, `DELETE`
@ -510,13 +510,13 @@ Add a new Ceph RBD volume with name `<volume>` to Ceph RBD pool with name `<pool
* Mandatory values: N/A
* Optional values: N/A
Return a JSON document containing information about Ceph RBD volume with name `<volume>` in Ceph RBD pool with name `<pool>`. The output is identical to `/api/v1/storage/ceph/volume?pool=<pool>&limit=<volume>` without fuzzy regex matching.
Return a JSON document containing information about Ceph RBD volume `<volume>` in Ceph RBD pool `<pool>`. The output is identical to `/api/v1/storage/ceph/volume?pool=<pool>&limit=<volume>` without fuzzy regex matching.
###### `DELETE`
* Mandatory values: N/A
* Optional values: N/A
Remove a Ceph RBD volume with name `<volume>` from Ceph RBD pool `<pool>`.
Remove a Ceph RBD volume `<volume>` from Ceph RBD pool `<pool>`.
#### `/api/v1/storage/ceph/volume/snapshot`
* Methods: `GET`, `POST`
@ -525,15 +525,15 @@ Remove a Ceph RBD volume with name `<volume>` from Ceph RBD pool `<pool>`.
* Mandatory values: N/A
* Optional values: `pool`, `volume`, `limit`
Return a JSON document containing information about all Ceph RBD volume snapshots in the storage cluster. If `pool` is specified, return a JSON document containing information about all Ceph RBD volume snapshots in Ceph RBD pool with name `pool`. If `volume` is specified, return a JSON document containing information about all Ceph RBD volume snapshots of Ceph RBD volume with name `volume`. If `limit` is specified, return a JSON document containing information about all Ceph RBD volume snapshots with names matching `limit` as fuzzy regex.
Return a JSON document containing information about all Ceph RBD volume snapshots in the storage cluster. If `pool` is specified, return a JSON document containing information about all Ceph RBD volume snapshots in Ceph RBD pool `pool`. If `volume` is specified, return a JSON document containing information about all Ceph RBD volume snapshots of Ceph RBD volume `volume`. If `limit` is specified, return a JSON document containing information about all Ceph RBD volume snapshots with names matching `limit` as fuzzy regex.
The various limit options can be combined freely, e.g. one can specify a `volume` without `pool`, which would match all snapshots of the named volume(s) regardless of pool, or a `pool` and `limit` without a `volume`, which would match all named snapshots on any volume in `pool`.
###### `POST`
* Mandatory values: `snapshot`, `pool`, `volume`
* Mandatory values: `snapshot`, `volume`, `pool`
* Optional values: N/A
Add a new Ceph RBD volume snapshot with name `<snapshot>` of Ceph RBD volume with name `<volume>` on Ceph RBD pool with name `<pool>`.
Add a new Ceph RBD volume snapshot `snapshot` of Ceph RBD volume `volume` on Ceph RBD pool `pool`.
#### `/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>`
* Methods: `GET`, `DELETE`
@ -542,10 +542,10 @@ Add a new Ceph RBD volume snapshot with name `<snapshot>` of Ceph RBD volume wit
* Mandatory values: N/A
* Optional values: N/A
Return a JSON document containing information about Ceph RBD volume snapshot with name `<snapshot>` of Ceph RBD volume with name `<volume>` in Ceph RBD pool with name `<pool>`. The output is identical to `/api/v1/storage/ceph/volume?pool=<pool>&volume=<volume>&limit=<snapshot>` without fuzzy regex matching.
Return a JSON document containing information about Ceph RBD volume snapshot `<snapshot>` of Ceph RBD volume `<volume>` in Ceph RBD pool `<pool>`. The output is identical to `/api/v1/storage/ceph/volume?pool=<pool>&volume=<volume>&limit=<snapshot>` without fuzzy regex matching.
###### `DELETE`
* Mandatory values: N/A
* Optional values: N/A
Remove a Ceph RBD volume snapshot with name `<snapshot>` of Ceph RBD volume with name `<volume>` on Ceph RBD pool with name `<pool>`.
Remove a Ceph RBD volume snapshot `<snapshot>` of Ceph RBD volume `<volume>` on Ceph RBD pool `<pool>`.