Statistics
| Branch: | Tag: | Revision:

root / pithos / backends / base.py @ a9b3f29d

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