"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ec2api/metadata/__init__.py" between
ec2-api-14.0.1.tar.gz and ec2-api-15.0.0.tar.gz

About: OpenStack EC2 API provides a standalone EC2 (and VPC) API service.
The "Zed" series (latest release).

__init__.py  (ec2-api-14.0.1):__init__.py  (ec2-api-15.0.0)
skipping to change at line 23 skipping to change at line 23
# limitations under the License. # limitations under the License.
import hashlib import hashlib
import hmac import hmac
import posixpath import posixpath
import httplib2 import httplib2
from oslo_cache import core as cache_core from oslo_cache import core as cache_core
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import six import urllib.parse as urlparse
import six.moves.urllib.parse as urlparse
import webob import webob
from ec2api import context as ec2_context from ec2api import context as ec2_context
from ec2api import exception from ec2api import exception
from ec2api.i18n import _ from ec2api.i18n import _
from ec2api.metadata import api from ec2api.metadata import api
from ec2api import utils from ec2api import utils
from ec2api import wsgi from ec2api import wsgi
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
skipping to change at line 120 skipping to change at line 119
resp = self._get_metadata(path_tokens, requester) resp = self._get_metadata(path_tokens, requester)
return self._add_response_data(req.response, resp) return self._add_response_data(req.response, resp)
except exception.EC2MetadataNotFound: except exception.EC2MetadataNotFound:
return webob.exc.HTTPNotFound() return webob.exc.HTTPNotFound()
except Exception: except Exception:
LOG.exception("Unexpected error.") LOG.exception("Unexpected error.")
msg = _('An unknown error has occurred. ' msg = _('An unknown error has occurred. '
'Please try your request again.') 'Please try your request again.')
return webob.exc.HTTPInternalServerError( return webob.exc.HTTPInternalServerError(
explanation=six.text_type(msg)) explanation=str(msg))
def _proxy_request(self, req, requester): def _proxy_request(self, req, requester):
headers = self._build_proxy_request_headers(requester) headers = self._build_proxy_request_headers(requester)
nova_ip_port = '%s:%s' % (CONF.metadata.nova_metadata_ip, nova_ip_port = '%s:%s' % (CONF.metadata.nova_metadata_ip,
CONF.metadata.nova_metadata_port) CONF.metadata.nova_metadata_port)
url = urlparse.urlunsplit(( url = urlparse.urlunsplit((
CONF.metadata.nova_metadata_protocol, CONF.metadata.nova_metadata_protocol,
nova_ip_port, nova_ip_port,
req.path_info, req.path_info,
req.query_string, req.query_string,
skipping to change at line 169 skipping to change at line 168
elif resp.status == 404: elif resp.status == 404:
return webob.exc.HTTPNotFound() return webob.exc.HTTPNotFound()
elif resp.status == 409: elif resp.status == 409:
return webob.exc.HTTPConflict() return webob.exc.HTTPConflict()
elif resp.status == 500: elif resp.status == 500:
msg = _( msg = _(
'Remote metadata server experienced an internal server error.' 'Remote metadata server experienced an internal server error.'
) )
LOG.warning(msg) LOG.warning(msg)
return webob.exc.HTTPInternalServerError( return webob.exc.HTTPInternalServerError(
explanation=six.text_type(msg)) explanation=str(msg))
else: else:
raise Exception(_('Unexpected response code: %s') % resp.status) raise Exception(_('Unexpected response code: %s') % resp.status)
def _build_proxy_request_headers(self, requester): def _build_proxy_request_headers(self, requester):
signature = self._sign_instance_id(requester['os_instance_id']) signature = self._sign_instance_id(requester['os_instance_id'])
return { return {
'X-Forwarded-For': requester['private_ip'], 'X-Forwarded-For': requester['private_ip'],
'X-Instance-ID': requester['os_instance_id'], 'X-Instance-ID': requester['os_instance_id'],
'X-Tenant-ID': requester['project_id'], 'X-Tenant-ID': requester['project_id'],
'X-Instance-ID-Signature': signature, 'X-Instance-ID-Signature': signature,
skipping to change at line 215 skipping to change at line 214
signature = req.headers.get('X-Instance-ID-Signature') signature = req.headers.get('X-Instance-ID-Signature')
remote_ip = req.headers.get('X-Forwarded-For') remote_ip = req.headers.get('X-Forwarded-For')
if not remote_ip: if not remote_ip:
raise exception.EC2MetadataInvalidAddress() raise exception.EC2MetadataInvalidAddress()
if os_instance_id is None: if os_instance_id is None:
msg = _('X-Instance-ID header is missing from request.') msg = _('X-Instance-ID header is missing from request.')
elif project_id is None: elif project_id is None:
msg = _('X-Tenant-ID header is missing from request.') msg = _('X-Tenant-ID header is missing from request.')
elif not isinstance(os_instance_id, six.string_types): elif not isinstance(os_instance_id, str):
msg = _('Multiple X-Instance-ID headers found within request.') msg = _('Multiple X-Instance-ID headers found within request.')
elif not isinstance(project_id, six.string_types): elif not isinstance(project_id, str):
msg = _('Multiple X-Tenant-ID headers found within request.') msg = _('Multiple X-Tenant-ID headers found within request.')
else: else:
msg = None msg = None
if msg: if msg:
raise webob.exc.HTTPBadRequest(explanation=msg) raise webob.exc.HTTPBadRequest(explanation=msg)
self._validate_signature(signature, os_instance_id, remote_ip) self._validate_signature(signature, os_instance_id, remote_ip)
return os_instance_id, project_id, remote_ip return os_instance_id, project_id, remote_ip
skipping to change at line 279 skipping to change at line 278
# It's needed for correct describe and auto update DB operations. # It's needed for correct describe and auto update DB operations.
# It doesn't affect operations via OpenStack's clients because # It doesn't affect operations via OpenStack's clients because
# these clients use auth_token field only # these clients use auth_token field only
context.project_id = requester['project_id'] context.project_id = requester['project_id']
return api.get_metadata_item(context, path_tokens, return api.get_metadata_item(context, path_tokens,
requester['os_instance_id'], requester['os_instance_id'],
requester['private_ip'], requester['private_ip'],
self.cache_region) self.cache_region)
def _add_response_data(self, response, data): def _add_response_data(self, response, data):
if isinstance(data, six.text_type): if isinstance(data, str):
response.text = data response.text = data
else: else:
response.body = data response.body = data
response.content_type = 'text/plain' response.content_type = 'text/plain'
return response return response
 End of changes. 6 change blocks. 
7 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)