Statistics
| Branch: | Tag: | Revision:

root / pithos / backends / base.py @ e9363f82

History | View | Annotate | Download (18.2 kB)

1
# Copyright 2011 GRNET S.A. All rights reserved.
2
# 
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
# 
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
# 
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
# 
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
# 
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

    
34
class NotAllowedError(Exception):
35
    pass
36

    
37
class QuotaError(Exception):
38
    pass
39

    
40
class BaseBackend(object):
41
    """Abstract backend class that serves as a reference for actual implementations.
42
    
43
    The purpose of the backend is to provide the necessary functions for handling data
44
    and metadata. It is responsible for the actual storage and retrieval of information.
45
    
46
    Note that the account level is always valid as it is checked from another subsystem.
47
    
48
    When not replacing metadata/groups/policy, keys with empty values should be deleted.
49
    
50
    The following variables should be available:
51
        'hash_algorithm': Suggested is 'sha256'
52
        
53
        'block_size': Suggested is 4MB
54
        
55
        'default_policy': A dictionary with default policy settings
56
    """
57
    
58
    def __init__(self, db_module, db_connection, block_module, block_path):
59
        """Initialize backend with supplied modules and options."""
60
        pass
61
    
62
    def close(self):
63
        """Close the backend connection."""
64
        pass
65
    
66
    def list_accounts(self, user, marker=None, limit=10000):
67
        """Return a list of accounts the user can access.
68
        
69
        Parameters:
70
            'marker': Start list from the next item after 'marker'
71
            
72
            'limit': Number of containers to return
73
        """
74
        return []
75
    
76
    def get_account_meta(self, user, account, until=None):
77
        """Return a dictionary with the account metadata.
78
        
79
        The keys returned are all user-defined, except:
80
            'name': The account name
81
            
82
            'count': The number of containers (or 0)
83
            
84
            'bytes': The total data size (or 0)
85
            
86
            'modified': Last modification timestamp (overall)
87
            
88
            'until_timestamp': Last modification until the timestamp provided
89
        
90
        Raises:
91
            NotAllowedError: Operation not permitted
92
        """
93
        return {}
94
    
95
    def update_account_meta(self, user, account, meta, replace=False):
96
        """Update the metadata associated with the account.
97
        
98
        Parameters:
99
            'meta': Dictionary with metadata to update
100
            
101
            'replace': Replace instead of update
102
        
103
        Raises:
104
            NotAllowedError: Operation not permitted
105
        """
106
        return
107
    
108
    def get_account_groups(self, user, account):
109
        """Return a dictionary with the user groups defined for this account.
110
        
111
        Raises:
112
            NotAllowedError: Operation not permitted
113
        """
114
        return {}
115
    
116
    def update_account_groups(self, user, account, groups, replace=False):
117
        """Update the groups associated with the account.
118
        
119
        Raises:
120
            NotAllowedError: Operation not permitted
121
            
122
            ValueError: Invalid data in groups
123
        """
124
        return
125
    
126
    def get_account_policy(self, user, account):
127
        """Return a dictionary with the account policy.
128
        
129
        The keys returned are:
130
            'quota': The maximum bytes allowed (default is 0 - unlimited)
131
            
132
            'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
133
        
134
        Raises:
135
            NotAllowedError: Operation not permitted
136
        """
137
        return {}
138
    
139
    def update_account_policy(self, user, account, policy, replace=False):
140
        """Update the policy associated with the account.
141
        
142
        Raises:
143
            NotAllowedError: Operation not permitted
144
            
145
            ValueError: Invalid policy defined
146
        """
147
        return
148
    
149
    def put_account(self, user, account, policy={}):
150
        """Create a new account with the given name.
151
        
152
        Raises:
153
            NotAllowedError: Operation not permitted
154
            
155
            ValueError: Invalid policy defined
156
        """
157
        return
158
    
159
    def delete_account(self, user, account):
160
        """Delete the account with the given name.
161
        
162
        Raises:
163
            NotAllowedError: Operation not permitted
164
            
165
            IndexError: Account is not empty
166
        """
167
        return
168
    
169
    def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None):
170
        """Return a list of container names existing under an account.
171
        
172
        Parameters:
173
            'marker': Start list from the next item after 'marker'
174
            
175
            'limit': Number of containers to return
176
            
177
            'shared': Only list containers with permissions set
178
            
179
        
180
        Raises:
181
            NotAllowedError: Operation not permitted
182
        """
183
        return []
184
    
185
    def get_container_meta(self, user, account, container, until=None):
186
        """Return a dictionary with the container metadata.
187
        
188
        The keys returned are all user-defined, except:
189
            'name': The container name
190
            
191
            'count': The number of objects
192
            
193
            'bytes': The total data size
194
            
195
            'modified': Last modification timestamp (overall)
196
            
197
            'until_timestamp': Last modification until the timestamp provided
198
        
199
        Raises:
200
            NotAllowedError: Operation not permitted
201
            
202
            NameError: Container does not exist
203
        """
204
        return {}
205
    
206
    def update_container_meta(self, user, account, container, meta, replace=False):
207
        """Update the metadata associated with the container.
208
        
209
        Parameters:
210
            'meta': Dictionary with metadata to update
211
            
212
            'replace': Replace instead of update
213
        
214
        Raises:
215
            NotAllowedError: Operation not permitted
216
            
217
            NameError: Container does not exist
218
        """
219
        return
220
    
221
    def get_container_policy(self, user, account, container):
222
        """Return a dictionary with the container policy.
223
        
224
        The keys returned are:
225
            'quota': The maximum bytes allowed (default is 0 - unlimited)
226
            
227
            'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
228
        
229
        Raises:
230
            NotAllowedError: Operation not permitted
231
            
232
            NameError: Container does not exist
233
        """
234
        return {}
235
    
236
    def update_container_policy(self, user, account, container, policy, replace=False):
237
        """Update the policy associated with the container.
238
        
239
        Raises:
240
            NotAllowedError: Operation not permitted
241
            
242
            NameError: Container does not exist
243
            
244
            ValueError: Invalid policy defined
245
        """
246
        return
247
    
248
    def put_container(self, user, account, container, policy={}):
249
        """Create a new container with the given name.
250
        
251
        Raises:
252
            NotAllowedError: Operation not permitted
253
            
254
            NameError: Container already exists
255
            
256
            ValueError: Invalid policy defined
257
        """
258
        return
259
    
260
    def delete_container(self, user, account, container, until=None):
261
        """Delete/purge the container with the given name.
262
        
263
        Raises:
264
            NotAllowedError: Operation not permitted
265
            
266
            NameError: Container does not exist
267
            
268
            IndexError: Container is not empty
269
        """
270
        return
271
    
272
    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], shared=False, until=None):
273
        """Return a list of object (name, version_id) tuples existing under a container.
274
        
275
        Parameters:
276
            'prefix': List objects starting with 'prefix'
277
            
278
            'delimiter': Return unique names before 'delimiter' and after 'prefix'
279
            
280
            'marker': Start list from the next item after 'marker'
281
            
282
            'limit': Number of objects to return
283
            
284
            'virtual': If not set, the result will only include names starting
285
                       with 'prefix' and ending without a 'delimiter' or with
286
                       the first occurance of the 'delimiter' after 'prefix'.
287
                       If set, the result will include all names after 'prefix',
288
                       up to and including the 'delimiter' if it is found
289
            
290
            'keys': Include objects that have meta with the keys in the list
291
            
292
            'shared': Only list objects with permissions set
293
        
294
        Raises:
295
            NotAllowedError: Operation not permitted
296
            
297
            NameError: Container does not exist
298
        """
299
        return []
300
    
301
    def list_public(self, user, account, container):
302
        """Return a list of object (name, version_id) tuples existing under a container and are public.
303
        
304
        Raises:
305
            NotAllowedError: Operation not permitted
306
            
307
            NameError: Container does not exist
308
        """
309
        return []
310
    
311
    def list_object_meta(self, user, account, container, until=None):
312
        """Return a list with all the container's object meta keys.
313
        
314
        Raises:
315
            NotAllowedError: Operation not permitted
316
            
317
            NameError: Container does not exist
318
        """
319
        return []
320
    
321
    def get_object_meta(self, user, account, container, name, version=None):
322
        """Return a dictionary with the object metadata.
323
        
324
        The keys returned are all user-defined, except:
325
            'name': The object name
326
            
327
            'bytes': The total data size
328
            
329
            'modified': Last modification timestamp (overall)
330
            
331
            'modified_by': The user that committed the object (version requested)
332
            
333
            'version': The version identifier
334
            
335
            'version_timestamp': The version's modification timestamp
336
        
337
        Raises:
338
            NotAllowedError: Operation not permitted
339
            
340
            NameError: Container/object does not exist
341
            
342
            IndexError: Version does not exist
343
        """
344
        return {}
345
    
346
    def update_object_meta(self, user, account, container, name, meta, replace=False):
347
        """Update the metadata associated with the object and return the new version.
348
        
349
        Parameters:
350
            'meta': Dictionary with metadata to update
351
            
352
            'replace': Replace instead of update
353
        
354
        Raises:
355
            NotAllowedError: Operation not permitted
356
            
357
            NameError: Container/object does not exist
358
        """
359
        return ''
360
    
361
    def get_object_permissions(self, user, account, container, name):
362
        """Return the action allowed on the object, the path
363
        from which the object gets its permissions from,
364
        along with a dictionary containing the permissions.
365
        
366
        The dictionary keys are (also used for defining the action):
367
            'read': The object is readable by the users/groups in the list
368
            
369
            'write': The object is writable by the users/groups in the list
370
        
371
        Raises:
372
            NotAllowedError: Operation not permitted
373
            
374
            NameError: Container/object does not exist
375
        """
376
        return {}
377
    
378
    def update_object_permissions(self, user, account, container, name, permissions):
379
        """Update the permissions associated with the object.
380
        
381
        Parameters:
382
            'permissions': Dictionary with permissions to update
383
        
384
        Raises:
385
            NotAllowedError: Operation not permitted
386
            
387
            NameError: Container/object does not exist
388
            
389
            ValueError: Invalid users/groups in permissions
390
            
391
            AttributeError: Can not set permissions, as this object
392
                is already shared/private by another object higher
393
                in the hierarchy, or setting permissions here will
394
                invalidate other permissions deeper in the hierarchy
395
        """
396
        return
397
    
398
    def get_object_public(self, user, account, container, name):
399
        """Return the public URL of the object if applicable.
400
        
401
        Raises:
402
            NotAllowedError: Operation not permitted
403
            
404
            NameError: Container/object does not exist
405
        """
406
        return None
407
    
408
    def update_object_public(self, user, account, container, name, public):
409
        """Update the public status of the object.
410
        
411
        Parameters:
412
            'public': Boolean value
413
        
414
        Raises:
415
            NotAllowedError: Operation not permitted
416
            
417
            NameError: Container/object does not exist
418
        """
419
        return
420
    
421
    def get_object_hashmap(self, user, account, container, name, version=None):
422
        """Return the object's size and a list with partial hashes.
423
        
424
        Raises:
425
            NotAllowedError: Operation not permitted
426
            
427
            NameError: Container/object does not exist
428
            
429
            IndexError: Version does not exist
430
        """
431
        return 0, []
432
    
433
    def update_object_hashmap(self, user, account, container, name, size, hashmap, meta={}, replace_meta=False, permissions=None):
434
        """Create/update an object with the specified size and partial hashes and return the new version.
435
        
436
        Parameters:
437
            'dest_meta': Dictionary with metadata to change
438
            
439
            'replace_meta': Replace metadata instead of update
440
            
441
            'permissions': Updated object permissions
442
        
443
        Raises:
444
            NotAllowedError: Operation not permitted
445
            
446
            NameError: Container does not exist
447
            
448
            ValueError: Invalid users/groups in permissions
449
            
450
            AttributeError: Can not set permissions
451
            
452
            QuotaError: Account or container quota exceeded
453
        """
454
        return ''
455
    
456
    def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None, src_version=None):
457
        """Copy an object's data and metadata and return the new version.
458
        
459
        Parameters:
460
            'dest_meta': Dictionary with metadata to change from source to destination
461
            
462
            'replace_meta': Replace metadata instead of update
463
            
464
            'permissions': New object permissions
465
            
466
            'src_version': Copy from the version provided
467
        
468
        Raises:
469
            NotAllowedError: Operation not permitted
470
            
471
            NameError: Container/object does not exist
472
            
473
            IndexError: Version does not exist
474
            
475
            ValueError: Invalid users/groups in permissions
476
            
477
            AttributeError: Can not set permissions
478
            
479
            QuotaError: Account or container quota exceeded
480
        """
481
        return ''
482
    
483
    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None):
484
        """Move an object's data and metadata and return the new version.
485
        
486
        Parameters:
487
            'dest_meta': Dictionary with metadata to change from source to destination
488
            
489
            'replace_meta': Replace metadata instead of update
490
            
491
            'permissions': New object permissions
492
        
493
        Raises:
494
            NotAllowedError: Operation not permitted
495
            
496
            NameError: Container/object does not exist
497
            
498
            ValueError: Invalid users/groups in permissions
499
            
500
            AttributeError: Can not set permissions
501
            
502
            QuotaError: Account or container quota exceeded
503
        """
504
        return ''
505
    
506
    def delete_object(self, user, account, container, name, until=None):
507
        """Delete/purge an object.
508
        
509
        Raises:
510
            NotAllowedError: Operation not permitted
511
            
512
            NameError: Container/object does not exist
513
        """
514
        return
515
    
516
    def list_versions(self, user, account, container, name):
517
        """Return a list of all (version, version_timestamp) tuples for an object.
518
        
519
        Raises:
520
            NotAllowedError: Operation not permitted
521
        """
522
        return []
523
    
524
    def get_block(self, hash):
525
        """Return a block's data.
526
        
527
        Raises:
528
            NameError: Block does not exist
529
        """
530
        return ''
531
    
532
    def put_block(self, data):
533
        """Store a block and return the hash."""
534
        return 0
535
    
536
    def update_block(self, hash, data, offset=0):
537
        """Update a known block and return the hash.
538
        
539
        Raises:
540
            IndexError: Offset or data outside block limits
541
        """
542
        return 0