summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Prince <dan.prince@rackspace.com>2011-08-29 18:36:30 +0000
committerTarmac <>2011-08-29 18:36:30 +0000
commit2a2aa10316abe9135541198bddd4c189976eb2fd (patch)
tree8f30ad33aaf047b705e8f95d5913810bfbc727db
parentcff35e4bc169d3d011aa3b32f3812ec21455b365 (diff)
parent6b6de435efb83fc88c885c459fb70c46c646be84 (diff)
Update the EC2 ToToken middleware to use eventlet.green.httplib instead of httplib2. Fixes issues where the JSON request body wasn't getting sent to Keystone.
-rw-r--r--nova/api/ec2/__init__.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py
index 5430f443d..ec4743cea 100644
--- a/nova/api/ec2/__init__.py
+++ b/nova/api/ec2/__init__.py
@@ -20,7 +20,10 @@ Starting point for routing EC2 requests.
"""
-import httplib2
+from urlparse import urlparse
+
+import eventlet
+from eventlet.green import httplib
import webob
import webob.dec
import webob.exc
@@ -35,7 +38,6 @@ from nova.api.ec2 import apirequest
from nova.api.ec2 import ec2utils
from nova.auth import manager
-
FLAGS = flags.FLAGS
LOG = logging.getLogger("nova.api")
flags.DEFINE_integer('lockout_attempts', 5,
@@ -158,7 +160,6 @@ class ToToken(wsgi.Middleware):
auth_params.pop('Signature')
# Authenticate the request.
- client = httplib2.Http()
creds = {'ec2Credentials': {'access': access,
'signature': signature,
'host': req.host,
@@ -166,18 +167,24 @@ class ToToken(wsgi.Middleware):
'path': req.path,
'params': auth_params,
}}
- headers = {'Content-Type': 'application/json'},
- resp, content = client.request(FLAGS.keystone_ec2_url,
- 'POST',
- headers=headers,
- body=utils.dumps(creds))
+ creds_json = utils.dumps(creds)
+ headers = {'Content-Type': 'application/json'}
+ o = urlparse(FLAGS.keystone_ec2_url)
+ if o.scheme == "http":
+ conn = httplib.HTTPConnection(o.netloc)
+ else:
+ conn = httplib.HTTPSConnection(o.netloc)
+ conn.request('POST', o.path, body=creds_json, headers=headers)
+ response = conn.getresponse().read()
+ conn.close()
+
# NOTE(vish): We could save a call to keystone by
# having keystone return token, tenant,
# user, and roles from this call.
- result = utils.loads(content)
+ result = utils.loads(response)
# TODO(vish): check for errors
- token_id = result['auth']['token']['id']
+ token_id = result['auth']['token']['id']
# Authenticated!
req.headers['X-Auth-Token'] = token_id
return self.application