API: Add v1.1 routing and versioning

Change-Id: I07a14cfb83c252a097e6a995132b83e670228a75
This commit is contained in:
Andrew Hutchings 2013-05-17 16:42:33 +01:00
parent 1b52cd047d
commit 2ee4a76e38
6 changed files with 104 additions and 26 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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
"""

View File

@ -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