Refactor API into separate files
Make it easier to separate the model (i.e. API endpoints) from the controller (i.e. the actual functions which talk to ZK). Helps to keep the main API file smaller and more regular.
This commit is contained in:
parent
6ee3c91a63
commit
061b4eb61e
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# pvcapi.py - PVC HTTP API interface
|
# api.py - PVC HTTP API interface
|
||||||
# Part of the Parallel Virtual Cluster (PVC) system
|
# Part of the Parallel Virtual Cluster (PVC) system
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018 Joshua M. Boniface <joshua@boniface.me>
|
# Copyright (C) 2018 Joshua M. Boniface <joshua@boniface.me>
|
||||||
|
@ -29,42 +29,35 @@ import client_lib.vm as pvc_vm
|
||||||
import client_lib.network as pvc_network
|
import client_lib.network as pvc_network
|
||||||
import client_lib.ceph as pvc_ceph
|
import client_lib.ceph as pvc_ceph
|
||||||
|
|
||||||
import api_lib.api as api
|
import api_lib.pvcapi as pvcapi
|
||||||
|
|
||||||
zk_host = "hv1:2181,hv2:2181,hv3:2181"
|
zk_host = "hv1:2181,hv2:2181,hv3:2181"
|
||||||
|
|
||||||
pvcapi = flask.Flask(__name__)
|
api = flask.Flask(__name__)
|
||||||
pvcapi.config["DEBUG"] = True
|
api.config["DEBUG"] = True
|
||||||
|
|
||||||
@pvcapi.route('/api/v1', methods=['GET'])
|
@api.route('/api/v1', methods=['GET'])
|
||||||
def api_root():
|
def api_root():
|
||||||
return "PVC API version 1", 209
|
return "PVC API version 1", 209
|
||||||
|
|
||||||
#
|
#
|
||||||
# Node endpoints
|
# Node endpoints
|
||||||
#
|
#
|
||||||
@pvcapi.route('/api/v1/node', methods=['GET'])
|
@api.route('/api/v1/node', methods=['GET'])
|
||||||
def api_node():
|
def api_node():
|
||||||
"""
|
"""
|
||||||
Return a list of nodes with limit LIMIT.
|
Return a list of nodes.
|
||||||
"""
|
"""
|
||||||
# Get limit
|
return pvcapi.node_list()
|
||||||
if 'limit' in flask.request.values:
|
|
||||||
limit = flask.request.values['limit']
|
|
||||||
else:
|
|
||||||
limit = None
|
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
@api.route('/api/v1/node/<name>', methods=['GET'])
|
||||||
retflag, retdata = pvc_node.get_list(zk_conn, limit)
|
def api_node_name(name):
|
||||||
if retflag:
|
"""
|
||||||
retcode = 200
|
Return information about node NAME.
|
||||||
else:
|
"""
|
||||||
retcode = 510
|
return pvcapi.node_list(name)
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/node/secondary', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/node/secondary', methods=['POST'])
|
|
||||||
def api_node_secondary():
|
def api_node_secondary():
|
||||||
"""
|
"""
|
||||||
Take NODE out of primary router mode.
|
Take NODE out of primary router mode.
|
||||||
|
@ -75,20 +68,9 @@ def api_node_secondary():
|
||||||
else:
|
else:
|
||||||
return "Error: No node provided. Please specify a node.\n", 510
|
return "Error: No node provided. Please specify a node.\n", 510
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.node_secondary(node)
|
||||||
retflag, retmsg = pvc_node.secondary_node(zk_conn, node)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/node/primary', methods=['POST'])
|
||||||
output = {
|
|
||||||
'message': retmsg,
|
|
||||||
}
|
|
||||||
return flask.jsonify(output), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/node/primary', methods=['POST'])
|
|
||||||
def api_node_primary():
|
def api_node_primary():
|
||||||
"""
|
"""
|
||||||
Set NODE to primary router mode.
|
Set NODE to primary router mode.
|
||||||
|
@ -99,20 +81,9 @@ def api_node_primary():
|
||||||
else:
|
else:
|
||||||
return "Error: No node provided. Please specify a node.\n", 510
|
return "Error: No node provided. Please specify a node.\n", 510
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.node_primary(node)
|
||||||
retflag, retmsg = pvc_node.primary_node(zk_conn, node)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/node/flush', methods=['POST'])
|
||||||
output = {
|
|
||||||
'message': retmsg,
|
|
||||||
}
|
|
||||||
return flask.jsonify(output), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/node/flush', methods=['POST'])
|
|
||||||
def api_node_flush():
|
def api_node_flush():
|
||||||
"""
|
"""
|
||||||
Flush NODE of running VMs.
|
Flush NODE of running VMs.
|
||||||
|
@ -123,21 +94,10 @@ def api_node_flush():
|
||||||
else:
|
else:
|
||||||
return "Error: No node provided. Please specify a node.\n", 510
|
return "Error: No node provided. Please specify a node.\n", 510
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.node_flush(node)
|
||||||
retflag, retmsg = pvc_node.flush_node(zk_conn, node, False)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/node/unflush', methods=['POST'])
|
||||||
output = {
|
@api.route('/api/v1/node/ready', methods=['POST'])
|
||||||
'message': retmsg,
|
|
||||||
}
|
|
||||||
return flask.jsonify(output), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/node/unflush', methods=['POST'])
|
|
||||||
@pvcapi.route('/api/v1/node/ready', methods=['POST'])
|
|
||||||
def api_node_ready():
|
def api_node_ready():
|
||||||
"""
|
"""
|
||||||
Restore NODE to active service.
|
Restore NODE to active service.
|
||||||
|
@ -148,23 +108,12 @@ def api_node_ready():
|
||||||
else:
|
else:
|
||||||
return "Error: No node provided. Please specify a node.\n", 510
|
return "Error: No node provided. Please specify a node.\n", 510
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.node_ready(node)
|
||||||
retflag, retmsg = pvc_node.ready_node(zk_conn, node)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
|
||||||
output = {
|
|
||||||
'message': retmsg,
|
|
||||||
}
|
|
||||||
return flask.jsonify(output), retcode
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# VM endpoints
|
# VM endpoints
|
||||||
#
|
#
|
||||||
@pvcapi.route('/api/v1/vm', methods=['GET'])
|
@api.route('/api/v1/vm', methods=['GET'])
|
||||||
def api_vm():
|
def api_vm():
|
||||||
"""
|
"""
|
||||||
Return a list of VMs with limit LIMIT.
|
Return a list of VMs with limit LIMIT.
|
||||||
|
@ -187,104 +136,96 @@ def api_vm():
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.vm_list(node, state, limit)
|
||||||
retflag, retdata = pvc_vm.get_list(zk_conn, node, state, limit)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/vm/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/add', methods=['POST'])
|
|
||||||
def api_vm_add():
|
def api_vm_add():
|
||||||
"""
|
"""
|
||||||
Add a VM named NAME to the PVC cluster.
|
Add a VM named NAME to the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/define', methods=['POST'])
|
@api.route('/api/v1/vm/define', methods=['POST'])
|
||||||
def api_vm_define():
|
def api_vm_define():
|
||||||
"""
|
"""
|
||||||
Define a VM from Libvirt XML in the PVC cluster.
|
Define a VM from Libvirt XML in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_define()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/modify', methods=['POST'])
|
@api.route('/api/v1/vm/modify', methods=['POST'])
|
||||||
def api_vm_modify():
|
def api_vm_modify():
|
||||||
"""
|
"""
|
||||||
Modify a VM Libvirt XML in the PVC cluster.
|
Modify a VM Libvirt XML in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_modify()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/undefine', methods=['POST'])
|
@api.route('/api/v1/vm/undefine', methods=['POST'])
|
||||||
def api_vm_undefine():
|
def api_vm_undefine():
|
||||||
"""
|
"""
|
||||||
Undefine a VM from the PVC cluster.
|
Undefine a VM from the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_undefine()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/dump', methods=['GET'])
|
@api.route('/api/v1/vm/dump', methods=['GET'])
|
||||||
def api_vm_dump():
|
def api_vm_dump():
|
||||||
"""
|
"""
|
||||||
Dump a VM Libvirt XML configuration.
|
Dump a VM Libvirt XML configuration.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_dump()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/start', methods=['POST'])
|
@api.route('/api/v1/vm/start', methods=['POST'])
|
||||||
def api_vm_start():
|
def api_vm_start():
|
||||||
"""
|
"""
|
||||||
Start a VM in the PVC cluster.
|
Start a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_start()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/restart', methods=['POST'])
|
@api.route('/api/v1/vm/restart', methods=['POST'])
|
||||||
def api_vm_restart():
|
def api_vm_restart():
|
||||||
"""
|
"""
|
||||||
Restart a VM in the PVC cluster.
|
Restart a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_restart()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/shutdown', methods=['POST'])
|
@api.route('/api/v1/vm/shutdown', methods=['POST'])
|
||||||
def api_vm_shutdown():
|
def api_vm_shutdown():
|
||||||
"""
|
"""
|
||||||
Shutdown a VM in the PVC cluster.
|
Shutdown a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_shutdown()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/stop', methods=['POST'])
|
@api.route('/api/v1/vm/stop', methods=['POST'])
|
||||||
def api_vm_stop():
|
def api_vm_stop():
|
||||||
"""
|
"""
|
||||||
Forcibly stop a VM in the PVC cluster.
|
Forcibly stop a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_stop()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/move', methods=['POST'])
|
@api.route('/api/v1/vm/move', methods=['POST'])
|
||||||
def api_vm_move():
|
def api_vm_move():
|
||||||
"""
|
"""
|
||||||
Move a VM to another node.
|
Move a VM to another node.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_move()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/migrate', methods=['POST'])
|
@api.route('/api/v1/vm/migrate', methods=['POST'])
|
||||||
def api_vm_migrate():
|
def api_vm_migrate():
|
||||||
"""
|
"""
|
||||||
Temporarily migrate a VM to another node.
|
Temporarily migrate a VM to another node.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_migrate()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/vm/unmigrate', methods=['POST'])
|
@api.route('/api/v1/vm/unmigrate', methods=['POST'])
|
||||||
def api_vm_unmigrate():
|
def api_vm_unmigrate():
|
||||||
"""
|
"""
|
||||||
Unmigrate a migrated VM.
|
Unmigrate a migrated VM.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.vm_unmigrate()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Network endpoints
|
# Network endpoints
|
||||||
#
|
#
|
||||||
@pvcapi.route('/api/v1/network', methods=['GET'])
|
@api.route('/api/v1/network', methods=['GET'])
|
||||||
def api_net():
|
def api_net():
|
||||||
"""
|
"""
|
||||||
Return a list of client networks with limit LIMIT.
|
Return a list of client networks with limit LIMIT.
|
||||||
|
@ -295,38 +236,30 @@ def api_net():
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.net_list(limit)
|
||||||
retflag, retdata = pvc_network.get_list(zk_conn, limit)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/network/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/add', methods=['POST'])
|
|
||||||
def api_net_add():
|
def api_net_add():
|
||||||
"""
|
"""
|
||||||
Add a virtual client network to the PVC cluster.
|
Add a virtual client network to the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/modify', methods=['POST'])
|
@api.route('/api/v1/network/modify', methods=['POST'])
|
||||||
def api_net_modify():
|
def api_net_modify():
|
||||||
"""
|
"""
|
||||||
Modify a virtual client network in the PVC cluster.
|
Modify a virtual client network in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_modify()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/remove', methods=['POST'])
|
@api.route('/api/v1/network/remove', methods=['POST'])
|
||||||
def api_net_remove():
|
def api_net_remove():
|
||||||
"""
|
"""
|
||||||
Remove a virtual client network from the PVC cluster.
|
Remove a virtual client network from the PVC cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_remove()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/dhcp', methods=['GET'])
|
@api.route('/api/v1/network/dhcp', methods=['GET'])
|
||||||
def api_net_dhcp():
|
def api_net_dhcp():
|
||||||
"""
|
"""
|
||||||
Return a list of DHCP leases in network NETWORK with limit LIMIT.
|
Return a list of DHCP leases in network NETWORK with limit LIMIT.
|
||||||
|
@ -343,58 +276,29 @@ def api_net_dhcp():
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
# Get static-only flag
|
||||||
retflag, retdata = pvc_network.get_list_dhcp(zk_conn, network, limit, False)
|
if 'flag_static' in flask.request.values:
|
||||||
if retflag:
|
flag_static = True
|
||||||
retcode = 200
|
|
||||||
else:
|
else:
|
||||||
retcode = 510
|
flag_static = False
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
return pvcapi.net_dhcp_list(network, limit. flag_static)
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/dhcp/static', methods=['GET'])
|
@api.route('/api/v1/network/dhcp/add', methods=['POST'])
|
||||||
def api_net_dhcp_static():
|
def api_net_dhcp_add():
|
||||||
"""
|
|
||||||
Return a list of static DHCP leases in network NETWORK with limit LIMIT.
|
|
||||||
"""
|
|
||||||
# Get network
|
|
||||||
if 'network' in flask.request.values:
|
|
||||||
network = flask.request.values['network']
|
|
||||||
else:
|
|
||||||
return "Error: No network provided. Please specify a network.\n", 510
|
|
||||||
|
|
||||||
# Get name limit
|
|
||||||
if 'limit' in flask.request.values:
|
|
||||||
limit = flask.request.values['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/dhcp/static/add', methods=['POST'])
|
|
||||||
def api_net_dhcp_static_add():
|
|
||||||
"""
|
"""
|
||||||
Add a static DHCP lease to a virtual client network.
|
Add a static DHCP lease to a virtual client network.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_dhcp_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/dhcp/static/remove', methods=['POST'])
|
@api.route('/api/v1/network/dhcp/remove', methods=['POST'])
|
||||||
def api_net_dhcp_static_remove():
|
def api_net_dhcp_remove():
|
||||||
"""
|
"""
|
||||||
Remove a static DHCP lease from a virtual client network.
|
Remove a static DHCP lease from a virtual client network.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_dhcp_remove()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/acl', methods=['GET'])
|
@api.route('/api/v1/network/acl', methods=['GET'])
|
||||||
def api_net_acl():
|
def api_net_acl():
|
||||||
"""
|
"""
|
||||||
Return a list of network ACLs in network NETWORK with limit LIMIT.
|
Return a list of network ACLs in network NETWORK with limit LIMIT.
|
||||||
|
@ -415,53 +319,37 @@ def api_net_acl():
|
||||||
if 'direction' in flask.request.values:
|
if 'direction' in flask.request.values:
|
||||||
direction = flask.request.values['direction']
|
direction = flask.request.values['direction']
|
||||||
if not 'in' in direction or not 'out' in direction:
|
if not 'in' in direction or not 'out' in direction:
|
||||||
return "Error: Direction must be either 'in' or 'out'.\n", 510
|
return "Error: Direction must be either 'in' or 'out'; for both, do not specify a direction.\n", 510
|
||||||
else:
|
else:
|
||||||
direction = None
|
direction = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.net_acl_list(network, limit, direction)
|
||||||
retflag, retdata = pvc_network.get_list_acl(zk_conn, network, limit, direction)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/network/acl/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/acl/add', methods=['POST'])
|
|
||||||
def api_net_acl_add():
|
def api_net_acl_add():
|
||||||
"""
|
"""
|
||||||
Add an ACL to a virtual client network.
|
Add an ACL to a virtual client network.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_acl_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/network/acl/remove', methods=['POST'])
|
@api.route('/api/v1/network/acl/remove', methods=['POST'])
|
||||||
def api_net_acl_remove():
|
def api_net_acl_remove():
|
||||||
"""
|
"""
|
||||||
Remove an ACL from a virtual client network.
|
Remove an ACL from a virtual client network.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.net_acl_remove()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Ceph endpoints
|
# Ceph endpoints
|
||||||
#
|
#
|
||||||
@pvcapi.route('/api/v1/ceph', methods=['GET'])
|
@api.route('/api/v1/ceph', methods=['GET'])
|
||||||
def api_ceph():
|
def api_ceph():
|
||||||
"""
|
"""
|
||||||
Get the current Ceph cluster status.
|
Get the current Ceph cluster status.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.ceph_status()
|
||||||
retflag, retdata = pvc_ceph.get_status(zk_conn)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/ceph/osd', methods=['GET'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd', methods=['GET'])
|
|
||||||
def api_ceph_osd():
|
def api_ceph_osd():
|
||||||
"""
|
"""
|
||||||
Get the list of OSDs in the Ceph storage cluster.
|
Get the list of OSDs in the Ceph storage cluster.
|
||||||
|
@ -472,59 +360,51 @@ def api_ceph_osd():
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.ceph_osd_list(limit)
|
||||||
retflag, retdata = pvc_ceph.get_list_osd(zk_conn, limit)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/ceph/osd/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/add', methods=['POST'])
|
|
||||||
def api_ceph_osd_add():
|
def api_ceph_osd_add():
|
||||||
"""
|
"""
|
||||||
Add a Ceph OSD to the PVC Ceph storage cluster.
|
Add a Ceph OSD to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/remove', methods=['POST'])
|
@api.route('/api/v1/ceph/osd/remove', methods=['POST'])
|
||||||
def api_ceph_osd_remove():
|
def api_ceph_osd_remove():
|
||||||
"""
|
"""
|
||||||
Remove a Ceph OSD from the PVC Ceph storage cluster.
|
Remove a Ceph OSD from the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_remove()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/in', methods=['POST'])
|
@api.route('/api/v1/ceph/osd/in', methods=['POST'])
|
||||||
def api_ceph_osd_in():
|
def api_ceph_osd_in():
|
||||||
"""
|
"""
|
||||||
Set in a Ceph OSD in the PVC Ceph storage cluster.
|
Set in a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_in()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/out', methods=['POST'])
|
@api.route('/api/v1/ceph/osd/out', methods=['POST'])
|
||||||
def api_ceph_osd_out():
|
def api_ceph_osd_out():
|
||||||
"""
|
"""
|
||||||
Set out a Ceph OSD in the PVC Ceph storage cluster.
|
Set out a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_out()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/set', methods=['POST'])
|
@api.route('/api/v1/ceph/osd/set', methods=['POST'])
|
||||||
def api_ceph_osd_set():
|
def api_ceph_osd_set():
|
||||||
"""
|
"""
|
||||||
Set options on a Ceph OSD in the PVC Ceph storage cluster.
|
Set options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_set()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/osd/unset', methods=['POST'])
|
@api.route('/api/v1/ceph/osd/unset', methods=['POST'])
|
||||||
def api_ceph_osd_unset():
|
def api_ceph_osd_unset():
|
||||||
"""
|
"""
|
||||||
Unset options on a Ceph OSD in the PVC Ceph storage cluster.
|
Unset options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_osd_unset()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/pool', methods=['GET'])
|
@api.route('/api/v1/ceph/pool', methods=['GET'])
|
||||||
def api_ceph_pool():
|
def api_ceph_pool():
|
||||||
"""
|
"""
|
||||||
Get the list of RBD pools in the Ceph storage cluster.
|
Get the list of RBD pools in the Ceph storage cluster.
|
||||||
|
@ -535,31 +415,23 @@ def api_ceph_pool():
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.ceph_pool_list(limit)
|
||||||
retflag, retdata = pvc_ceph.get_list_pool(zk_conn, limit)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/ceph/pool/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/pool/add', methods=['POST'])
|
|
||||||
def api_ceph_pool_add():
|
def api_ceph_pool_add():
|
||||||
"""
|
"""
|
||||||
Add a Ceph RBD pool to the PVC Ceph storage cluster.
|
Add a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_pool_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/pool/remove', methods=['POST'])
|
@api.route('/api/v1/ceph/pool/remove', methods=['POST'])
|
||||||
def api_ceph_pool_remove():
|
def api_ceph_pool_remove():
|
||||||
"""
|
"""
|
||||||
Remove a Ceph RBD pool to the PVC Ceph storage cluster.
|
Remove a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_pool_remove()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume', methods=['GET'])
|
@api.route('/api/v1/ceph/volume', methods=['GET'])
|
||||||
def api_ceph_volume():
|
def api_ceph_volume():
|
||||||
"""
|
"""
|
||||||
Get the list of RBD volumes in the Ceph storage cluster.
|
Get the list of RBD volumes in the Ceph storage cluster.
|
||||||
|
@ -574,80 +446,64 @@ def api_ceph_volume():
|
||||||
if 'pool' in flask.request.values:
|
if 'pool' in flask.request.values:
|
||||||
pool = flask.request.values['pool']
|
pool = flask.request.values['pool']
|
||||||
else:
|
else:
|
||||||
pool = 'all'
|
pool = None
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
return pvcapi.ceph_volume_list(pool, limit)
|
||||||
retflag, retdata = pvc_ceph.get_list_volume(zk_conn, pool, limit)
|
|
||||||
if retflag:
|
|
||||||
retcode = 200
|
|
||||||
else:
|
|
||||||
retcode = 510
|
|
||||||
|
|
||||||
pvc_common.stopZKConnection(zk_conn)
|
@api.route('/api/v1/ceph/volume/add', methods=['POST'])
|
||||||
return flask.jsonify(retdata), retcode
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume/add', methods=['POST'])
|
|
||||||
def api_ceph_volume_add():
|
def api_ceph_volume_add():
|
||||||
"""
|
"""
|
||||||
Add a Ceph RBD volume to the PVC Ceph storage cluster.
|
Add a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_volume_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume/remove', methods=['POST'])
|
@api.route('/api/v1/ceph/volume/remove', methods=['POST'])
|
||||||
def api_ceph_volume_remove():
|
def api_ceph_volume_remove():
|
||||||
"""
|
"""
|
||||||
Remove a Ceph RBD volume to the PVC Ceph storage cluster.
|
Remove a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_volume_remove()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume/snapshot', methods=['GET'])
|
@api.route('/api/v1/ceph/volume/snapshot', methods=['GET'])
|
||||||
def api_ceph_volume_snapshot():
|
def api_ceph_volume_snapshot():
|
||||||
"""
|
"""
|
||||||
Get the list of RBD volume snapshots in the Ceph storage cluster.
|
Get the list of RBD volume snapshots in the Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
|
# Get pool limit
|
||||||
|
if 'pool' in flask.request.values:
|
||||||
|
pool = flask.request.values['pool']
|
||||||
|
else:
|
||||||
|
pool = None
|
||||||
|
|
||||||
|
# Get volume limit
|
||||||
|
if 'volume' in flask.request.values:
|
||||||
|
volume = flask.request.values['volume']
|
||||||
|
else:
|
||||||
|
volume = None
|
||||||
|
|
||||||
# Get name limit
|
# Get name limit
|
||||||
if 'limit' in flask.request.values:
|
if 'limit' in flask.request.values:
|
||||||
limit = flask.request.values['limit']
|
limit = flask.request.values['limit']
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
# Get volume limit
|
return pvcapi.ceph_volume_snapshot_list(pool, volume, limit)
|
||||||
if 'volume' in flask.request.values:
|
|
||||||
volume = flask.request.values['volume']
|
|
||||||
else:
|
|
||||||
volume = 'all'
|
|
||||||
|
|
||||||
# Get pool limit
|
@api.route('/api/v1/ceph/volume/snapshot/add', methods=['POST'])
|
||||||
if 'pool' in flask.request.values:
|
|
||||||
pool = flask.request.values['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
|
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume/snapshot/add', methods=['POST'])
|
|
||||||
def api_ceph_volume_snapshot_add():
|
def api_ceph_volume_snapshot_add():
|
||||||
"""
|
"""
|
||||||
Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_volume_snapshot_add()
|
||||||
|
|
||||||
@pvcapi.route('/api/v1/ceph/volume/snapshot/remove', methods=['POST'])
|
@api.route('/api/v1/ceph/volume/snapshot/remove', methods=['POST'])
|
||||||
def api_ceph_volume_snapshot_remove():
|
def api_ceph_volume_snapshot_remove():
|
||||||
"""
|
"""
|
||||||
Remove a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
Remove a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
||||||
"""
|
"""
|
||||||
pass
|
return pvcapi.ceph_volume_snapshot_remove()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Entrypoint
|
# Entrypoint
|
||||||
#
|
#
|
||||||
pvcapi.run()
|
api.run()
|
|
@ -0,0 +1,439 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# pvcapi.py - PVC HTTP API functions
|
||||||
|
# Part of the Parallel Virtual Cluster (PVC) system
|
||||||
|
#
|
||||||
|
# Copyright (C) 2018 Joshua M. Boniface <joshua@boniface.me>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import json
|
||||||
|
|
||||||
|
import client_lib.common as pvc_common
|
||||||
|
import client_lib.node as pvc_node
|
||||||
|
import client_lib.vm as pvc_vm
|
||||||
|
import client_lib.network as pvc_network
|
||||||
|
import client_lib.ceph as pvc_ceph
|
||||||
|
|
||||||
|
zk_host = "hv1:2181,hv2:2181,hv3:2181"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Node functions
|
||||||
|
#
|
||||||
|
def node_list(limit=None):
|
||||||
|
"""
|
||||||
|
Return a list of nodes with limit LIMIT.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retdata = pvc_node.get_list(zk_conn, limit)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
return flask.jsonify(retdata), retcode
|
||||||
|
|
||||||
|
def node_secondary(node):
|
||||||
|
"""
|
||||||
|
Take NODE out of primary router mode.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retmsg = pvc_node.secondary_node(zk_conn, node)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
output = {
|
||||||
|
'message': retmsg,
|
||||||
|
}
|
||||||
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
|
def node_primary(node):
|
||||||
|
"""
|
||||||
|
Set NODE to primary router mode.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retmsg = pvc_node.primary_node(zk_conn, node)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
output = {
|
||||||
|
'message': retmsg,
|
||||||
|
}
|
||||||
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
|
def node_flush(node):
|
||||||
|
"""
|
||||||
|
Flush NODE of running VMs.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retmsg = pvc_node.flush_node(zk_conn, node, False)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
output = {
|
||||||
|
'message': retmsg,
|
||||||
|
}
|
||||||
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
|
def node_ready(node):
|
||||||
|
"""
|
||||||
|
Restore NODE to active service.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retmsg = pvc_node.ready_node(zk_conn, node)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
output = {
|
||||||
|
'message': retmsg,
|
||||||
|
}
|
||||||
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
|
#
|
||||||
|
# VM functions
|
||||||
|
#
|
||||||
|
def vm_list(node=None, state=None, limit=None):
|
||||||
|
"""
|
||||||
|
Return a list of VMs with limit LIMIT.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retdata = pvc_vm.get_list(zk_conn, node, state, limit)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
return flask.jsonify(retdata), retcode
|
||||||
|
|
||||||
|
def vm_add():
|
||||||
|
"""
|
||||||
|
Add a VM named NAME to the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_define():
|
||||||
|
"""
|
||||||
|
Define a VM from Libvirt XML in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_modify():
|
||||||
|
"""
|
||||||
|
Modify a VM Libvirt XML in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_undefine():
|
||||||
|
"""
|
||||||
|
Undefine a VM from the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_dump():
|
||||||
|
"""
|
||||||
|
Dump a VM Libvirt XML configuration.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_start():
|
||||||
|
"""
|
||||||
|
Start a VM in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_restart():
|
||||||
|
"""
|
||||||
|
Restart a VM in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_shutdown():
|
||||||
|
"""
|
||||||
|
Shutdown a VM in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_stop():
|
||||||
|
"""
|
||||||
|
Forcibly stop a VM in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_move():
|
||||||
|
"""
|
||||||
|
Move a VM to another node.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_migrate():
|
||||||
|
"""
|
||||||
|
Temporarily migrate a VM to another node.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def vm_unmigrate():
|
||||||
|
"""
|
||||||
|
Unmigrate a migrated VM.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
#
|
||||||
|
# Network functions
|
||||||
|
#
|
||||||
|
def net_list(limit=None):
|
||||||
|
"""
|
||||||
|
Return a list of client networks with limit LIMIT.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def net_add():
|
||||||
|
"""
|
||||||
|
Add a virtual client network to the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_modify():
|
||||||
|
"""
|
||||||
|
Modify a virtual client network in the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_remove():
|
||||||
|
"""
|
||||||
|
Remove a virtual client network from the PVC cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_dhcp_list(network, limit=None, static=False):
|
||||||
|
"""
|
||||||
|
Return a list of DHCP leases in network NETWORK with limit LIMIT.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
|
retflag, retdata = pvc_network.get_list_dhcp(zk_conn, network, limit, static)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 510
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
return flask.jsonify(retdata), retcode
|
||||||
|
|
||||||
|
def net_dhcp_add():
|
||||||
|
"""
|
||||||
|
Add a static DHCP lease to a virtual client network.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_dhcp_remove():
|
||||||
|
"""
|
||||||
|
Remove a static DHCP lease from a virtual client network.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_acl_list(network, limit=None, direction=None):
|
||||||
|
"""
|
||||||
|
Return a list of network ACLs in network NETWORK with limit LIMIT.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def net_acl_add():
|
||||||
|
"""
|
||||||
|
Add an ACL to a virtual client network.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def net_acl_remove():
|
||||||
|
"""
|
||||||
|
Remove an ACL from a virtual client network.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ceph functions
|
||||||
|
#
|
||||||
|
def 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
|
||||||
|
|
||||||
|
def ceph_osd_list(limit=None):
|
||||||
|
"""
|
||||||
|
Get the list of OSDs in the Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def ceph_osd_add():
|
||||||
|
"""
|
||||||
|
Add a Ceph OSD to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_osd_remove():
|
||||||
|
"""
|
||||||
|
Remove a Ceph OSD from the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_osd_in():
|
||||||
|
"""
|
||||||
|
Set in a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_osd_out():
|
||||||
|
"""
|
||||||
|
Set out a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_osd_set():
|
||||||
|
"""
|
||||||
|
Set options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_osd_unset():
|
||||||
|
"""
|
||||||
|
Unset options on a Ceph OSD in the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_pool_list(limit=None):
|
||||||
|
"""
|
||||||
|
Get the list of RBD pools in the Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def ceph_pool_add():
|
||||||
|
"""
|
||||||
|
Add a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_pool_remove():
|
||||||
|
"""
|
||||||
|
Remove a Ceph RBD pool to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_volume_list(pool=None, limit=None):
|
||||||
|
"""
|
||||||
|
Get the list of RBD volumes in the Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def ceph_volume_add():
|
||||||
|
"""
|
||||||
|
Add a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_volume_remove():
|
||||||
|
"""
|
||||||
|
Remove a Ceph RBD volume to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_volume_snapshot_list(pool=None, volume=None, limit=None):
|
||||||
|
"""
|
||||||
|
Get the list of RBD volume snapshots in the Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def ceph_volume_snapshot_add():
|
||||||
|
"""
|
||||||
|
Add a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
||||||
|
def ceph_volume_snapshot_remove():
|
||||||
|
"""
|
||||||
|
Remove a Ceph RBD volume snapshot to the PVC Ceph storage cluster.
|
||||||
|
"""
|
||||||
|
return '', 200
|
||||||
|
|
1398
client-api/pvc.py
1398
client-api/pvc.py
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue