Revision 71c0f614 tools/storefs.py
b/tools/storefs.py | ||
---|---|---|
42 | 42 |
from time import time |
43 | 43 |
|
44 | 44 |
from pithos.api.compat import parse_http_date |
45 |
from pithos.lib.client import Client, Fault |
|
45 |
from pithos.lib.client import OOS_Client, Fault
|
|
46 | 46 |
from pithos.lib.fuse import FUSE, FuseOSError, Operations |
47 | 47 |
|
48 | 48 |
DEFAULT_HOST = 'pithos.dev.grnet.gr' |
49 |
DEFAULT_API = 'v1' |
|
50 | 49 |
|
51 | 50 |
|
52 | 51 |
epoch = int(time()) |
53 | 52 |
|
54 | 53 |
|
55 | 54 |
class StoreFS(Operations): |
56 |
def __init__(self, user, verbose=False): |
|
55 |
def __init__(self, user, token, verbose=False):
|
|
57 | 56 |
self.verbose = verbose |
58 |
self.client = Client(DEFAULT_HOST, user, DEFAULT_API)
|
|
57 |
self.client = OOS_Client(DEFAULT_HOST, token, user)
|
|
59 | 58 |
|
60 | 59 |
def __call__(self, op, path, *args): |
61 | 60 |
container, sep, object = path[1:].partition('/') |
... | ... | |
66 | 65 |
|
67 | 66 |
try: |
68 | 67 |
if object: |
69 |
ret = getattr(self, 'object_' + op)(container, object, *args) |
|
68 |
func = getattr(self, 'object_' + op, None) |
|
69 |
funcargs = (container, object) + args |
|
70 | 70 |
elif container: |
71 |
ret = getattr(self, 'container_' + op)(container, *args) |
|
71 |
func = getattr(self, 'container_' + op, None) |
|
72 |
funcargs = (container,) + args |
|
72 | 73 |
else: |
73 |
ret = getattr(self, 'account_' + op)(*args) |
|
74 |
return ret |
|
75 |
except AttributeError: |
|
76 |
ret = getattr(self, op)(path, *args) |
|
74 |
func = getattr(self, 'account_' + op, None) |
|
75 |
funcargs = args |
|
76 |
|
|
77 |
if not func: |
|
78 |
# Fallback to defaults |
|
79 |
func = getattr(self, op) |
|
80 |
funcargs = (path,) + args |
|
81 |
|
|
82 |
ret = func(*funcargs) |
|
77 | 83 |
return ret |
78 | 84 |
except FuseOSError, e: |
79 | 85 |
ret = str(e) |
... | ... | |
107 | 113 |
# Account Level |
108 | 114 |
|
109 | 115 |
def account_chmod(self, mode): |
110 |
self.client.update_account_metadata(mode=mode)
|
|
116 |
self.client.update_account_metadata(mode=str(mode))
|
|
111 | 117 |
|
112 | 118 |
def account_chown(self, uid, gid): |
113 | 119 |
self.client.update_account_metadata(uid=uid, gid=gid) |
114 | 120 |
|
115 | 121 |
def account_getattr(self, fh=None): |
116 |
meta = self.client.account_metadata() |
|
122 |
meta = self.client.retrieve_account_metadata()
|
|
117 | 123 |
mode = int(meta.get('x-account-meta-mode', 0755)) |
118 |
modified = parse_http_date(meta['last-modified']) |
|
124 |
last_modified = meta.get('last-modified', None) |
|
125 |
modified = parse_http_date(last_modified) if last_modified else epoch |
|
119 | 126 |
count = int(meta['x-account-container-count']) |
120 | 127 |
uid = int(meta.get('x-account-meta-uid', 0)) |
121 | 128 |
gid = int(meta.get('x-account-meta-gid', 0)) |
... | ... | |
154 | 161 |
# Container Level |
155 | 162 |
|
156 | 163 |
def container_chmod(self, container, mode): |
157 |
self.client.update_container_metadata(container, mode=mode)
|
|
164 |
self.client.update_container_metadata(container, mode=str(mode))
|
|
158 | 165 |
|
159 | 166 |
def container_chown(self, container, uid, gid): |
160 | 167 |
self.client.update_container_metadata(container, uid=uid, gid=gid) |
... | ... | |
186 | 193 |
return [k[len(prefix):] for k in meta if k.startswith(prefix)] |
187 | 194 |
|
188 | 195 |
def container_mkdir(self, container, mode): |
189 |
self.client.create_container(container)
|
|
190 |
self.client.update_container_metadata(container, mode=mode)
|
|
196 |
mode = str(mode & 0777)
|
|
197 |
self.client.create_container(container, mode=mode)
|
|
191 | 198 |
|
192 | 199 |
def container_readdir(self, container, fh): |
193 | 200 |
params = {'delimiter': '/', 'prefix': ''} |
... | ... | |
221 | 228 |
# Object Level |
222 | 229 |
|
223 | 230 |
def object_chmod(self, container, object, mode): |
224 |
self.client.update_object_metadata(container, object, mode=mode)
|
|
231 |
self.client.update_object_metadata(container, object, mode=str(mode))
|
|
225 | 232 |
|
226 | 233 |
def object_chown(self, container, uid, gid): |
227 |
self.client.update_object_metadata(container, object, uid=uid, gid=gid) |
|
234 |
self.client.update_object_metadata(container, object, |
|
235 |
uid=str(uid), gid=str(gid)) |
|
228 | 236 |
|
229 | 237 |
def object_create(self, container, object, mode, fi=None): |
230 | 238 |
mode &= 0777 |
231 |
headers = {'Content-Type': 'application/octet-stream'} |
|
232 |
self.client.create_object(container, object, f=None, headers=headers) |
|
233 |
self.client.update_object_metadata(container, object, mode=mode) |
|
239 |
self.client.create_object(container, object, |
|
240 |
f=None, |
|
241 |
content_type='application/octet-stream', |
|
242 |
mode=str(mode)) |
|
234 | 243 |
return 0 |
235 | 244 |
|
236 | 245 |
def object_getattr(self, container, object, fh=None): |
... | ... | |
268 | 277 |
return [k[len(prefix):] for k in meta if k.startswith(prefix)] |
269 | 278 |
|
270 | 279 |
def object_mkdir(self, container, object, mode): |
280 |
mode = str(mode & 0777) |
|
271 | 281 |
self.client.create_directory_marker(container, object) |
272 | 282 |
self.client.update_object_metadata(container, object, mode=mode) |
273 | 283 |
|
... | ... | |
310 | 320 |
|
311 | 321 |
def object_write(self, container, object, data, offset, fh): |
312 | 322 |
f = StringIO(data) |
313 |
headers = {} |
|
314 |
if offset: |
|
315 |
headers['CONTENT_RANGE'] = 'bytes %d-/*' % offset |
|
316 |
else: |
|
317 |
headers['CONTENT_RANGE'] = 'bytes */*' |
|
318 |
|
|
319 |
self.client.update_object(container, object, f, headers=headers) |
|
323 |
self.client.update_object(container, object, f, offset=offset) |
|
320 | 324 |
return len(data) |
321 | 325 |
|
322 | 326 |
|
323 | 327 |
if __name__ == "__main__": |
324 |
if len(argv) != 2:
|
|
325 |
print 'usage: %s <mountpoint>' % argv[0] |
|
328 |
if len(argv) != 4:
|
|
329 |
print 'usage: %s <user> <token> <mountpoint>' % argv[0]
|
|
326 | 330 |
exit(1) |
327 | 331 |
|
328 | 332 |
user = getuser() |
329 |
fs = StoreFS(user, verbose=True) |
|
330 |
fuse = FUSE(fs, argv[1], foreground=True) |
|
333 |
fs = StoreFS(argv[1], argv[2], verbose=True) |
|
334 |
fuse = FUSE(fs, argv[3], foreground=True) |
Also available in: Unified diff