Revert "escalator should use oslo.xxx instead of oslo-xxx"
[escalator.git] / api / escalator / api / v1 / versions.py
1 # Copyright 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16 """
17 /hosts endpoint for Escalator v1 API
18 """
19 from oslo_log import log as logging
20 from escalator import i18n
21 from escalator import notifier
22 from escalator.common import utils
23 from escalator.common import wsgi
24 from escalator.version import version_info
25
26
27 LOG = logging.getLogger(__name__)
28 _ = i18n._
29 _LE = i18n._LE
30 _LI = i18n._LI
31 _LW = i18n._LW
32
33
34 class Controller():
35     """
36     WSGI controller for hosts resource in Escalator v1 API
37
38     """
39     def __init__(self):
40         self.notifier = notifier.Notifier()
41
42     @utils.mutating
43     def version(self, req, version):
44         """
45         Get version of esclator.
46         :param req: The WSGI/Webob Request object
47         """
48         if version.get('type') == 'pbr':
49             return {"escalator_version":
50                     version_info.version_string_with_vcs()}
51         else:
52             # reserved for external version
53             return {"escalator_version": '1.0.0-1.1.0'}
54
55
56 class VersionDeserializer(wsgi.JSONRequestDeserializer):
57     """Handles deserialization of specific controller method requests."""
58
59     def _deserialize(self, request):
60         result = {}
61         result['file_meta'] = utils.get_dict_meta(request)
62         return result
63
64     def version(self, request):
65         result = {}
66         result['version'] = utils.get_dict_meta(request)
67         return result
68
69
70 class VersionSerializer(wsgi.JSONResponseSerializer):
71     """Handles serialization of specific controller method responses."""
72
73     def __init__(self):
74         self.notifier = notifier.Notifier()
75
76     def version(self, response, result):
77         response.status = 201
78         response.headers['Content-Type'] = 'application/json'
79         response.body = self.to_json(result)
80         return response
81
82
83 def create_resource():
84     """Version resource factory method"""
85     deserializer = VersionDeserializer()
86     serializer = VersionSerializer()
87     return wsgi.Resource(Controller(), deserializer, serializer)