Beispiel #1
0
    def __call__(self, req):
        LOG.debug('Request: %s', req)

        path = req.path_info
        if path == '' or path[0] != '/':
            path = '/' + path
        path = posixpath.normpath(path)
        path_tokens = path.split('/')[1:]

        if path_tokens in ([''], ['ec2']):
            resp = api.get_version_list()
            return self._add_response_data(req.response, resp)

        try:
            if path_tokens[0] == 'openstack':
                return self._proxy_request(req)
            elif path_tokens[0] == 'ec2':
                path_tokens = path_tokens[1:]
            resp = self._get_metadata(req, path_tokens)
            return self._add_response_data(req.response, resp)
        except exception.EC2MetadataNotFound:
            return webob.exc.HTTPNotFound()
        except Exception:
            LOG.exception(_LE("Unexpected error."))
            msg = _('An unknown error has occurred. '
                    'Please try your request again.')
            return webob.exc.HTTPInternalServerError(explanation=unicode(msg))
Beispiel #2
0
    def __call__(self, req):
        LOG.debug('Request: %s', req)

        path = req.path_info
        if path == '' or path[0] != '/':
            path = '/' + path
        path = posixpath.normpath(path)
        path_tokens = path.split('/')[1:]
        if path_tokens[0] == 'ec2':
            path_tokens = path_tokens[1:]

        if path_tokens == ['']:
            resp = api.get_version_list()
            return self._add_response_data(req.response, resp)

        try:
            requester = self._get_requester(req)
            if path_tokens[0] == 'openstack':
                return self._proxy_request(req, requester)

            resp = self._get_metadata(path_tokens, requester)
            return self._add_response_data(req.response, resp)

        except exception.EC2MetadataNotFound:
            return webob.exc.HTTPNotFound()
        except Exception:
            LOG.exception("Unexpected error.")
            msg = _('An unknown error has occurred. '
                    'Please try your request again.')
            return webob.exc.HTTPInternalServerError(
                explanation=six.text_type(msg))
 def test_get_version_list(self):
     retval = api.get_version_list()
     self.assertEqual('\n'.join(api.VERSIONS + ['latest']), retval)
Beispiel #4
0
 def test_get_version_list(self):
     retval = api.get_version_list()
     self.assertEqual('\n'.join(api.VERSIONS + ['latest']), retval)
 def test_get_version_list(self):
     retval = api.get_version_list()
     self.assertEqual("\n".join(api.VERSIONS + ["latest"]), retval)