Commit cc665452 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add size and free to floating-ip-pools

parent 4991475e
......@@ -228,12 +228,19 @@ def release_floating_ip(request, floating_ip_id):
return HttpResponse(status=204)
def network_to_pool(network):
pool = network.get_pool(with_lock=False)
return {"name": str(network.id),
"size": pool.pool_size,
"free": pool.count_available()}
@api.api_method(http_method='GET', user_required=True, logger=log,
serializations=["json"])
def list_floating_ip_pools(request):
networks = Network.objects.filter(public=True, floating_ip_pool=True)
networks = utils.filter_modified_since(request, objects=networks)
pools = [{"name": str(net.id)} for net in networks]
pools = map(network_to_pool, networks)
request.serialization = "json"
data = json.dumps({"floating_ip_pools": pools})
request.serialization = "json"
......
......@@ -248,14 +248,15 @@ class FloatingIPPoolsAPITest(BaseAPITest):
self.assertEqual(json.loads(response.content)["floating_ip_pools"], [])
def test_list_pools(self):
net = FloatingIPPoolFactory()
net = FloatingIPPoolFactory(subnet="192.168.0.0/30",
gateway="192.168.0.1")
NetworkFactory(public=True, deleted=True)
NetworkFactory(public=False, deleted=False)
NetworkFactory(public=True, deleted=False)
response = self.get(POOLS_URL)
self.assertSuccess(response)
self.assertEqual(json.loads(response.content)["floating_ip_pools"],
[{"name": str(net.id)}])
[{"name": str(net.id), "size": 4, "free": 1}])
class FloatingIPActionsTest(BaseAPITest):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment