74
74
if not is_success(resp.status):
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)),
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
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)
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)),
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)),
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):
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)),
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)),
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()
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)),
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)
201
202
def direct_head_object(node, part, account, container, obj, conn_timeout=5,
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)),
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)),
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):
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)),
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:
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:
331
331
with Timeout(response_timeout):
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)),
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)),
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('"')
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()
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)),
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)),
375
http_host=node['ip'], http_port=node['port'],
376
http_device=node['device'], http_status=resp.status,
377
http_reason=resp.reason)
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={}):
383
383
Delete object directly from the object server.
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()
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)),
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)),
408
http_host=node['ip'], http_port=node['port'],
409
http_device=node['device'], http_status=resp.status,
410
http_reason=resp.reason)
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'])
457
0]['ip'], http_port=args[0]['port'],
458
http_device=args[0]['device'])
459
460
raise ClientException('Raise too many retries')