~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/api/ec2/__init__.py

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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
"""
22
22
 
23
 
import httplib2
 
23
from urlparse import urlparse
 
24
 
 
25
import eventlet
 
26
from eventlet.green import httplib
24
27
import webob
25
28
import webob.dec
26
29
import webob.exc
35
38
from nova.api.ec2 import ec2utils
36
39
from nova.auth import manager
37
40
 
38
 
 
39
41
FLAGS = flags.FLAGS
40
42
LOG = logging.getLogger("nova.api")
41
43
flags.DEFINE_integer('lockout_attempts', 5,
158
160
        auth_params.pop('Signature')
159
161
 
160
162
        # Authenticate the request.
161
 
        client = httplib2.Http()
162
163
        creds = {'ec2Credentials': {'access': access,
163
164
                                    'signature': signature,
164
165
                                    'host': req.host,
166
167
                                    'path': req.path,
167
168
                                    'params': auth_params,
168
169
                                   }}
169
 
        headers = {'Content-Type': 'application/json'},
170
 
        resp, content = client.request(FLAGS.keystone_ec2_url,
171
 
                                       'POST',
172
 
                                       headers=headers,
173
 
                                       body=utils.dumps(creds))
 
170
        creds_json = utils.dumps(creds)
 
171
        headers = {'Content-Type': 'application/json'}
 
172
        o = urlparse(FLAGS.keystone_ec2_url)
 
173
        if o.scheme == "http":
 
174
            conn = httplib.HTTPConnection(o.netloc)
 
175
        else:
 
176
            conn = httplib.HTTPSConnection(o.netloc)
 
177
        conn.request('POST', o.path, body=creds_json, headers=headers)
 
178
        response = conn.getresponse().read()
 
179
        conn.close()
 
180
 
174
181
        # NOTE(vish): We could save a call to keystone by
175
182
        #             having keystone return token, tenant,
176
183
        #             user, and roles from this call.
177
 
        result = utils.loads(content)
 
184
        result = utils.loads(response)
178
185
        # TODO(vish): check for errors
 
186
 
179
187
        token_id = result['auth']['token']['id']
180
 
 
181
188
        # Authenticated!
182
189
        req.headers['X-Auth-Token'] = token_id
183
190
        return self.application