diff --git a/etc/events_api.conf b/etc/events_api.conf index 66552fc..6158bfc 100755 --- a/etc/events_api.conf +++ b/etc/events_api.conf @@ -10,6 +10,7 @@ region = useast # Dispatchers to be loaded to serve restful APIs [dispatcher] +versions = monasca_events_api.v2.versions:Versions stream_definitions = monasca_events_api.v2.stream_definitions:StreamDefinitions events = monasca_events_api.v2.events:Events transforms = monasca_events_api.v2.transforms:Transforms diff --git a/monasca_events_api/api/server.py b/monasca_events_api/api/server.py index f95c425..08b250e 100755 --- a/monasca_events_api/api/server.py +++ b/monasca_events_api/api/server.py @@ -22,7 +22,9 @@ import paste.deploy import simport -dispatcher_opts = [cfg.StrOpt('stream_definitions', default=None, +dispatcher_opts = [cfg.StrOpt('versions', default=None, + help='Versions endpoint'), + cfg.StrOpt('stream_definitions', default=None, help='Stream definition endpoint'), cfg.StrOpt('events', default=None, help='Events endpoint'), @@ -46,6 +48,10 @@ def launch(conf, config_file="/etc/monasca/events_api.conf"): app = falcon.API() + versions = simport.load(cfg.CONF.dispatcher.versions)() + app.add_route("/", versions) + app.add_route("/{version_id}", versions) + events = simport.load(cfg.CONF.dispatcher.events)() app.add_route("/v2.0/events", events) app.add_route("/v2.0/events/{event_id}", events) diff --git a/monasca_events_api/api/versions_api.py b/monasca_events_api/api/versions_api.py new file mode 100644 index 0000000..721b3dd --- /dev/null +++ b/monasca_events_api/api/versions_api.py @@ -0,0 +1,26 @@ +# Copyright 2015 Hewlett-Packard +# +# 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 oslo_log import log + +LOG = log.getLogger(__name__) + + +class VersionsAPI(object): + def __init__(self): + super(VersionsAPI, self).__init__() + LOG.info('Initializing Versions!') + + def on_get(self, req, res, id): + res.status = '501 Not Implemented' diff --git a/monasca_events_api/v2/versions.py b/monasca_events_api/v2/versions.py new file mode 100644 index 0000000..23bb5e8 --- /dev/null +++ b/monasca_events_api/v2/versions.py @@ -0,0 +1,63 @@ +# Copyright 2015 Hewlett-Packard +# +# 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 + +import falcon + +from monasca_events_api.api import versions_api +from oslo_log import log + +LOG = log.getLogger(__name__) +VERSIONS = { + 'v2.0': { + 'id': 'v2.0', + 'links': [{ + 'rel': 'self', + 'href': '' + }], + 'status': 'CURRENT', + 'updated': "2014-02-18T00:00:00Z" + } +} + + +class Versions(versions_api.VersionsAPI): + + def __init__(self): + super(Versions, self).__init__() + + def on_get(self, req, res, version_id=None): + result = { + 'links': [{ + 'rel': 'self', + 'href': req.uri.decode('utf8') + }], + 'elements': [] + } + if version_id is None: + for version in VERSIONS: + VERSIONS[version]['links'][0]['href'] = ( + req.uri.decode('utf8') + version) + result['elements'].append(VERSIONS[version]) + res.body = json.dumps(result) + res.status = falcon.HTTP_200 + else: + if version_id in VERSIONS: + VERSIONS[version_id]['links'][0]['href'] = ( + req.uri.decode('utf8')) + res.body = json.dumps(VERSIONS[version_id]) + res.status = falcon.HTTP_200 + else: + res.body = 'Invalid Version ID' + res.status = falcon.HTTP_400 diff --git a/requirements.txt b/requirements.txt index 1985add..2e2b22a 100755 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ # The above command will install monasca-api base and elasticsearch # implementation while leave other implementation dependencies alone. -falcon>=0.2 +falco==0.2 gunicorn>=19.1.0 keystonemiddleware oslo.config>=1.2.1