1 # Copyright 2013 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
17 /hosts endpoint for Escalator v1 API
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
27 LOG = logging.getLogger(__name__)
36 WSGI controller for hosts resource in Escalator v1 API
40 self.notifier = notifier.Notifier()
43 def version(self, req, version):
45 Get version of esclator.
46 :param req: The WSGI/Webob Request object
48 if version.get('type') == 'pbr':
49 return {"escalator_version":
50 version_info.version_string_with_vcs()}
52 # reserved for external version
53 return {"escalator_version": '1.0.0-1.1.0'}
56 class VersionDeserializer(wsgi.JSONRequestDeserializer):
57 """Handles deserialization of specific controller method requests."""
59 def _deserialize(self, request):
61 result['file_meta'] = utils.get_dict_meta(request)
64 def version(self, request):
66 result['version'] = utils.get_dict_meta(request)
70 class VersionSerializer(wsgi.JSONResponseSerializer):
71 """Handles serialization of specific controller method responses."""
74 self.notifier = notifier.Notifier()
76 def version(self, response, result):
78 response.headers['Content-Type'] = 'application/json'
79 response.body = self.to_json(result)
83 def create_resource():
84 """Version resource factory method"""
85 deserializer = VersionDeserializer()
86 serializer = VersionSerializer()
87 return wsgi.Resource(Controller(), deserializer, serializer)