Skip to content

Instantly share code, notes, and snippets.

@alistairncoles
Last active August 29, 2015 14:04
Show Gist options
  • Save alistairncoles/a98c0c607ff4253a4967 to your computer and use it in GitHub Desktop.
Save alistairncoles/a98c0c607ff4253a4967 to your computer and use it in GitHub Desktop.
data migration get_object() method returning a reader
diff --git a/swift/common/data_migrator_drivers.py b/swift/common/data_migrator_drivers.py
index 128d8b0..f004573 100644
--- a/swift/common/data_migrator_drivers.py
+++ b/swift/common/data_migrator_drivers.py
@@ -16,10 +16,12 @@ import os
import stat
import mimetypes
from xattr import xattr
+from swift.common.request_helpers import is_user_meta
SWIFTCLIENT_IMPORTED = False
try:
- from swiftclient import client
+ from swiftclient import client, http_connection, quote
+
SWIFTCLIENT_IMPORTED = True
except ImportError:
pass
@@ -152,16 +154,25 @@ class SwiftAccessDriver(object):
if SWIFTCLIENT_IMPORTED:
storage_url, token = client.get_auth(self.token_url,
self.user, self.key)
- resp_headers = client.head_object(storage_url, token,
- self.data_source, object_name)
- data = self.ReadWrapper(storage_url, token, self.data_source,
- object_name)
+
+ parsed, conn = http_connection(storage_url)
+ path = '%s/%s/%s' % (parsed.path, quote(self.data_source),
+ quote(object_name))
+ conn.request('GET', path, '', {'X-Auth-Token': token})
+ resp = conn.getresponse()
+ if resp.status < 200 or resp.status >= 300:
+ body = resp.read()
+ raise Exception('Object GET failed: %s' % body)
+
+ resp_headers = dict()
metadata = dict()
- for key, val in resp_headers.iteritems():
- if key.startswith('x-object-meta'):
- metadata[key] = val
+ for key, value in resp.getheaders():
+ key = key.lower()
+ resp_headers[key] = value
+ if is_user_meta('object', key):
+ metadata[key] = value
return metadata, resp_headers.get('content-length'),\
- data, resp_headers.get('content-type'), \
+ resp, resp_headers.get('content-type'), \
resp_headers.get('x-timestamp')
return {}, None, None, None, None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment