Consolidate path parsing logic in metadata server

This easies understanding of the code.

Change-Id: I3585853f49864402dcd4ce8fa63fd64dbbc6b0cd
This commit is contained in:
Feodor Tersin 2015-09-01 19:54:57 +03:00
parent 9149b914e1
commit 5fb8e79312
1 changed files with 5 additions and 3 deletions

View File

@ -79,8 +79,10 @@ class MetadataRequestHandler(wsgi.Application):
path = '/' + path
path = posixpath.normpath(path)
path_tokens = path.split('/')[1:]
if path_tokens[0] == 'ec2':
path_tokens = path_tokens[1:]
if path_tokens in ([''], ['ec2']):
if path_tokens == ['']:
resp = api.get_version_list()
return self._add_response_data(req.response, resp)
@ -88,10 +90,10 @@ class MetadataRequestHandler(wsgi.Application):
requester = self._get_requester(req)
if path_tokens[0] == 'openstack':
return self._proxy_request(req, requester)
elif path_tokens[0] == 'ec2':
path_tokens = path_tokens[1:]
resp = self._get_metadata(path_tokens, requester)
return self._add_response_data(req.response, resp)
except exception.EC2MetadataNotFound:
return webob.exc.HTTPNotFound()
except Exception: