Merge "Add NetworkDriver api AllocateNetwork and FreeNetwork"
This commit is contained in:
commit
c51fb9d7ae
kuryr_libnetwork
@ -607,6 +607,46 @@ def network_driver_discover_delete():
|
||||
return flask.jsonify(const.SCHEMA['SUCCESS'])
|
||||
|
||||
|
||||
@app.route('/NetworkDriver.AllocateNetwork', methods=['POST'])
|
||||
def network_driver_allocate_network():
|
||||
"""Allocate network specific resources passing network id and network specific config.
|
||||
|
||||
Libnetwork miss this API in their doc.
|
||||
https://github.com/docker/libnetwork/issues/1699
|
||||
|
||||
See the following like for more detail about the spec:
|
||||
|
||||
https://github.com/docker/libnetwork/blob/master/driverapi/driverapi.go # noqa
|
||||
"""
|
||||
json_data = flask.request.get_json(force=True)
|
||||
LOG.debug("Received JSON data %s for "
|
||||
"/NetworkDriver.AllocateNetwork", json_data)
|
||||
# Note(limao): This API will only called in docker swarm mode,
|
||||
# we do not have specific resource need to allocate
|
||||
# right now, so just return SUCCESS.
|
||||
return flask.jsonify(const.SCHEMA['SUCCESS'])
|
||||
|
||||
|
||||
@app.route('/NetworkDriver.FreeNetwork', methods=['POST'])
|
||||
def network_driver_free_network():
|
||||
"""Free network specific resources associated with a given network id.
|
||||
|
||||
Libnetwork miss this API in their doc.
|
||||
https://github.com/docker/libnetwork/issues/1699
|
||||
|
||||
See the following like for more detail about the spec:
|
||||
|
||||
https://github.com/docker/libnetwork/blob/master/driverapi/driverapi.go # noqa
|
||||
"""
|
||||
json_data = flask.request.get_json(force=True)
|
||||
LOG.debug("Received JSON data %s for "
|
||||
"/NetworkDriver.FreeNetwork", json_data)
|
||||
# Note(limao): This API will only called in docker swarm mode,
|
||||
# we do not have network resource to free right now,
|
||||
# so just return SUCCESS.
|
||||
return flask.jsonify(const.SCHEMA['SUCCESS'])
|
||||
|
||||
|
||||
@app.route('/NetworkDriver.CreateNetwork', methods=['POST'])
|
||||
def network_driver_create_network():
|
||||
"""Creates a new Neutron Network which name is the given NetworkID.
|
||||
|
@ -45,6 +45,8 @@ class TestKuryr(base.TestKuryrBase):
|
||||
- POST /NetworkDriver.Leave
|
||||
- POST /NetworkDriver.DiscoverNew
|
||||
- POST /NetworkDriver.DiscoverDelete
|
||||
- POST /NetworkDriver.AllocateNetwork
|
||||
- POST /NetworkDriver.FreeNetwork
|
||||
"""
|
||||
@ddt.data(('/Plugin.Activate', constants.SCHEMA['PLUGIN_ACTIVATE']),
|
||||
('/NetworkDriver.GetCapabilities',
|
||||
@ -2260,3 +2262,35 @@ class TestKuryr(base.TestKuryrBase):
|
||||
self.assertEqual(200, response.status_code)
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(constants.SCHEMA['SUCCESS'], decoded_json)
|
||||
|
||||
def test_network_driver_allocate_network(self):
|
||||
docker_network_id = lib_utils.get_hash()
|
||||
allocate_network_request = {
|
||||
'NetworkID': docker_network_id,
|
||||
'IPv4Data': [{
|
||||
'AddressSpace': 'foo',
|
||||
'Pool': '192.168.42.0/24',
|
||||
'Gateway': '192.168.42.1/24',
|
||||
}],
|
||||
'IPv6Data': [],
|
||||
'Options': {}
|
||||
}
|
||||
|
||||
response = self.app.post('/NetworkDriver.AllocateNetwork',
|
||||
content_type='application/json',
|
||||
data=jsonutils.dumps(
|
||||
allocate_network_request))
|
||||
self.assertEqual(200, response.status_code)
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(constants.SCHEMA['SUCCESS'], decoded_json)
|
||||
|
||||
def test_network_driver_free_network(self):
|
||||
docker_network_id = lib_utils.get_hash()
|
||||
free_network_request = {'NetworkID': docker_network_id}
|
||||
|
||||
response = self.app.post('/NetworkDriver.FreeNetwork',
|
||||
content_type='application/json',
|
||||
data=jsonutils.dumps(free_network_request))
|
||||
self.assertEqual(200, response.status_code)
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(constants.SCHEMA['SUCCESS'], decoded_json)
|
||||
|
Loading…
x
Reference in New Issue
Block a user