RESTify the network endpoints; remove some cruft

This commit is contained in:
Joshua Boniface 2019-07-26 09:41:17 -04:00
parent 375bbf4b82
commit d43ced176f
3 changed files with 274 additions and 393 deletions

View File

@ -376,14 +376,15 @@ def net_add(vni, description, nettype, domain,
} }
return flask.jsonify(output), retcode return flask.jsonify(output), retcode
def net_modify(vni, description, nettype, domain, def net_modify(vni, description, domain,
ip4_network, ip4_gateway, ip6_network, ip6_gateway, ip4_network, ip4_gateway,
ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end): dhcp4_flag, dhcp4_start, dhcp4_end):
""" """
Modify a virtual client network in the PVC cluster. Modify a virtual client network in the PVC cluster.
""" """
zk_conn = pvc_common.startZKConnection(config['coordinators']) zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retmsg = pvc_network.add_network(zk_conn, vni, description, nettype, domain, retflag, retmsg = pvc_network.modify_network(zk_conn, vni, description, domain,
ip4_network, ip4_gateway, ip6_network, ip6_gateway, ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end) dhcp4_flag, dhcp4_start, dhcp4_end)
if retflag: if retflag:
@ -397,12 +398,12 @@ def net_modify(vni, description, nettype, domain,
} }
return flask.jsonify(output), retcode return flask.jsonify(output), retcode
def net_remove(description): def net_remove(network):
""" """
Remove a virtual client network from the PVC cluster. Remove a virtual client network from the PVC cluster.
""" """
zk_conn = pvc_common.startZKConnection(config['coordinators']) zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retmsg = pvc_network.remove_network(zk_conn, description) retflag, retmsg = pvc_network.remove_network(zk_conn, network)
if retflag: if retflag:
retcode = 200 retcode = 200
else: else:

View File

@ -138,9 +138,6 @@ def api_auth_logout():
@api.route('/api/v1/node', methods=['GET']) @api.route('/api/v1/node', methods=['GET'])
@authenticator @authenticator
def api_node(): def api_node():
"""
Return a list of nodes with limit LIMIT.
"""
# 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']
@ -152,9 +149,6 @@ def api_node():
@api.route('/api/v1/node/<node>', methods=['GET']) @api.route('/api/v1/node/<node>', methods=['GET'])
@authenticator @authenticator
def api_node_root(node): def api_node_root(node):
"""
Return information about node NODE.
"""
# Same as specifying /node?limit=NODE # Same as specifying /node?limit=NODE
return pvcapi.node_list(node) return pvcapi.node_list(node)
@ -162,10 +156,6 @@ def api_node_root(node):
@api.route('/api/v1/node/<node>/coordinator-state', methods=['GET', 'POST']) @api.route('/api/v1/node/<node>/coordinator-state', methods=['GET', 'POST'])
@authenticator @authenticator
def api_node_coordinator_state(node): def api_node_coordinator_state(node):
"""
Manage NODE coordinator state.
"""
if flask.request.method == 'GET': if flask.request.method == 'GET':
return "Test", 200 return "Test", 200
@ -182,10 +172,6 @@ def api_node_coordinator_state(node):
@api.route('/api/v1/node/<node>/domain-state', methods=['GET', 'POST']) @api.route('/api/v1/node/<node>/domain-state', methods=['GET', 'POST'])
@authenticator @authenticator
def api_node_domain_state(node): def api_node_domain_state(node):
"""
Manage NODE domain state.
"""
if flask.request.method == 'GET': if flask.request.method == 'GET':
return "Test", 200 return "Test", 200
@ -343,310 +329,275 @@ def api_vm_node(vm):
# #
# Network endpoints # Network endpoints
# #
@api.route('/api/v1/network', methods=['GET']) @api.route('/api/v1/network', methods=['GET', 'POST'])
@authenticator @authenticator
def api_net(): def api_net():
""" if flask.request.method == 'GET':
Return a list of virtual client networks with limit LIMIT. # Get name limit
""" if 'limit' in flask.request.values:
# Get name limit limit = flask.request.values['limit']
if 'limit' in flask.request.values: else:
limit = flask.request.values['limit'] limit = None
else:
limit = None return pvcapi.net_list(limit)
return pvcapi.net_list(limit) if flask.request.method == 'POST':
# Get network VNI
if 'vni' in flask.request.values:
vni = flask.request.values['vni']
else:
return flask.jsonify({"message":"ERROR: A VNI must be specified for the virtual network."}), 520
# Get network description
if 'description' in flask.request.values:
description = flask.request.values['vni']
else:
return flask.jsonify({"message":"ERROR: A VNI must be specified for the virtual network."}), 520
# Get network type
if 'nettype' in flask.request.values:
nettype = flask.request.values['nettype']
if not 'managed' in nettype and not 'bridged' in nettype:
return flask.jsonify({"message":"ERROR: A valid nettype must be specified: 'managed' or 'bridged'."}), 520
else:
return flask.jsonify({"message":"ERROR: A nettype must be specified for the virtual network."}), 520
# Get network domain
if 'domain' in flask.request.values:
domain = flask.request.values['domain']
else:
domain = None
# Get ipv4 network
if 'ip4_network' in flask.request.values:
ip4_network = flask.request.values['ip4_network']
else:
ip4_network = None
# Get ipv4 gateway
if 'ip4_gateway' in flask.request.values:
ip4_gateway = flask.request.values['ip4_gateway']
else:
ip4_gateway = None
# Get ipv6 network
if 'ip6_network' in flask.request.values:
ip6_network = flask.request.values['ip6_network']
else:
ip6_network = None
# Get ipv6 gateway
if 'ip6_gateway' in flask.request.values:
ip6_gateway = flask.request.values['ip6_gateway']
else:
ip6_gateway = None
# Get ipv4 DHCP flag
if 'dhcp4' in flask.request.values and flask.request.values['dhcp4']:
dhcp4_flag = True
else:
dhcp4_flag = False
# Get ipv4 DHCP start
if 'dhcp4_start' in flask.request.values:
dhcp4_start = flask.request.values['dhcp4_start']
else:
dhcp4_start = None
# Get ipv4 DHCP end
if 'dhcp4_end' in flask.request.values:
dhcp4_end = flask.request.values['dhcp4_end']
else:
dhcp4_end = None
return pvcapi.net_add(vni, description, nettype, domain,
ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end)
@api.route('/api/v1/network/<network>', methods=['GET']) @api.route('/api/v1/network/<network>', methods=['GET', 'PUT', 'DELETE'])
@authenticator @authenticator
def api_net_info(network): def api_net_root(network):
"""
Get information about a virtual client network with description NETWORK.
"""
# Same as specifying /network?limit=NETWORK # Same as specifying /network?limit=NETWORK
return pvcapi.net_list(network) if flask.request.method == 'GET':
return pvcapi.net_list(network)
@api.route('/api/v1/network/<network>/add', methods=['POST']) if flask.request.method == 'PUT':
# Get network description
if 'description' in flask.request.values:
description = flask.request.values['description']
else:
description = None
# Get network domain
if 'domain' in flask.request.values:
domain = flask.request.values['domain']
else:
domain = None
# Get ipv4 network
if 'ip4_network' in flask.request.values:
ip4_network = flask.request.values['ip4_network']
else:
ip4_network = None
# Get ipv4 gateway
if 'ip4_gateway' in flask.request.values:
ip4_gateway = flask.request.values['ip4_gateway']
else:
ip4_gateway = None
# Get ipv6 network
if 'ip6_network' in flask.request.values:
ip6_network = flask.request.values['ip6_network']
else:
ip6_network = None
# Get ipv6 gateway
if 'ip6_gateway' in flask.request.values:
ip6_gateway = flask.request.values['ip6_gateway']
else:
ip6_gateway = None
# Get ipv4 DHCP flag
if 'dhcp4' in flask.request.values and flask.request.values['dhcp4']:
dhcp4_flag = True
else:
dhcp4_flag = False
# Get ipv4 DHCP start
if 'dhcp4_start' in flask.request.values:
dhcp4_start = flask.request.values['dhcp4_start']
else:
dhcp4_start = None
# Get ipv4 DHCP end
if 'dhcp4_end' in flask.request.values:
dhcp4_end = flask.request.values['dhcp4_end']
else:
dhcp4_end = None
return pvcapi.net_modify(network, description, domain,
ip4_network, ip4_gateway,
ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end)
if flask.request.method == 'DELETE':
return pvcapi.net_remove(network)
@api.route('/api/v1/network/<network>/lease', methods=['GET', 'POST'])
@authenticator @authenticator
def api_net_add(network): def api_net_lease(network):
""" if flask.request.method == 'GET':
Add a virtual client network with description NETWORK. # Get name limit
""" if 'limit' in flask.request.values:
# Get network VNI limit = flask.request.values['limit']
if 'vni' in flask.request.values: else:
vni = flask.request.values['vni'] limit = None
else:
return flask.jsonify({"message":"ERROR: A VNI must be specified for the virtual network."}), 520 # Get static-only flag
if 'static' in flask.request.values and flask.request.values['static']:
flag_static = True
else:
flag_static = False
return pvcapi.net_dhcp_list(network, limit. flag_static)
# Get network type if flask.request.method == 'POST':
if 'nettype' in flask.request.values: # Get lease macaddr
nettype = flask.request.values['nettype'] if 'macaddress' in flask.request.values:
if not 'managed' in nettype and not 'bridged' in nettype: macaddress = flask.request.values['macaddress']
return flask.jsonify({"message":"ERROR: A valid nettype must be specified: 'managed' or 'bridged'."}), 520 else:
else: return flask.jsonify({"message":"ERROR: An IP address must be specified for the lease."}), 400
return flask.jsonify({"message":"ERROR: A nettype must be specified for the virtual network."}), 520 # Get lease ipaddress
if 'ipaddress' in flask.request.values:
ipaddress = flask.request.values['ipaddress']
else:
return flask.jsonify({"message":"ERROR: An IP address must be specified for the lease."}), 400
# Get lease hostname
if 'hostname' in flask.request.values:
hostname = flask.request.values['hostname']
else:
hostname = None
return pvcapi.net_dhcp_add(network, ipaddress, lease, hostname)
# Get network domain @api.route('/api/v1/network/<network>/lease/<lease>', methods=['GET', 'DELETE'])
if 'domain' in flask.request.values:
domain = flask.request.values['domain']
else:
domain = None
# Get ipv4 network
if 'ip4_network' in flask.request.values:
ip4_network = flask.request.values['ip4_network']
else:
ip4_network = None
# Get ipv4 gateway
if 'ip4_gateway' in flask.request.values:
ip4_gateway = flask.request.values['ip4_gateway']
else:
ip4_gateway = None
# Get ipv6 network
if 'ip6_network' in flask.request.values:
ip6_network = flask.request.values['ip6_network']
else:
ip6_network = None
# Get ipv6 gateway
if 'ip6_gateway' in flask.request.values:
ip6_gateway = flask.request.values['ip6_gateway']
else:
ip6_gateway = None
# Get ipv4 DHCP flag
if 'flag_dhcp4' in flask.request.values:
dhcp4_flag = True
else:
dhcp4_flag = False
# Get ipv4 DHCP start
if 'dhcp4_start' in flask.request.values:
dhcp4_start = flask.request.values['dhcp4_start']
else:
dhcp4_start = None
# Get ipv4 DHCP end
if 'dhcp4_end' in flask.request.values:
dhcp4_end = flask.request.values['dhcp4_end']
else:
dhcp4_end = None
return pvcapi.net_add(vni, network, nettype, domain,
ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end)
@api.route('/api/v1/network/<network>/modify', methods=['POST'])
@authenticator @authenticator
def api_net_modify(network): def api_net_lease_root(network, lease):
""" if flask.request.method == 'GET':
Modify a virtual client network with description NETWORK. # Same as specifying /network?limit=NETWORK
""" return pvcapi.net_dhcp_list(network, lease, False)
# Get network VNI
if 'vni' in flask.request.values:
vni = flask.request.values['vni']
else:
vni = None
# Get network type if flask.request.method == 'DELETE':
if 'nettype' in flask.request.values: return pvcapi.net_dhcp_remove(network, lease)
nettype = flask.request.values['nettype']
else:
vni = None
# Get network domain @api.route('/api/v1/network/<network>/acl', methods=['GET', 'POST'])
if 'domain' in flask.request.values:
domain = flask.request.values['domain']
else:
domain = None
# Get ipv4 network
if 'ip4_network' in flask.request.values:
ip4_network = flask.request.values['ip4_network']
else:
ip4_network = None
# Get ipv4 gateway
if 'ip4_gateway' in flask.request.values:
ip4_gateway = flask.request.values['ip4_gateway']
else:
ip4_gateway = None
# Get ipv6 network
if 'ip6_network' in flask.request.values:
ip6_network = flask.request.values['ip6_network']
else:
ip6_network = None
# Get ipv6 gateway
if 'ip6_gateway' in flask.request.values:
ip6_gateway = flask.request.values['ip6_gateway']
else:
ip6_gateway = None
# Get ipv4 DHCP flag
if 'flag_dhcp4' in flask.request.values:
dhcp4_flag = True
else:
dhcp4_flag = False
# Get ipv4 DHCP start
if 'dhcp4_start' in flask.request.values:
dhcp4_start = flask.request.values['dhcp4_start']
else:
dhcp4_start = None
# Get ipv4 DHCP end
if 'dhcp4_end' in flask.request.values:
dhcp4_end = flask.request.values['dhcp4_end']
else:
dhcp4_end = None
return pvcapi.net_modify(vni, network, nettype, domain,
ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end)
@api.route('/api/v1/network/<network>/remove', methods=['POST'])
@authenticator
def api_net_remove(network):
"""
Remove a virtual client network with description NETWORK.
"""
return pvcapi.net_remove(network)
@api.route('/api/v1/network/<network>/dhcp', methods=['GET'])
@authenticator
def api_net_dhcp(network):
"""
Return a list of DHCP leases in virtual client network with description NETWORK with limit LIMIT.
"""
# Get name limit
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
else:
limit = None
# Get static-only flag
if 'flag_static' in flask.request.values:
flag_static = True
else:
flag_static = False
return pvcapi.net_dhcp_list(network, limit. flag_static)
@api.route('/api/v1/network/<network>/dhcp/<lease>', methods=['GET'])
@authenticator
def api_net_dhcp_info(network, lease):
"""
Get information about a DHCP lease for MAC address LEASE in virtual client network with description NETWORK.
"""
# Same as specifying /network?limit=NETWORK
return pvcapi.net_dhcp_list(network, lease, False)
@api.route('/api/v1/network/<network>/dhcp/<lease>/add', methods=['POST'])
@authenticator
def api_net_dhcp_add(network, lease):
"""
Add a static DHCP lease for MAC address LEASE to virtual client network with description NETWORK.
"""
# Get lease ipaddress
if 'ipaddress' in flask.request.values:
ipaddress = flask.request.values['ipaddress']
else:
return flask.jsonify({"message":"ERROR: An IP address must be specified for the lease."}), 520
# Get lease hostname
if 'hostname' in flask.request.values:
hostname = flask.request.values['hostname']
else:
hostname = None
return pvcapi.net_dhcp_add(network, ipaddress, lease, hostname)
@api.route('/api/v1/network/<network>/dhcp/<lease>/remove', methods=['POST'])
@authenticator
def api_net_dhcp_remove(network, lease):
"""
Remove a static DHCP lease for MAC address LEASE from virtual client network with description NETWORK.
"""
return pvcapi.net_dhcp_remove(network, lease)
@api.route('/api/v1/network/<network>/acl', methods=['GET'])
@authenticator @authenticator
def api_net_acl(network): def api_net_acl(network):
""" if flask.request.method == 'GET':
Return a list of network ACLs in network NETWORK with limit LIMIT. # Get name limit
""" if 'limit' in flask.request.values:
# Get name limit limit = flask.request.values['limit']
if 'limit' in flask.request.values: else:
limit = flask.request.values['limit'] limit = None
else:
limit = None # Get direction limit
if 'direction' in flask.request.values:
direction = flask.request.values['direction']
if not 'in' in direction and not 'out' in direction:
return flash.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'; for both, do not specify a direction."}), 400
else:
direction = None
return pvcapi.net_acl_list(network, limit, direction)
# Get direction limit if flask.request.method == 'POST':
if 'direction' in flask.request.values: # Get ACL description
direction = flask.request.values['direction'] if 'description' in flask.request.values:
if not 'in' in direction and not 'out' in direction: description = flask.request.values['description']
return flash.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'; for both, do not specify a direction."}), 510 else:
else: return flask.jsonify({"message":"ERROR: A description must be provided."}), 400
direction = None
# Get rule direction
if 'direction' in flask.request.values:
direction = flask.request.values['limit']
if not 'in' in direction and not 'out' in direction:
return flask.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'."}), 400
else:
return flask.jsonify({"message":"ERROR: A direction must be specified for the ACL."}), 400
# Get rule data
if 'rule' in flask.request.values:
rule = flask.request.values['rule']
else:
return flask.jsonify({"message":"ERROR: A valid NFT rule line must be specified for the ACL."}), 400
# Get order value
if 'order' in flask.request.values:
order = flask.request.values['order']
else:
order = None
return pvcapi.net_acl_add(network, direction, acl, rule, order)
return pvcapi.net_acl_list(network, limit, direction) @api.route('/api/v1/network/<network>/acl/<acl>', methods=['GET', 'DELETE'])
@api.route('/api/v1/network/<network>/acl/<acl>', methods=['GET'])
@authenticator @authenticator
def api_net_acl_info(network, acl): def api_net_acl_info(network, acl):
""" if flask.request.method == 'GET':
Get information about a network access control entry with description ACL in virtual client network with description NETWORK. # Same as specifying /network?limit=NETWORK
""" return pvcapi.net_acl_list(network, acl, None)
# Same as specifying /network?limit=NETWORK
return pvcapi.net_acl_list(network, acl, None)
@api.route('/api/v1/network/<network>/acl/<acl>/add', methods=['POST']) if flask.request.method == 'DELETE':
@authenticator # Get rule direction
def api_net_acl_add(network, acl): if 'direction' in flask.request.values:
""" direction = flask.request.values['limit']
Add an access control list with description ACL to virtual client network with description NETWORK. if not 'in' in direction and not 'out' in direction:
""" return flask.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'."}), 400
# Get rule direction else:
if 'direction' in flask.request.values: return flask.jsonify({"message":"ERROR: A direction must be specified for the ACL."}), 400
direction = flask.request.values['limit']
if not 'in' in direction and not 'out' in direction: return pvcapi.net_acl_remove(network, direction, acl)
return flask.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'."}), 510
else:
return flask.jsonify({"message":"ERROR: A direction must be specified for the ACL."}), 510
# Get rule data
if 'rule' in flask.request.values:
rule = flask.request.values['rule']
else:
return flask.jsonify({"message":"ERROR: A valid NFT rule line must be specified for the ACL."}), 510
# Get order value
if 'order' in flask.request.values:
order = flask.request.values['order']
else:
order = None
return pvcapi.net_acl_add(network, direction, acl, rule, order)
@api.route('/api/v1/network/<network>/acl/<acl>/remove', methods=['POST'])
@authenticator
def api_net_acl_remove(network, acl):
"""
Remove an access control list with description ACL from virtual client network with description NETWORK.
"""
# Get rule direction
if 'direction' in flask.request.values:
direction = flask.request.values['limit']
if not 'in' in direction and not 'out' in direction:
return flask.jsonify({"message":"ERROR: Direction must be either 'in' or 'out'."}), 510
else:
return flask.jsonify({"message":"ERROR: A direction must be specified for the ACL."}), 510
return pvcapi.net_acl_remove(network, direction, acl)
# #
# Storage (Ceph) endpoints # Storage (Ceph) endpoints
@ -658,34 +609,22 @@ def api_net_acl_remove(network, acl):
# #
@api.route('/api/v1/storage', methods=['GET']) @api.route('/api/v1/storage', methods=['GET'])
def api_storage(): def api_storage():
"""
Manage the storage of the PVC cluster.
"""
return flask.jsonify({"message":"Manage the storage of the PVC cluster."}), 200 return flask.jsonify({"message":"Manage the storage of the PVC cluster."}), 200
@api.route('/api/v1/storage/ceph', methods=['GET']) @api.route('/api/v1/storage/ceph', methods=['GET'])
@api.route('/api/v1/storage/ceph/status', methods=['GET']) @api.route('/api/v1/storage/ceph/status', methods=['GET'])
@authenticator @authenticator
def api_ceph_status(): def api_ceph_status():
"""
Get the current Ceph cluster status.
"""
return pvcapi.ceph_status() return pvcapi.ceph_status()
@api.route('/api/v1/storage/ceph/df', methods=['GET']) @api.route('/api/v1/storage/ceph/df', methods=['GET'])
@authenticator @authenticator
def api_ceph_radosdf(): def api_ceph_radosdf():
"""
Get the current Ceph cluster utilization.
"""
return pvcapi.ceph_radosdf() return pvcapi.ceph_radosdf()
@api.route('/api/v1/storage/ceph/osd', methods=['GET']) @api.route('/api/v1/storage/ceph/osd', methods=['GET'])
@authenticator @authenticator
def api_ceph_osd(): def api_ceph_osd():
"""
Get the list of OSDs in the Ceph storage cluster.
"""
# 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']
@ -697,66 +636,51 @@ def api_ceph_osd():
@api.route('/api/v1/storage/ceph/osd/set', methods=['POST']) @api.route('/api/v1/storage/ceph/osd/set', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_set(): def api_ceph_osd_set():
"""
Set OSD option OPTION on the PVC Ceph storage cluster, e.g. 'noout' or 'noscrub'.
"""
# Get OSD option # Get OSD option
if 'option' in flask.request.options: if 'option' in flask.request.options:
option = flask.request.options['option'] option = flask.request.options['option']
else: else:
return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 510 return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 400
return pvcapi.ceph_osd_set(option) return pvcapi.ceph_osd_set(option)
@api.route('/api/v1/storage/ceph/osd/unset', methods=['POST']) @api.route('/api/v1/storage/ceph/osd/unset', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_unset(): def api_ceph_osd_unset():
"""
Unset OSD option OPTION on the PVC Ceph storage cluster, e.g. 'noout' or 'noscrub'.
"""
# Get OSD option # Get OSD option
if 'option' in flask.request.options: if 'option' in flask.request.options:
option = flask.request.options['option'] option = flask.request.options['option']
else: else:
return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 510 return flask.jsonify({"message":"ERROR: An OSD option must be specified."}), 400
return pvcapi.ceph_osd_unset(option) return pvcapi.ceph_osd_unset(option)
@api.route('/api/v1/storage/ceph/osd/<osd>', methods=['GET']) @api.route('/api/v1/storage/ceph/osd/<osd>', methods=['GET'])
@authenticator @authenticator
def api_ceph_osd_info(osd): def api_ceph_osd_info(osd):
"""
Get information about an OSD with ID OSD.
"""
# Same as specifying /osd?limit=OSD # Same as specifying /osd?limit=OSD
return pvcapi.ceph_osd_list(osd) return pvcapi.ceph_osd_list(osd)
@api.route('/api/v1/storage/ceph/osd/<node>/add', methods=['POST']) @api.route('/api/v1/storage/ceph/osd/<node>/add', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_add(node): def api_ceph_osd_add(node):
"""
Add a Ceph OSD to node NODE.
"""
# Get OSD device # Get OSD device
if 'device' in flask.request.devices: if 'device' in flask.request.devices:
device = flask.request.devices['device'] device = flask.request.devices['device']
else: else:
return flask.jsonify({"message":"ERROR: A block device must be specified."}), 510 return flask.jsonify({"message":"ERROR: A block device must be specified."}), 400
# Get OSD weight # Get OSD weight
if 'weight' in flask.request.weights: if 'weight' in flask.request.weights:
weight = flask.request.weights['weight'] weight = flask.request.weights['weight']
else: else:
return flask.jsonify({"message":"ERROR: An OSD weight must be specified."}), 510 return flask.jsonify({"message":"ERROR: An OSD weight must be specified."}), 400
return pvcapi.ceph_osd_add(node, device, weight) 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>/remove', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_remove(osd): def api_ceph_osd_remove(osd):
"""
Remove a Ceph OSD with ID OSD.
"""
# Verify yes-i-really-mean-it flag # Verify yes-i-really-mean-it flag
if not 'flag_yes_i_really_mean_it' in flask.request.values: 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 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
@ -766,25 +690,16 @@ def api_ceph_osd_remove(osd):
@api.route('/api/v1/storage/ceph/osd/<osd>/in', methods=['POST']) @api.route('/api/v1/storage/ceph/osd/<osd>/in', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_in(osd): def api_ceph_osd_in(osd):
"""
Set in a Ceph OSD with ID OSD.
"""
return pvcapi.ceph_osd_in(osd) return pvcapi.ceph_osd_in(osd)
@api.route('/api/v1/storage/ceph/osd/<osd>/out', methods=['POST']) @api.route('/api/v1/storage/ceph/osd/<osd>/out', methods=['POST'])
@authenticator @authenticator
def api_ceph_osd_out(osd): def api_ceph_osd_out(osd):
"""
Set out a Ceph OSD with ID OSD.
"""
return pvcapi.ceph_osd_out(osd) return pvcapi.ceph_osd_out(osd)
@api.route('/api/v1/storage/ceph/pool', methods=['GET']) @api.route('/api/v1/storage/ceph/pool', methods=['GET'])
@authenticator @authenticator
def api_ceph_pool(): def api_ceph_pool():
"""
Get the list of RBD pools in the Ceph storage cluster.
"""
# 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']
@ -796,18 +711,12 @@ def api_ceph_pool():
@api.route('/api/v1/storage/ceph/pool/<pool>', methods=['GET']) @api.route('/api/v1/storage/ceph/pool/<pool>', methods=['GET'])
@authenticator @authenticator
def api_ceph_pool_info(pool): def api_ceph_pool_info(pool):
"""
Get information about an RBD pool with name POOL.
"""
# Same as specifying /pool?limit=POOL # Same as specifying /pool?limit=POOL
return pvcapi.ceph_pool_list(pool) return pvcapi.ceph_pool_list(pool)
@api.route('/api/v1/storage/ceph/pool/<pool>/add', methods=['POST']) @api.route('/api/v1/storage/ceph/pool/<pool>/add', methods=['POST'])
@authenticator @authenticator
def api_ceph_pool_add(pool): def api_ceph_pool_add(pool):
"""
Add a Ceph RBD pool with name POOL.
"""
# Get placement groups # Get placement groups
if 'pgs' in flask.request.values: if 'pgs' in flask.request.values:
pgs = flask.request.values['pgs'] pgs = flask.request.values['pgs']
@ -820,9 +729,6 @@ def api_ceph_pool_add(pool):
@api.route('/api/v1/storage/ceph/pool/<pool>/remove', methods=['POST']) @api.route('/api/v1/storage/ceph/pool/<pool>/remove', methods=['POST'])
@authenticator @authenticator
def api_ceph_pool_remove(pool): def api_ceph_pool_remove(pool):
"""
Remove a Ceph RBD pool with name POOL.
"""
# Verify yes-i-really-mean-it flag # Verify yes-i-really-mean-it flag
if not 'flag_yes_i_really_mean_it' in flask.request.values: 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 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
@ -832,9 +738,6 @@ def api_ceph_pool_remove(pool):
@api.route('/api/v1/storage/ceph/volume', methods=['GET']) @api.route('/api/v1/storage/ceph/volume', methods=['GET'])
@authenticator @authenticator
def api_ceph_volume(): def api_ceph_volume():
"""
Get the list of RBD volumes in the Ceph storage cluster.
"""
# Get pool limit # Get pool limit
if 'pool' in flask.request.values: if 'pool' in flask.request.values:
pool = flask.request.values['pool'] pool = flask.request.values['pool']
@ -852,40 +755,28 @@ def api_ceph_volume():
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>', methods=['GET']) @api.route('/api/v1/storage/ceph/volume/<pool>/<volume>', methods=['GET'])
@authenticator @authenticator
def api_ceph_volume_info(pool, volume): def api_ceph_volume_info(pool, volume):
"""
Get information about an RBD volume with name VOLUME in RBD pool with name POOL.
"""
# Same as specifying /volume?limit=VOLUME # Same as specifying /volume?limit=VOLUME
return pvcapi.ceph_osd_list(pool, osd) return pvcapi.ceph_osd_list(pool, osd)
@api.route('/api/v1/storage/ceph/volume/<pool>/<volume>/add', methods=['POST']) @api.route('/api/v1/storage/ceph/volume/<pool>/<volume>/add', methods=['POST'])
@authenticator @authenticator
def api_ceph_volume_add(pool, volume): def api_ceph_volume_add(pool, volume):
"""
Add a Ceph RBD volume with name VOLUME to RBD pool with name POOL.
"""
# Get volume size # Get volume size
if 'size' in flask.request.values: if 'size' in flask.request.values:
size = flask.request.values['size'] size = flask.request.values['size']
else: else:
return flask.jsonify({"message":"ERROR: A volume size in bytes (or with an M/G/T suffix) must be specified."}), 510 return flask.jsonify({"message":"ERROR: A volume size in bytes (or with an M/G/T suffix) must be specified."}), 400
return pvcapi.ceph_volume_add(pool, volume, size) 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>/remove', methods=['POST'])
@authenticator @authenticator
def api_ceph_volume_remove(pool, volume): def api_ceph_volume_remove(pool, volume):
"""
Remove a Ceph RBD volume with name VOLUME from RBD pool with name POOL.
"""
return pvcapi.ceph_volume_remove(pool, volume) 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'])
@authenticator @authenticator
def api_ceph_volume_snapshot(): def api_ceph_volume_snapshot():
"""
Get the list of RBD volume snapshots in the Ceph storage cluster.
"""
# Get pool limit # Get pool limit
if 'pool' in flask.request.values: if 'pool' in flask.request.values:
pool = flask.request.values['pool'] pool = flask.request.values['pool']
@ -909,26 +800,17 @@ def api_ceph_volume_snapshot():
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>', methods=['GET']) @api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>', methods=['GET'])
@authenticator @authenticator
def api_ceph_volume_snapshot_info(pool, volume, snapshot): def api_ceph_volume_snapshot_info(pool, volume, snapshot):
"""
Get information about a snapshot with name SNAPSHOT of RBD volume with name VOLUME in RBD pool with name POOL.
"""
# Same as specifying /snapshot?limit=VOLUME # Same as specifying /snapshot?limit=VOLUME
return pvcapi.ceph_snapshot_list(pool, volume, snapshot) return pvcapi.ceph_snapshot_list(pool, volume, snapshot)
@api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>/add', methods=['POST']) @api.route('/api/v1/storage/ceph/volume/snapshot/<pool>/<volume>/<snapshot>/add', methods=['POST'])
@authenticator @authenticator
def api_ceph_volume_snapshot_add(pool, volume, snapshot): def api_ceph_volume_snapshot_add(pool, volume, snapshot):
"""
Add a Ceph RBD volume snapshot with name SNAPSHOT of RBD volume with name VOLUME in RBD pool with name POOL.
"""
return pvcapi.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>/remove', methods=['POST'])
@authenticator @authenticator
def api_ceph_volume_snapshot_remove(pool, volume, snapshot): def api_ceph_volume_snapshot_remove(pool, volume, snapshot):
"""
Remove a Ceph RBD volume snapshot with name SNAPSHOT from RBD volume with name VOLUME in RBD pool with name POOL.
"""
return pvcapi.ceph_volume_snapshot_remove(pool, volume, snapshot) return pvcapi.ceph_volume_snapshot_remove(pool, volume, snapshot)
# #

View File

@ -277,21 +277,19 @@ Add a new virtual network to the cluster. `vni` must be a valid VNI, either a vL
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: N/A * Optional values: N/A
Return a JSON document containing information about the virtual network with description `<network>`. The output is identical to `/api/v1/network?limit=<network>` without fuzzy regex matching. Return a JSON document containing information about the virtual network `<network>`. The output is identical to `/api/v1/network?limit=<network>` without fuzzy regex matching.
###### `PUT` ###### `PUT`
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: `vni`, `nettype` `domain`, `ip4_network`, `ip4_gateway`, `ip6_network`, `ip6_gateway`, `dhcp4`, `dhcp4_start`, `dhcp4_end` * Optional values: `domain`, `ip4_network`, `ip4_gateway`, `ip6_network`, `ip6_gateway`, `dhcp4`, `dhcp4_start`, `dhcp4_end`
Modify the options of an existing virtual network with description `<network>`. Modify the options of an existing virtual network `<network>`.
All values are optional and are identical to the values for `add`. Only those values specified will be updated. All values are optional and are identical to the values for `add`. Only those values specified will be updated.
**NOTE:** Changing the `vni` or `nettype` of a virtual network is technically possible, but is not recommended. This would require updating all VMs in the network. It is usually advisable to create a new virtual network with the new VNI and type, move VMs to it, then finally remove the old virtual network.
###### `DELETE` ###### `DELETE`
Remove a virtual network with description `<network>`. Remove a virtual network `<network>`.
#### `/api/v1/network/<network>/lease` #### `/api/v1/network/<network>/lease`
* Methods: `GET`, `POST` * Methods: `GET`, `POST`
@ -300,7 +298,7 @@ Remove a virtual network with description `<network>`.
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: `limit`, `static` * Optional values: `limit`, `static`
Return a JSON document containing information about all active DHCP leases in virtual network with description `<network>`. Return a JSON document containing information about all active DHCP leases in virtual network `<network>`.
If `limit` is specified, return a JSON document containing information about all active DHCP leases with MAC addresses matching `limit` as fuzzy regex. If `limit` is specified, return a JSON document containing information about all active DHCP leases with MAC addresses matching `limit` as fuzzy regex.
@ -310,7 +308,7 @@ If `static` is specified, only return static DHCP leases.
* Mandatory values: `macaddress`, `ipaddress` * Mandatory values: `macaddress`, `ipaddress`
* Optional values: `hostname` * Optional values: `hostname`
Add a new static DHCP lease for MAC address `<macaddress>` in virtual network with description `<network>`. Add a new static DHCP lease for MAC address `<macaddress>` in virtual network `<network>`.
`ipaddress` must be a valid IP address in the specified `<network>` IPv4 netblock, and ideally outside of the DHCPv4 range. `ipaddress` must be a valid IP address in the specified `<network>` IPv4 netblock, and ideally outside of the DHCPv4 range.
@ -323,13 +321,13 @@ Add a new static DHCP lease for MAC address `<macaddress>` in virtual network wi
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: N/A * Optional values: N/A
Return a JSON document containing information about DHCP lease with MAC address `<lease>` in virtual network with description `<network>`. The output is identical to `/api/v1/network/<network>/dhcp?limit=<lease>` without fuzzy regex matching. Return a JSON document containing information about DHCP lease with MAC address `<lease>` in virtual network `<network>`. The output is identical to `/api/v1/network/<network>/dhcp?limit=<lease>` without fuzzy regex matching.
###### `DELETE` ###### `DELETE`
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: N/A * Optional values: N/A
Remove a static DHCP lease for MAC address `<lease`> in virtual network with description `<network>`. Remove a static DHCP lease for MAC address `<lease`> in virtual network `<network>`.
#### `/api/v1/network/<network>/acl` #### `/api/v1/network/<network>/acl`
* Methods: `GET`, `POST` * Methods: `GET`, `POST`
@ -338,17 +336,17 @@ Remove a static DHCP lease for MAC address `<lease`> in virtual network with des
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: `limit`, `direction` * Optional values: `limit`, `direction`
Return a JSON document containing information about all active NFTables ACLs in virtual network with description `<network>`. Return a JSON document containing information about all active NFTables ACLs in virtual network `<network>`.
If `limit` is specified, return a JSON document containing information about all active NFTables ACLs with descriptions matching `limit` as fuzzy regex. If `limit` is specified, return a JSON document containing information about all active NFTables ACLs with descriptions matching `limit` as fuzzy regex.
If `direction` is specified and is one of `in` or `out`, return a JSON codument listing all active NFTables ACLs in the specified direction only. If `direction` is invalid, return a failure. If `direction` is specified and is one of `in` or `out`, return a JSON codument listing all active NFTables ACLs in the specified direction only. If `direction` is invalid, return a failure.
###### `POST` ###### `POST`
* Mandatory values: `direction`, `rule` * Mandatory values: `description`, `direction`, `rule`
* Optional values: `order` * Optional values: `order`
Add a new NFTables ACL with description `<acl>` in virtual network with description `<network>`. Add a new NFTables ACL with `description` in virtual network `<network>`.
`direction` must be one of `in` or `out`. `direction` must be one of `in` or `out`.
@ -363,15 +361,15 @@ Add a new NFTables ACL with description `<acl>` in virtual network with descript
* Mandatory values: N/A * Mandatory values: N/A
* Optional values: N/A * Optional values: N/A
Return a JSON document containing information about NFTables ACL with description `<acl>` in virtual network with description `<network>`. The output is identical to `/api/v1/network/<network>/acl?limit=<acl>` without fuzzy regex matching. Return a JSON document containing information about NFTables ACL with description `<acl>` in virtual network `<network>`. The output is identical to `/api/v1/network/<network>/acl?limit=<acl>` without fuzzy regex matching.
If `<acl>` is not valid, return an empty JSON document. If `<acl>` is not valid, return an empty JSON document.
###### `DELETE` ###### `DELETE`
* Mandatory values: N/A * Mandatory values: `direction`
* Optional values: N/A * Optional values: N/A
Remove an NFTables ACL with description `<acl>` from virtual network with description `<network>`. Remove an NFTables ACL with description `<acl>` in direction `direction` from virtual network `<network>`.
### Storage (Ceph) endpoints ### Storage (Ceph) endpoints