~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/direct_client.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-28 09:40:30 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130128094030-aetz57x2qz9ye2d4
Tags: 1.7.6-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    if not is_success(resp.status):
75
75
        resp.read()
76
76
        raise ClientException(
77
 
            'Account server %s:%s direct GET %s gave status %s' % (node['ip'],
78
 
                node['port'], repr('/%s/%s%s' % (node['device'], part, path)),
79
 
                resp.status),
 
77
            'Account server %s:%s direct GET %s gave status %s' %
 
78
            (node['ip'], node['port'],
 
79
             repr('/%s/%s%s' % (node['device'], part, path)),
 
80
             resp.status),
80
81
            http_host=node['ip'], http_port=node['port'],
81
82
            http_device=node['device'], http_status=resp.status,
82
83
            http_reason=resp.reason)
112
113
        resp.read()
113
114
    if not is_success(resp.status):
114
115
        raise ClientException(
115
 
                'Container server %s:%s direct HEAD %s gave status %s' %
116
 
                (node['ip'], node['port'],
117
 
                 repr('/%s/%s%s' % (node['device'], part, path)),
118
 
                 resp.status),
119
 
                http_host=node['ip'], http_port=node['port'],
120
 
                http_device=node['device'], http_status=resp.status,
121
 
                http_reason=resp.reason)
 
116
            'Container server %s:%s direct HEAD %s gave status %s' %
 
117
            (node['ip'], node['port'],
 
118
             repr('/%s/%s%s' % (node['device'], part, path)),
 
119
             resp.status),
 
120
            http_host=node['ip'], http_port=node['port'],
 
121
            http_device=node['device'], http_status=resp.status,
 
122
            http_reason=resp.reason)
122
123
    resp_headers = {}
123
124
    for header, value in resp.getheaders():
124
125
        resp_headers[header.lower()] = value
162
163
    if not is_success(resp.status):
163
164
        resp.read()
164
165
        raise ClientException(
165
 
            'Container server %s:%s direct GET %s gave stats %s' % (node['ip'],
166
 
                node['port'], repr('/%s/%s%s' % (node['device'], part, path)),
167
 
                resp.status),
 
166
            'Container server %s:%s direct GET %s gave stats %s' %
 
167
            (node['ip'], node['port'],
 
168
             repr('/%s/%s%s' % (node['device'], part, path)),
 
169
             resp.status),
168
170
            http_host=node['ip'], http_port=node['port'],
169
171
            http_device=node['device'], http_status=resp.status,
170
172
            http_reason=resp.reason)
183
185
    headers['X-Timestamp'] = normalize_timestamp(time())
184
186
    with Timeout(conn_timeout):
185
187
        conn = http_connect(node['ip'], node['port'], node['device'], part,
186
 
                'DELETE', path, headers)
 
188
                            'DELETE', path, headers)
187
189
    with Timeout(response_timeout):
188
190
        resp = conn.getresponse()
189
191
        resp.read()
190
192
    if not is_success(resp.status):
191
193
        raise ClientException(
192
 
                'Container server %s:%s direct DELETE %s gave status %s' %
193
 
                (node['ip'], node['port'],
194
 
                repr('/%s/%s%s' % (node['device'], part, path)),
195
 
                resp.status),
196
 
                http_host=node['ip'], http_port=node['port'],
197
 
                http_device=node['device'], http_status=resp.status,
198
 
                http_reason=resp.reason)
 
194
            'Container server %s:%s direct DELETE %s gave status %s' %
 
195
            (node['ip'], node['port'],
 
196
             repr('/%s/%s%s' % (node['device'], part, path)), resp.status),
 
197
            http_host=node['ip'], http_port=node['port'],
 
198
            http_device=node['device'], http_status=resp.status,
 
199
            http_reason=resp.reason)
199
200
 
200
201
 
201
202
def direct_head_object(node, part, account, container, obj, conn_timeout=5,
222
223
        resp.read()
223
224
    if not is_success(resp.status):
224
225
        raise ClientException(
225
 
                'Object server %s:%s direct HEAD %s gave status %s' %
226
 
                (node['ip'], node['port'],
227
 
                 repr('/%s/%s%s' % (node['device'], part, path)),
228
 
                 resp.status),
229
 
                http_host=node['ip'], http_port=node['port'],
230
 
                http_device=node['device'], http_status=resp.status,
231
 
                http_reason=resp.reason)
 
226
            'Object server %s:%s direct HEAD %s gave status %s' %
 
227
            (node['ip'], node['port'],
 
228
             repr('/%s/%s%s' % (node['device'], part, path)),
 
229
             resp.status),
 
230
            http_host=node['ip'], http_port=node['port'],
 
231
            http_device=node['device'], http_status=resp.status,
 
232
            http_reason=resp.reason)
232
233
    resp_headers = {}
233
234
    for header, value in resp.getheaders():
234
235
        resp_headers[header.lower()] = value
255
256
    path = '/%s/%s/%s' % (account, container, obj)
256
257
    with Timeout(conn_timeout):
257
258
        conn = http_connect(node['ip'], node['port'], node['device'], part,
258
 
                'GET', path, headers=headers)
 
259
                            'GET', path, headers=headers)
259
260
    with Timeout(response_timeout):
260
261
        resp = conn.getresponse()
261
262
    if not is_success(resp.status):
262
263
        resp.read()
263
264
        raise ClientException(
264
 
                'Object server %s:%s direct GET %s gave status %s' %
265
 
                (node['ip'], node['port'],
266
 
                repr('/%s/%s%s' % (node['device'], part, path)),
267
 
                resp.status),
268
 
                http_host=node['ip'], http_port=node['port'],
269
 
                http_device=node['device'], http_status=resp.status,
270
 
                http_reason=resp.reason)
 
265
            'Object server %s:%s direct GET %s gave status %s' %
 
266
            (node['ip'], node['port'],
 
267
             repr('/%s/%s%s' % (node['device'], part, path)), resp.status),
 
268
            http_host=node['ip'], http_port=node['port'],
 
269
            http_device=node['device'], http_status=resp.status,
 
270
            http_reason=resp.reason)
271
271
    if resp_chunk_size:
272
272
 
273
273
        def _object_body():
325
325
    headers['X-Timestamp'] = normalize_timestamp(time())
326
326
    with Timeout(conn_timeout):
327
327
        conn = http_connect(node['ip'], node['port'], node['device'], part,
328
 
                'PUT', path, headers=headers)
 
328
                            'PUT', path, headers=headers)
329
329
    for chunk in contents:
330
330
        conn.send(chunk)
331
331
    with Timeout(response_timeout):
333
333
        resp.read()
334
334
    if not is_success(resp.status):
335
335
        raise ClientException(
336
 
                'Object server %s:%s direct PUT %s gave status %s' %
337
 
                (node['ip'], node['port'],
338
 
                repr('/%s/%s%s' % (node['device'], part, path)),
339
 
                resp.status),
340
 
                http_host=node['ip'], http_port=node['port'],
341
 
                http_device=node['device'], http_status=resp.status,
342
 
                http_reason=resp.reason)
 
336
            'Object server %s:%s direct PUT %s gave status %s' %
 
337
            (node['ip'], node['port'],
 
338
             repr('/%s/%s%s' % (node['device'], part, path)),
 
339
             resp.status),
 
340
            http_host=node['ip'], http_port=node['port'],
 
341
            http_device=node['device'], http_status=resp.status,
 
342
            http_reason=resp.reason)
343
343
    return resp.getheader('etag').strip('"')
344
344
 
345
345
 
362
362
    headers['X-Timestamp'] = normalize_timestamp(time())
363
363
    with Timeout(conn_timeout):
364
364
        conn = http_connect(node['ip'], node['port'], node['device'], part,
365
 
                'POST', path, headers=headers)
 
365
                            'POST', path, headers=headers)
366
366
    with Timeout(response_timeout):
367
367
        resp = conn.getresponse()
368
368
        resp.read()
369
369
    if not is_success(resp.status):
370
370
        raise ClientException(
371
 
                'Object server %s:%s direct POST %s gave status %s' %
372
 
                (node['ip'], node['port'],
373
 
                repr('/%s/%s%s' % (node['device'], part, path)),
374
 
                resp.status),
375
 
                http_host=node['ip'], http_port=node['port'],
376
 
                http_device=node['device'], http_status=resp.status,
377
 
                http_reason=resp.reason)
 
371
            'Object server %s:%s direct POST %s gave status %s' %
 
372
            (node['ip'], node['port'],
 
373
             repr('/%s/%s%s' % (node['device'], part, path)),
 
374
             resp.status),
 
375
            http_host=node['ip'], http_port=node['port'],
 
376
            http_device=node['device'], http_status=resp.status,
 
377
            http_reason=resp.reason)
378
378
 
379
379
 
380
380
def direct_delete_object(node, part, account, container, obj,
381
 
        conn_timeout=5, response_timeout=15, headers={}):
 
381
                         conn_timeout=5, response_timeout=15, headers={}):
382
382
    """
383
383
    Delete object directly from the object server.
384
384
 
395
395
    headers['X-Timestamp'] = normalize_timestamp(time())
396
396
    with Timeout(conn_timeout):
397
397
        conn = http_connect(node['ip'], node['port'], node['device'], part,
398
 
                'DELETE', path, headers)
 
398
                            'DELETE', path, headers)
399
399
    with Timeout(response_timeout):
400
400
        resp = conn.getresponse()
401
401
        resp.read()
402
402
    if not is_success(resp.status):
403
403
        raise ClientException(
404
 
                'Object server %s:%s direct DELETE %s gave status %s' %
405
 
                (node['ip'], node['port'],
406
 
                repr('/%s/%s%s' % (node['device'], part, path)),
407
 
                resp.status),
408
 
                http_host=node['ip'], http_port=node['port'],
409
 
                http_device=node['device'], http_status=resp.status,
410
 
                http_reason=resp.reason)
 
404
            'Object server %s:%s direct DELETE %s gave status %s' %
 
405
            (node['ip'], node['port'],
 
406
             repr('/%s/%s%s' % (node['device'], part, path)),
 
407
             resp.status),
 
408
            http_host=node['ip'], http_port=node['port'],
 
409
            http_device=node['device'], http_status=resp.status,
 
410
            http_reason=resp.reason)
411
411
 
412
412
 
413
413
def retry(func, *args, **kwargs):
453
453
    # Shouldn't actually get down here, but just in case.
454
454
    if args and 'ip' in args[0]:
455
455
        raise ClientException('Raise too many retries',
456
 
            http_host=args[0]['ip'], http_port=args[0]['port'],
457
 
            http_device=args[0]['device'])
 
456
                              http_host=args[
 
457
                              0]['ip'], http_port=args[0]['port'],
 
458
                              http_device=args[0]['device'])
458
459
    else:
459
460
        raise ClientException('Raise too many retries')