Update API to falcon 0.3

Mostly compatible, but required a different approach for the
versions resource. Should be able to revert when updating to
falcon 0.4

Change-Id: I41a5073748c9a8a3f5b92afdb416bb0294311911
This commit is contained in:
Ryan Brandt 2016-01-22 15:00:57 -07:00
parent b6a44d9244
commit 370d34f65f
6 changed files with 43 additions and 1 deletions

View File

@ -9,6 +9,7 @@ Derrick Johnson <johnson.derrick@gmail.com>
Dexter Fryar <dexter.fryar@outlook.com>
Ghanshyam <ghanshyam.mann@nectechnologies.in>
Haiwei Xu <xu-haiwei@mxw.nes.nec.co.jp>
Janonymous <janonymous.codevulture@gmail.com>
Jeremy Stanley <fungi@yuggoth.org>
Joe Keen <joe.keen@hp.com>
Jonathan Halterman <jhalterman@gmail.com>

View File

@ -11,6 +11,7 @@ region = useast
# Dispatchers to be loaded to serve restful APIs
[dispatcher]
versions = monasca_api.v2.reference.versions:Versions
version_2_0 = monasca_api.v2.reference.version_2_0:Version2
metrics = monasca_api.v2.reference.metrics:Metrics
metrics_measurements = monasca_api.v2.reference.metrics:MetricsMeasurements
metrics_statistics = monasca_api.v2.reference.metrics:MetricsStatistics

View File

@ -11,6 +11,7 @@ region = useast
# Dispatchers to be loaded to serve restful APIs
[dispatcher]
versions = monasca_api.v2.reference.versions:Versions
version_2_0 = monasca_api.v2.reference.version_2_0:Version2
metrics = monasca_api.v2.reference.metrics:Metrics
metrics_measurements = monasca_api.v2.reference.metrics:MetricsMeasurements
metrics_statistics = monasca_api.v2.reference.metrics:MetricsStatistics

View File

@ -24,6 +24,8 @@ import simport
dispatcher_opts = [cfg.StrOpt('versions', default=None,
help='Versions'),
cfg.StrOpt('version_2_0', default=None,
help='Version 2.0'),
cfg.StrOpt('metrics', default=None,
help='Metrics'),
cfg.StrOpt('metrics_measurements', default=None,
@ -62,6 +64,11 @@ def launch(conf, config_file="/etc/monasca/api-config.conf"):
app.add_route("/", versions)
app.add_route("/{version_id}", versions)
# The following resource is a workaround for a regression in falcon 0.3
# which causes the path '/v2.0' to not route to the versions resource
version_2_0 = simport.load(cfg.CONF.dispatcher.version_2_0)()
app.add_route("/v2.0", version_2_0)
metrics = simport.load(cfg.CONF.dispatcher.metrics)()
app.add_route("/v2.0/metrics", metrics)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Hewlett Packard Enterprise 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.
import json
class Version2(object):
def __init__(self):
super(Version2, self).__init__()
def on_get(self, req, res):
result = {
'id': 'v2.0',
'links': [{
'rel': 'self',
'href': req.uri.decode('utf-8')
}],
'status': 'CURRENT',
'updated': "2013-03-06T00:00:00.000Z"
}
res.body = json.dumps(result)

View File

@ -7,7 +7,7 @@ oslo.utils
python-keystoneclient
falcon==0.2.0
falcon==0.3.0
gunicorn>=19.1.0
keystonemiddleware
pastedeploy>=1.3.3