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

cyclades: Implement /floating-ip-pools API

Add Compute OS API extension /floating-ip-pools. This API implements
only the GET /floating-ip-pools, which returns the list of available
Floating IP pools. Currently, these pools are the public networks.
parent d14b3636
......@@ -46,12 +46,17 @@ from synnefo.db.models import Network, FloatingIP
from logging import getLogger
log = getLogger(__name__)
urlpatterns = patterns(
ips_urlpatterns = patterns(
'synnefo.api.floating_ips',
(r'^(?:/|.json|.xml)?$', 'demux'),
(r'^/(\w+)(?:.json|.xml)?$', 'floating_ip_demux'),
)
pools_urlpatterns = patterns(
"synnefo.api.floating_ips",
(r'^(?:/|.json|.xml)?$', 'list_floating_ip_pools'),
)
def demux(request):
if request.method == 'GET':
......@@ -183,3 +188,13 @@ def release_floating_ip(request, floating_ip_id):
log.info("User '%s' released IP '%s", userid, floating_ip)
return HttpResponse(status=204)
@api.api_method(http_method='GET', user_required=True, logger=log)
def list_floating_ip_pools(request):
networks = Network.objects.filter(public=True, deleted=False)
pools = [{"name": str(net.id)} for net in networks]
request.serialization = "json"
data = json.dumps({"floating_ip_pools": pools})
request.serialization = "json"
return HttpResponse(data, status=200)
......@@ -118,3 +118,22 @@ class FloatingIPAPITest(BaseAPITest):
self.assertSuccess(response)
ips_after = FloatingIP.objects.filter(id=ip.id)
self.assertEqual(len(ips_after), 0)
POOLS_URL = "/api/v1.1/os-floating-ip-pools"
class FloatingIPPoolsAPITest(BaseAPITest):
def test_no_pool(self):
response = self.get(POOLS_URL)
self.assertSuccess(response)
self.assertEqual(json.loads(response.content)["floating_ip_pools"], [])
def test_list_pools(self):
net = NetworkFactory(public=True, deleted=False)
NetworkFactory(public=True, deleted=True)
NetworkFactory(public=False, deleted=False)
response = self.get(POOLS_URL)
self.assertSuccess(response)
self.assertEqual(json.loads(response.content)["floating_ip_pools"],
[{"name": str(net.id)}])
......@@ -34,7 +34,8 @@
from django.conf.urls.defaults import include, patterns
from snf_django.lib.api import api_endpoint_not_found
from synnefo import api
from synnefo.api import (servers, flavors, images, networks, extensions,
floating_ips)
from synnefo.api.versions import versions_list, version_details
......@@ -43,12 +44,13 @@ from synnefo.api.versions import versions_list, version_details
#
api20_patterns = patterns(
'',
(r'^servers', include(api.servers)),
(r'^flavors', include(api.flavors)),
(r'^images', include(api.images)),
(r'^networks', include(api.networks)),
(r'^extensions', include(api.extensions)),
(r'^os-floating-ips', include(api.floating_ips)),
(r'^servers', include(servers)),
(r'^flavors', include(flavors)),
(r'^images', include(images)),
(r'^networks', include(networks)),
(r'^extensions', include(extensions)),
(r'^os-floating-ips', include(floating_ips.ips_urlpatterns)),
(r'^os-floating-ip-pools', include(floating_ips.pools_urlpatterns)),
)
......
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