diff --git a/libra/api/controllers/load_balancers.py b/libra/api/controllers/load_balancers.py index 3db2d98b..c4d6f9da 100644 --- a/libra/api/controllers/load_balancers.py +++ b/libra/api/controllers/load_balancers.py @@ -115,6 +115,7 @@ class LoadBalancersController(RestController): if not load_balancers: response.status = 400 + session.rollback() return dict(status=400, message="load balancer not found") load_balancers = load_balancers._asdict() @@ -149,6 +150,7 @@ class LoadBalancersController(RestController): del node['enabled'] load_balancers['nodes'].append(node) + session.commit() response.status = 200 return load_balancers diff --git a/libra/api/controllers/nodes.py b/libra/api/controllers/nodes.py index b959c04f..acd2ccf2 100644 --- a/libra/api/controllers/nodes.py +++ b/libra/api/controllers/nodes.py @@ -71,9 +71,11 @@ class NodesController(RestController): first() if node_response is None: + session.rollback() response.status = 400 return dict(status=400, message='node not found') else: + session.commit() response.status = 200 return node_response diff --git a/libra/api/controllers/root.py b/libra/api/controllers/root.py index e6179091..a1bacbec 100644 --- a/libra/api/controllers/root.py +++ b/libra/api/controllers/root.py @@ -14,7 +14,7 @@ # under the License. from pecan import expose, response -from load_balancers import LoadBalancersController +from v1 import V1Controller from libra.api.model.responses import Responses @@ -28,33 +28,19 @@ class RootController(object): response.status = 404 return Responses._default + @expose() + def _lookup(self, primary_key, *remainder): + if primary_key == 'v1.1': + return V1Controller(), remainder + else: + response.status = 404 + return Responses._default + @expose('json') def notfound(self): return Responses._default @expose('json') - def protocols(self): - """Lists all supported load balancing protocols. - - Url: - GET /protocols - - Returns: dict - """ + def index(self): response.status = 200 - return Responses.protocols - - @expose('json') - def algorithms(self): - """List all supported load balancing algorithms. - - Url: - GET /algorithms - - Returns: dict - """ - response.status = 200 - return Responses.algorithms - - #pecan uses this controller class for urls that start with /loadbalancers - loadbalancers = LoadBalancersController() + return Responses.versions diff --git a/libra/api/controllers/v1.py b/libra/api/controllers/v1.py new file mode 100644 index 00000000..8045224f --- /dev/null +++ b/libra/api/controllers/v1.py @@ -0,0 +1,54 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from pecan import expose, response +from load_balancers import LoadBalancersController +from libra.api.model.responses import Responses + + +class V1Controller(object): + """v1 control object.""" + + @expose('json') + def index(self): + response.status = 200 + return Responses.versions + + @expose('json') + def protocols(self): + """Lists all supported load balancing protocols. + + Url: + GET /protocols + + Returns: dict + """ + response.status = 200 + return Responses.protocols + + @expose('json') + def algorithms(self): + """List all supported load balancing algorithms. + + Url: + GET /algorithms + + Returns: dict + """ + response.status = 200 + return Responses.algorithms + + #pecan uses this controller class for urls that start with /loadbalancers + loadbalancers = LoadBalancersController() diff --git a/libra/api/model/responses.py b/libra/api/model/responses.py index adafda5e..c8d1a79a 100644 --- a/libra/api/model/responses.py +++ b/libra/api/model/responses.py @@ -54,6 +54,40 @@ class Responses(object): ] } + versions = { + "versions": [ + { + "id": "v1.1", + "updated": "2012-12-18T18:30:02.25Z", + "status": "CURRENT", + "links": [ + { + "rel": "self", + "href": "http://wiki.openstack.org/Atlas-LB" + } + ] + } + ] + } + + v1_1 = { + "version": { + "id": "v1.1", + "updated": "2012-12-18T18:30:02.25Z", + "status": "CURRENT", + "links": [ + { + "rel": "self", + "href": "http://wiki.openstack.org/Atlas-LB" + } + ], + "media-types": [ + { + "base": "application/json" + } + ] + } + } """class LoadBalancers grouping of lb responses """ diff --git a/libra/api/tests/test_functional.py b/libra/api/tests/test_functional.py index 43d64e34..c4970d13 100644 --- a/libra/api/tests/test_functional.py +++ b/libra/api/tests/test_functional.py @@ -21,7 +21,7 @@ class TestRootController(FunctionalTest): def test_get(self): response = self.app.get('/', expect_errors=True) - assert response.status_int == 404 + assert response.status_int == 200 def test_search(self): # Lets get post sorted before enabling this