API: Add v1.1 routing and versioning
Change-Id: I07a14cfb83c252a097e6a995132b83e670228a75
This commit is contained in:
parent
1b52cd047d
commit
2ee4a76e38
@ -115,6 +115,7 @@ class LoadBalancersController(RestController):
|
|||||||
|
|
||||||
if not load_balancers:
|
if not load_balancers:
|
||||||
response.status = 400
|
response.status = 400
|
||||||
|
session.rollback()
|
||||||
return dict(status=400, message="load balancer not found")
|
return dict(status=400, message="load balancer not found")
|
||||||
|
|
||||||
load_balancers = load_balancers._asdict()
|
load_balancers = load_balancers._asdict()
|
||||||
@ -149,6 +150,7 @@ class LoadBalancersController(RestController):
|
|||||||
del node['enabled']
|
del node['enabled']
|
||||||
load_balancers['nodes'].append(node)
|
load_balancers['nodes'].append(node)
|
||||||
|
|
||||||
|
session.commit()
|
||||||
response.status = 200
|
response.status = 200
|
||||||
return load_balancers
|
return load_balancers
|
||||||
|
|
||||||
|
@ -71,9 +71,11 @@ class NodesController(RestController):
|
|||||||
first()
|
first()
|
||||||
|
|
||||||
if node_response is None:
|
if node_response is None:
|
||||||
|
session.rollback()
|
||||||
response.status = 400
|
response.status = 400
|
||||||
return dict(status=400, message='node not found')
|
return dict(status=400, message='node not found')
|
||||||
else:
|
else:
|
||||||
|
session.commit()
|
||||||
response.status = 200
|
response.status = 200
|
||||||
return node_response
|
return node_response
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from pecan import expose, response
|
from pecan import expose, response
|
||||||
from load_balancers import LoadBalancersController
|
from v1 import V1Controller
|
||||||
from libra.api.model.responses import Responses
|
from libra.api.model.responses import Responses
|
||||||
|
|
||||||
|
|
||||||
@ -28,33 +28,19 @@ class RootController(object):
|
|||||||
response.status = 404
|
response.status = 404
|
||||||
return Responses._default
|
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')
|
@expose('json')
|
||||||
def notfound(self):
|
def notfound(self):
|
||||||
return Responses._default
|
return Responses._default
|
||||||
|
|
||||||
@expose('json')
|
@expose('json')
|
||||||
def protocols(self):
|
def index(self):
|
||||||
"""Lists all supported load balancing protocols.
|
|
||||||
|
|
||||||
Url:
|
|
||||||
GET /protocols
|
|
||||||
|
|
||||||
Returns: dict
|
|
||||||
"""
|
|
||||||
response.status = 200
|
response.status = 200
|
||||||
return Responses.protocols
|
return Responses.versions
|
||||||
|
|
||||||
@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()
|
|
||||||
|
54
libra/api/controllers/v1.py
Normal file
54
libra/api/controllers/v1.py
Normal 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()
|
@ -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
|
"""class LoadBalancers
|
||||||
grouping of lb responses
|
grouping of lb responses
|
||||||
"""
|
"""
|
||||||
|
@ -21,7 +21,7 @@ class TestRootController(FunctionalTest):
|
|||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
response = self.app.get('/', expect_errors=True)
|
response = self.app.get('/', expect_errors=True)
|
||||||
assert response.status_int == 404
|
assert response.status_int == 200
|
||||||
|
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
# Lets get post sorted before enabling this
|
# Lets get post sorted before enabling this
|
||||||
|
Loading…
x
Reference in New Issue
Block a user