Revision 7d368e73

b/snf-cyclades-app/synnefo/api/floating_ips.py
46 46
from logging import getLogger
47 47
log = getLogger(__name__)
48 48

  
49
urlpatterns = patterns(
49
ips_urlpatterns = patterns(
50 50
    'synnefo.api.floating_ips',
51 51
    (r'^(?:/|.json|.xml)?$', 'demux'),
52 52
    (r'^/(\w+)(?:.json|.xml)?$', 'floating_ip_demux'),
53 53
)
54 54

  
55
pools_urlpatterns = patterns(
56
    "synnefo.api.floating_ips",
57
    (r'^(?:/|.json|.xml)?$', 'list_floating_ip_pools'),
58
)
59

  
55 60

  
56 61
def demux(request):
57 62
    if request.method == 'GET':
......
183 188
    log.info("User '%s' released IP '%s", userid, floating_ip)
184 189

  
185 190
    return HttpResponse(status=204)
191

  
192

  
193
@api.api_method(http_method='GET', user_required=True, logger=log)
194
def list_floating_ip_pools(request):
195
    networks = Network.objects.filter(public=True, deleted=False)
196
    pools = [{"name": str(net.id)} for net in networks]
197
    request.serialization = "json"
198
    data = json.dumps({"floating_ip_pools": pools})
199
    request.serialization = "json"
200
    return HttpResponse(data, status=200)
b/snf-cyclades-app/synnefo/api/test/floating_ips.py
118 118
        self.assertSuccess(response)
119 119
        ips_after = FloatingIP.objects.filter(id=ip.id)
120 120
        self.assertEqual(len(ips_after), 0)
121

  
122

  
123
POOLS_URL = "/api/v1.1/os-floating-ip-pools"
124

  
125

  
126
class FloatingIPPoolsAPITest(BaseAPITest):
127
    def test_no_pool(self):
128
        response = self.get(POOLS_URL)
129
        self.assertSuccess(response)
130
        self.assertEqual(json.loads(response.content)["floating_ip_pools"], [])
131

  
132
    def test_list_pools(self):
133
        net = NetworkFactory(public=True, deleted=False)
134
        NetworkFactory(public=True, deleted=True)
135
        NetworkFactory(public=False, deleted=False)
136
        response = self.get(POOLS_URL)
137
        self.assertSuccess(response)
138
        self.assertEqual(json.loads(response.content)["floating_ip_pools"],
139
                        [{"name": str(net.id)}])
b/snf-cyclades-app/synnefo/api/urls.py
34 34
from django.conf.urls.defaults import include, patterns
35 35

  
36 36
from snf_django.lib.api import api_endpoint_not_found
37
from synnefo import api
37
from synnefo.api import (servers, flavors, images, networks, extensions,
38
                         floating_ips)
38 39
from synnefo.api.versions import versions_list, version_details
39 40

  
40 41

  
......
43 44
#
44 45
api20_patterns = patterns(
45 46
    '',
46
    (r'^servers', include(api.servers)),
47
    (r'^flavors', include(api.flavors)),
48
    (r'^images', include(api.images)),
49
    (r'^networks', include(api.networks)),
50
    (r'^extensions', include(api.extensions)),
51
    (r'^os-floating-ips', include(api.floating_ips)),
47
    (r'^servers', include(servers)),
48
    (r'^flavors', include(flavors)),
49
    (r'^images', include(images)),
50
    (r'^networks', include(networks)),
51
    (r'^extensions', include(extensions)),
52
    (r'^os-floating-ips', include(floating_ips.ips_urlpatterns)),
53
    (r'^os-floating-ip-pools', include(floating_ips.pools_urlpatterns)),
52 54
)
53 55

  
54 56

  

Also available in: Unified diff