Statistics
| Branch: | Tag: | Revision:

root / pithos / backends / base.py @ f77b150f

History | View | Annotate | Download (15.6 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 BaseBackend(object):
38
    """Abstract backend class that serves as a reference for actual implementations.
39
    
40
    The purpose of the backend is to provide the necessary functions for handling data
41
    and metadata. It is responsible for the actual storage and retrieval of information.
42
    
43
    Note that the account level is always valid as it is checked from another subsystem.
44
    
45
    When not replacing metadata/groups/policy, keys with empty values should be deleted.
46
    
47
    The following variables should be available:
48
        'hash_algorithm': Suggested is 'sha256'
49
        'block_size': Suggested is 4MB
50
    """
51
    
52
    def get_account_meta(self, user, account, until=None):
53
        """Return a dictionary with the account metadata.
54
        
55
        The keys returned are all user-defined, except:
56
            'name': The account name
57
            'count': The number of containers (or 0)
58
            'bytes': The total data size (or 0)
59
            'modified': Last modification timestamp (overall)
60
            'until_timestamp': Last modification until the timestamp provided
61
        
62
        Raises:
63
            NotAllowedError: Operation not permitted
64
        """
65
        return {}
66
    
67
    def update_account_meta(self, user, account, meta, replace=False):
68
        """Update the metadata associated with the account.
69
        
70
        Parameters:
71
            'meta': Dictionary with metadata to update
72
            'replace': Replace instead of update
73
        
74
        Raises:
75
            NotAllowedError: Operation not permitted
76
        """
77
        return
78
    
79
    def get_account_groups(self, user, account):
80
        """Return a dictionary with the user groups defined for this account.
81
        
82
        Raises:
83
            NotAllowedError: Operation not permitted
84
        """
85
        return {}
86
    
87
    def update_account_groups(self, user, account, groups, replace=False):
88
        """Update the groups associated with the account.
89
        
90
        Raises:
91
            NotAllowedError: Operation not permitted
92
            ValueError: Invalid data in groups
93
        """
94
        return
95
    
96
    def put_account(self, user, account):
97
        """Create a new account with the given name.
98
        
99
        Raises:
100
            NotAllowedError: Operation not permitted
101
            NameError: Account already exists
102
        """
103
        return
104
    
105
    def delete_account(self, user, account):
106
        """Delete the account with the given name.
107
        
108
        Raises:
109
            NotAllowedError: Operation not permitted
110
            IndexError: Account is not empty
111
        """
112
        return
113
    
114
    def list_containers(self, user, account, marker=None, limit=10000, until=None):
115
        """Return a list of container (name, version_id) tuples existing under an account.
116
        
117
        Parameters:
118
            'marker': Start list from the next item after 'marker'
119
            'limit': Number of containers to return
120
        
121
        Raises:
122
            NotAllowedError: Operation not permitted
123
        """
124
        return []
125
    
126
    def get_container_meta(self, user, account, container, until=None):
127
        """Return a dictionary with the container metadata.
128
        
129
        The keys returned are all user-defined, except:
130
            'name': The container name
131
            'count': The number of objects
132
            'bytes': The total data size
133
            'modified': Last modification timestamp (overall)
134
            'until_timestamp': Last modification until the timestamp provided
135
        
136
        Raises:
137
            NotAllowedError: Operation not permitted
138
            NameError: Container does not exist
139
        """
140
        return {}
141
    
142
    def update_container_meta(self, user, account, container, meta, replace=False):
143
        """Update the metadata associated with the container.
144
        
145
        Parameters:
146
            'meta': Dictionary with metadata to update
147
            'replace': Replace instead of update
148
        
149
        Raises:
150
            NotAllowedError: Operation not permitted
151
            NameError: Container does not exist
152
        """
153
        return
154
    
155
    def get_container_policy(self, user, account, container):
156
        """Return a dictionary with the container policy.
157
        
158
        The keys returned are:
159
            'quota': The maximum bytes allowed (default is 0 - unlimited)
160
            'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
161
        
162
        Raises:
163
            NotAllowedError: Operation not permitted
164
            NameError: Container does not exist
165
        """
166
        return {}
167
    
168
    def update_container_policy(self, user, account, container, policy, replace=False):
169
        """Update the policy associated with the account.
170
        
171
        Raises:
172
            NotAllowedError: Operation not permitted
173
            NameError: Container does not exist
174
            ValueError: Invalid policy defined
175
        """
176
        return
177
    
178
    def put_container(self, user, account, container, policy=None):
179
        """Create a new container with the given name.
180
        
181
        Raises:
182
            NotAllowedError: Operation not permitted
183
            NameError: Container already exists
184
            ValueError: Invalid policy defined
185
        """
186
        return
187
    
188
    def delete_container(self, user, account, container, until=None):
189
        """Delete the container with the given name.
190
        
191
        Raises:
192
            NotAllowedError: Operation not permitted
193
            NameError: Container does not exist
194
            IndexError: Container is not empty
195
        """
196
        return
197
    
198
    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], trash=False, until=None):
199
        """Return a list of object (name, version_id) tuples existing under a container.
200
        
201
        Parameters:
202
            'prefix': List objects starting with 'prefix'
203
            'delimiter': Return unique names before 'delimiter' and after 'prefix'
204
            'marker': Start list from the next item after 'marker'
205
            'limit': Number of objects to return
206
            'virtual': If not set, the result will only include names starting\
207
                       with 'prefix' and ending without a 'delimiter' or with\
208
                       the first occurance of the 'delimiter' after 'prefix'.\
209
                       If set, the result will include all names after 'prefix',\
210
                       up to and including the 'delimiter' if it is found
211
            'keys': Include objects that have meta with the keys in the list
212
            'trash': List objects in trash
213
        
214
        Raises:
215
            NotAllowedError: Operation not permitted
216
            NameError: Container does not exist
217
        """
218
        return []
219
    
220
    def list_object_meta(self, user, account, container, trash=False, until=None):
221
        """Return a list with all the container's object meta keys.
222
        
223
        Raises:
224
            NotAllowedError: Operation not permitted
225
            NameError: Container does not exist
226
        """
227
        return []
228
    
229
    def get_object_meta(self, user, account, container, name, version=None):
230
        """Return a dictionary with the object metadata.
231
        
232
        The keys returned are all user-defined, except:
233
            'name': The object name
234
            'bytes': The total data size
235
            'modified': Last modification timestamp (overall)
236
            'modified_by': The user that committed the object (version requested)
237
            'version': The version identifier
238
            'version_timestamp': The version's modification timestamp
239
        
240
        Raises:
241
            NotAllowedError: Operation not permitted
242
            NameError: Container/object does not exist
243
            IndexError: Version does not exist
244
        """
245
        return {}
246
    
247
    def update_object_meta(self, user, account, container, name, meta, replace=False):
248
        """Update the metadata associated with the object.
249
        
250
        Parameters:
251
            'meta': Dictionary with metadata to update
252
            'replace': Replace instead of update
253
        
254
        Raises:
255
            NotAllowedError: Operation not permitted
256
            NameError: Container/object does not exist
257
        """
258
        return
259
    
260
    def get_object_permissions(self, user, account, container, name):
261
        """Return the path from which this object gets its permissions from,\
262
        along with a dictionary containing the permissions.
263
        
264
        The keys are:
265
            'read': The object is readable by the users/groups in the list
266
            'write': The object is writable by the users/groups in the list
267
        
268
        Raises:
269
            NotAllowedError: Operation not permitted
270
            NameError: Container/object does not exist
271
        """
272
        return {}
273
    
274
    def update_object_permissions(self, user, account, container, name, permissions):
275
        """Update the permissions associated with the object.
276
        
277
        Parameters:
278
            'permissions': Dictionary with permissions to update
279
        
280
        Raises:
281
            NotAllowedError: Operation not permitted
282
            NameError: Container/object does not exist
283
            ValueError: Invalid users/groups in permissions
284
            AttributeError: Can not set permissions, as this object\
285
                is already shared/private by another object higher\
286
                in the hierarchy, or setting permissions here will\
287
                invalidate other permissions deeper in the hierarchy
288
        """
289
        return
290
    
291
    def get_object_public(self, user, account, container, name):
292
        """Return the public URL of the object if applicable.
293
        
294
        Raises:
295
            NotAllowedError: Operation not permitted
296
            NameError: Container/object does not exist
297
        """
298
        return None
299
    
300
    def update_object_public(self, user, account, container, name, public):
301
        """Update the public status of the object.
302
        
303
        Parameters:
304
            'public': Boolean value
305
        
306
        Raises:
307
            NotAllowedError: Operation not permitted
308
            NameError: Container/object does not exist
309
        """
310
        return
311
    
312
    def get_object_hashmap(self, user, account, container, name, version=None):
313
        """Return the object's size and a list with partial hashes.
314
        
315
        Raises:
316
            NotAllowedError: Operation not permitted
317
            NameError: Container/object does not exist
318
            IndexError: Version does not exist
319
        """
320
        return 0, []
321
    
322
    def update_object_hashmap(self, user, account, container, name, size, hashmap, meta={}, replace_meta=False, permissions=None):
323
        """Create/update an object with the specified size and partial hashes.
324
        
325
        Parameters:
326
            'dest_meta': Dictionary with metadata to change
327
            'replace_meta': Replace metadata instead of update
328
            'permissions': Updated object permissions
329
        
330
        Raises:
331
            NotAllowedError: Operation not permitted
332
            NameError: Container does not exist
333
            ValueError: Invalid users/groups in permissions
334
            AttributeError: Can not set permissions
335
        """
336
        return
337
    
338
    def copy_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None, src_version=None):
339
        """Copy an object's data and metadata.
340
        
341
        Parameters:
342
            'dest_meta': Dictionary with metadata to change from source to destination
343
            'replace_meta': Replace metadata instead of update
344
            'permissions': New object permissions
345
            'src_version': Copy from the version provided
346
        
347
        Raises:
348
            NotAllowedError: Operation not permitted
349
            NameError: Container/object does not exist
350
            IndexError: Version does not exist
351
            ValueError: Invalid users/groups in permissions
352
            AttributeError: Can not set permissions
353
        """
354
        return
355
    
356
    def move_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None):
357
        """Move an object's data and metadata.
358
        
359
        Parameters:
360
            'dest_meta': Dictionary with metadata to change from source to destination
361
            'replace_meta': Replace metadata instead of update
362
            'permissions': New object permissions
363
        
364
        Raises:
365
            NotAllowedError: Operation not permitted
366
            NameError: Container/object does not exist
367
            ValueError: Invalid users/groups in permissions
368
            AttributeError: Can not set permissions
369
        """
370
        return
371
    
372
    def delete_object(self, user, account, container, name, until=None):
373
        """Delete an object.
374
        
375
        Raises:
376
            NotAllowedError: Operation not permitted
377
            NameError: Container/object does not exist
378
        """
379
        return
380
    
381
    def trash_object(self, user, account, container, name):
382
        """Trash an object.
383
        
384
        Raises:
385
            NotAllowedError: Operation not permitted
386
            NameError: Container/object does not exist
387
        """
388
        return
389
    
390
    def untrash_object(self, user, account, container, name):
391
        """Untrash an object.
392
        
393
        Raises:
394
            NotAllowedError: Operation not permitted
395
            NameError: Object not in trash
396
        """
397
        return
398
    
399
    def list_versions(self, user, account, container, name):
400
        """Return a list of all (version, version_timestamp) tuples for an object.
401
        
402
        Raises:
403
            NotAllowedError: Operation not permitted
404
        """
405
        return []
406
    
407
    def get_block(self, hash):
408
        """Return a block's data.
409
        
410
        Raises:
411
            NameError: Block does not exist
412
        """
413
        return ''
414
    
415
    def put_block(self, data):
416
        """Store a block and return the hash."""
417
        return 0
418
    
419
    def update_block(self, hash, data, offset=0):
420
        """Update a known block and return the hash.
421
        
422
        Raises:
423
            IndexError: Offset or data outside block limits
424
        """
425
        return 0