From 193567f965d7c7b19ba871864b22b2a53effd1f2 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 5 Jul 2019 01:19:39 -0400 Subject: [PATCH] Further work on API client Add list and info endpoints for all areas; add dummy endpoints for all remaining endpoints. --- client-api/pvcapi.py | 569 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 522 insertions(+), 47 deletions(-) diff --git a/client-api/pvcapi.py b/client-api/pvcapi.py index 4ae031e1..4c2ef43a 100755 --- a/client-api/pvcapi.py +++ b/client-api/pvcapi.py @@ -36,14 +36,15 @@ pvcapi.config["DEBUG"] = True @pvcapi.route('/api/v1', methods=['GET']) def api_root(): - print(flask.request) - print(flask.request.args) - return "", 200 + return "PVC API version 1", 209 +# +# Node endpoints +# @pvcapi.route('/api/v1/node', methods=['GET']) def api_node(): """ - Manage the state of a node in the PVC cluster + Manage the state of a node in the PVC cluster. """ return "Manage the state of a node in the PVC cluster.\n", 209 @@ -165,26 +166,100 @@ def api_node_list(): pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode +# # VM endpoints +# @pvcapi.route('/api/v1/vm', methods=['GET']) def api_vm(): """ - Manage the state of a VM in the PVC cluster + Manage the state of a VM in the PVC cluster. """ return "Manage the state of a VM in the PVC cluster.\n", 209 -#@pvcapi.route('/api/v1/vm/add', methods=['POST']) -#@pvcapi.route('/api/v1/vm/define', methods=['POST']) -#@pvcapi.route('/api/v1/vm/modify', methods=['POST']) -#@pvcapi.route('/api/v1/vm/undefine', methods=['POST']) -#@pvcapi.route('/api/v1/vm/dump', methods=['GET']) -#@pvcapi.route('/api/v1/vm/start', methods=['POST']) -#@pvcapi.route('/api/v1/vm/restart', methods=['POST']) -#@pvcapi.route('/api/v1/vm/shutdown', methods=['POST']) -#@pvcapi.route('/api/v1/vm/stop', methods=['POST']) -#@pvcapi.route('/api/v1/vm/move', methods=['POST']) -#@pvcapi.route('/api/v1/vm/migrate', methods=['POST']) -#@pvcapi.route('/api/v1/vm/unmigrate', methods=['POST']) +@pvcapi.route('/api/v1/vm/add', methods=['POST']) +def api_vm_add(): + """ + Add a VM to the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/define', methods=['POST']) +def api_vm_define(): + """ + Define a VM from Libvirt XML in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/modify', methods=['POST']) +def api_vm_modify(): + """ + Modify a VM Libvirt XML in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/undefine', methods=['POST']) +def api_vm_undefine(): + """ + Undefine a VM from the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/dump', methods=['GET']) +def api_vm_dump(): + """ + Dump a VM Libvirt XML configuration. + """ + pass + +@pvcapi.route('/api/v1/vm/start', methods=['POST']) +def api_vm_start(): + """ + Start a VM in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/restart', methods=['POST']) +def api_vm_restart(): + """ + Restart a VM in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/shutdown', methods=['POST']) +def api_vm_shutdown(): + """ + Shutdown a VM in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/stop', methods=['POST']) +def api_vm_stop(): + """ + Forcibly stop a VM in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/vm/move', methods=['POST']) +def api_vm_move(): + """ + Move a VM to another node. + """ + pass + +@pvcapi.route('/api/v1/vm/migrate', methods=['POST']) +def api_vm_migrate(): + """ + Temporarily migrate a VM to another node. + """ + pass + +@pvcapi.route('/api/v1/vm/unmigrate', methods=['POST']) +def api_vm_unmigrate(): + """ + Unmigrate a migrated VM. + """ + pass + @pvcapi.route('/api/v1/vm/list', methods=['GET']) def api_vm_list(): """ @@ -218,36 +293,436 @@ def api_vm_list(): pvc_common.stopZKConnection(zk_conn) return flask.jsonify(retdata), retcode +# # Network endpoints -#@pvcapi.route('/api/v1/network', methods=['GET']) -#@pvcapi.route('/api/v1/network/add', methods=['POST']) -#@pvcapi.route('/api/v1/network/modify', methods=['POST']) -#@pvcapi.route('/api/v1/network/remove', methods=['POST']) -#@pvcapi.route('/api/v1/network/list', methods=['GET']) -#@pvcapi.route('/api/v1/network/dhcp', methods=['GET']) -#@pvcapi.route('/api/v1/network/dhcp/list', methods=['GET']) -#@pvcapi.route('/api/v1/network/dhcp/static', methods=['GET']) -#@pvcapi.route('/api/v1/network/dhcp/static/add', methods=['POST']) -#@pvcapi.route('/api/v1/network/dhcp/static/remove', methods=['POST']) -#@pvcapi.route('/api/v1/network/dhcp/static/list', methods=['GET']) -#@pvcapi.route('/api/v1/network/acl', methods=['GET']) -#@pvcapi.route('/api/v1/network/acl/add', methods=['POST']) -#@pvcapi.route('/api/v1/network/acl/remove', methods=['POST']) -#@pvcapi.route('/api/v1/network/acl/list', methods=['GET']) -# Ceph endpoints -#@pvcapi.route('/api/v1/ceph', methods=['GET']) -#@pvcapi.route('/api/v1/ceph/status', methods=['GET']) -#@pvcapi.route('/api/v1/ceph/osd', methods=['GET']) -#@pvcapi.route('/api/v1/ceph/osd/add', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/remove', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/in', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/out', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/set', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/unset', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/osd/list', methods=['GET']) -#@pvcapi.route('/api/v1/ceph/pool', methods=['GET']) -#@pvcapi.route('/api/v1/ceph/pool/add', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/pool/remove', methods=['POST']) -#@pvcapi.route('/api/v1/ceph/pool/list', methods=['GET']) +# +@pvcapi.route('/api/v1/network', methods=['GET']) +def api_net(): + """ + Manage the state of a client network in the PVC cluster. + """ + return "Manage the state of a VM in the PVC cluster.\n", 209 +@pvcapi.route('/api/v1/network/add', methods=['POST']) +def api_net_add(): + """ + Add a virtual client network to the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/network/modify', methods=['POST']) +def api_net_modify(): + """ + Modify a virtual client network in the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/network/remove', methods=['POST']) +def api_net_remove(): + """ + Remove a virtual client network from the PVC cluster. + """ + pass + +@pvcapi.route('/api/v1/network/list', methods=['GET']) +def api_net_list(): + """ + Return a list of client networks with limit LIMIT. + """ + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_network.get_list(zk_conn, limit) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/network/dhcp', methods=['GET']) +def api_net_dhcp(): + """ + Manage the state of a client network DHCP in the PVC cluster. + """ + return "Manage the state of a VM in the PVC cluster.\n", 209 + +@pvcapi.route('/api/v1/network/dhcp/list', methods=['GET']) +def api_net_dhcp_list(): + """ + Return a list of DHCP leases in network NETWORK with limit LIMIT. + """ + # Get network + if 'network' in flask.request.args: + network = flask.request.args['network'] + else: + return "Error: No network provided. Please specify a network.\n", 510 + + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_network.get_list_dhcp(zk_conn, network, limit, False) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/network/dhcp/static', methods=['GET']) +def api_net_dhcp_static(): + """ + Manage the state of a client network static DHCP lease in the PVC cluster. + """ + return "Manage the state of a VM in the PVC cluster.\n", 209 + +@pvcapi.route('/api/v1/network/dhcp/static/add', methods=['POST']) +def api_net_dhcp_static_add(): + """ + Add a static DHCP lease to a virtual client network. + """ + pass + +@pvcapi.route('/api/v1/network/dhcp/static/remove', methods=['POST']) +def api_net_dhcp_static_remove(): + """ + Remove a static DHCP lease from a virtual client network. + """ + pass + +@pvcapi.route('/api/v1/network/dhcp/static/list', methods=['GET']) +def api_net_dhcp_static_list(): + """ + Return a list of static DHCP leases in network NETWORK with limit LIMIT. + """ + # Get network + if 'network' in flask.request.args: + network = flask.request.args['network'] + else: + return "Error: No network provided. Please specify a network.\n", 510 + + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_network.get_list_dhcp(zk_conn, network, limit, True) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/network/acl', methods=['GET']) +def api_net_acl(): + """ + Manage the state of a client network ACL in the PVC cluster. + """ + return "Manage the state of a VM in the PVC cluster.\n", 209 + +@pvcapi.route('/api/v1/network/acl/add', methods=['POST']) +def api_net_acl_add(): + """ + Add an ACL to a virtual client network. + """ + pass + +@pvcapi.route('/api/v1/network/acl/remove', methods=['POST']) +def api_net_acl_remove(): + """ + Remove an ACL from a virtual client network. + """ + pass + +@pvcapi.route('/api/v1/network/acl/list', methods=['GET']) +def api_net_acl_list(): + """ + Return a list of network ACLs in network NETWORK with limit LIMIT. + """ + # Get network + if 'network' in flask.request.args: + network = flask.request.args['network'] + else: + return "Error: No network provided. Please specify a network.\n", 510 + + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + # Get direction limit + if 'direction' in flask.request.args: + direction = flask.request.args['direction'] + if not 'in' in direction or not 'out' in direction: + return "Error: Direction must be either 'in' or 'out'.\n", 510 + else: + direction = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_network.get_list_acl(zk_conn, network, limit, direction) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +# +# Ceph endpoints +# +@pvcapi.route('/api/v1/ceph', methods=['GET']) +def api_ceph(): + """ + Manage the state of the Ceph storage cluster. + """ + return "Manage the state of the Ceph storage cluster.\n", 209 + +@pvcapi.route('/api/v1/ceph/status', methods=['GET']) +def api_ceph_status(): + """ + Get the current Ceph cluster status. + """ + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_ceph.get_status(zk_conn) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/ceph/osd', methods=['GET']) +def api_ceph_osd(): + """ + Manage the state of OSDs in the Ceph storage cluster. + """ + return "Manage the state of OSDs in the Ceph storage cluster.\n", 209 + +@pvcapi.route('/api/v1/ceph/osd/add', methods=['POST']) +def api_ceph_osd_add(): + """ + Add a Ceph OSD to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/remove', methods=['POST']) +def api_ceph_osd_remove(): + """ + Remove a Ceph OSD from the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/in', methods=['POST']) +def api_ceph_osd_in(): + """ + Set in a Ceph OSD in the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/out', methods=['POST']) +def api_ceph_osd_out(): + """ + Set out a Ceph OSD in the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/set', methods=['POST']) +def api_ceph_osd_set(): + """ + Set options on a Ceph OSD in the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/unset', methods=['POST']) +def api_ceph_osd_unset(): + """ + Unset options on a Ceph OSD in the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/osd/list', methods=['GET']) +def api_ceph_osd_list(): + """ + Get the list of OSDs in the Ceph storage cluster. + """ + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_ceph.get_list_osd(zk_conn, limit) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/ceph/pool', methods=['GET']) +def api_ceph_pool(): + """ + Manage the state of RBD pools in the Ceph storage cluster. + """ + return "Manage the state of RBD pools in the Ceph storage cluster.\n", 209 + +@pvcapi.route('/api/v1/ceph/pool/add', methods=['POST']) +def api_ceph_pool_add(): + """ + Add a Ceph RBD pool to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/pool/remove', methods=['POST']) +def api_ceph_pool_remove(): + """ + Remove a Ceph RBD pool to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/pool/list', methods=['GET']) +def api_ceph_pool_list(): + """ + Get the list of RBD pools in the Ceph storage cluster. + """ + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_ceph.get_list_pool(zk_conn, limit) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/ceph/volume', methods=['GET']) +def api_ceph_volume(): + """ + Manage the state of RBD volumes in the Ceph storage cluster. + """ + return "Manage the state of RBD volumes in the Ceph storage cluster.\n", 209 + +@pvcapi.route('/api/v1/ceph/volume/add', methods=['POST']) +def api_ceph_volume_add(): + """ + Add a Ceph RBD volume to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/volume/remove', methods=['POST']) +def api_ceph_volume_remove(): + """ + Remove a Ceph RBD volume to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/volume/list', methods=['GET']) +def api_ceph_volume_list(): + """ + Get the list of RBD volumes in the Ceph storage cluster. + """ + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + # Get pool limit + if 'pool' in flask.request.args: + pool = flask.request.args['pool'] + else: + pool = 'all' + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_ceph.get_list_volume(zk_conn, pool, limit) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +@pvcapi.route('/api/v1/ceph/volume/snapshot', methods=['GET']) +def api_ceph_volume_snapshot(): + """ + Manage the state of RBD volume snapshots in the Ceph storage cluster. + """ + return "Manage the state of RBD volume snapshots in the Ceph storage cluster.\n", 209 + +@pvcapi.route('/api/v1/ceph/volume/snapshot/add', methods=['POST']) +def api_ceph_volume_snapshot_add(): + """ + Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/volume/snapshot/remove', methods=['POST']) +def api_ceph_volume_snapshot_remove(): + """ + Remove a Ceph RBD volume snapshot to the PVC Ceph storage cluster. + """ + pass + +@pvcapi.route('/api/v1/ceph/volume/snapshot/list', methods=['GET']) +def api_ceph_volume_snapshot_list(): + """ + Get the list of RBD volume snapshots in the Ceph storage cluster. + """ + # Get name limit + if 'limit' in flask.request.args: + limit = flask.request.args['limit'] + else: + limit = None + + # Get volume limit + if 'volume' in flask.request.args: + volume = flask.request.args['volume'] + else: + volume = 'all' + + # Get pool limit + if 'pool' in flask.request.args: + pool = flask.request.args['pool'] + else: + pool = 'all' + + zk_conn = pvc_common.startZKConnection(zk_host) + retflag, retdata = pvc_ceph.get_list_snapshot(zk_conn, pool, volume, limit) + if retflag: + retcode = 200 + else: + retcode = 510 + + pvc_common.stopZKConnection(zk_conn) + return flask.jsonify(retdata), retcode + +# +# Entrypoint +# pvcapi.run()