1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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.
34 # Default setting for new accounts.
35 DEFAULT_QUOTA = 0 # No quota.
36 DEFAULT_VERSIONING = 'auto'
39 class NotAllowedError(Exception):
42 class QuotaError(Exception):
45 class BaseBackend(object):
46 """Abstract backend class that serves as a reference for actual implementations.
48 The purpose of the backend is to provide the necessary functions for handling data
49 and metadata. It is responsible for the actual storage and retrieval of information.
51 Note that the account level is always valid as it is checked from another subsystem.
53 When not replacing metadata/groups/policy, keys with empty values should be deleted.
55 The following variables should be available:
56 'hash_algorithm': Suggested is 'sha256'
58 'block_size': Suggested is 4MB
60 'default_policy': A dictionary with default policy settings
64 """Close the backend connection."""
67 def list_accounts(self, user, marker=None, limit=10000):
68 """Return a list of accounts the user can access.
71 'marker': Start list from the next item after 'marker'
73 'limit': Number of containers to return
77 def get_account_meta(self, user, account, domain, until=None):
78 """Return a dictionary with the account metadata for the domain.
80 The keys returned are all user-defined, except:
81 'name': The account name
83 'count': The number of containers (or 0)
85 'bytes': The total data size (or 0)
87 'modified': Last modification timestamp (overall)
89 'until_timestamp': Last modification until the timestamp provided
92 NotAllowedError: Operation not permitted
96 def update_account_meta(self, user, account, domain, meta, replace=False):
97 """Update the metadata associated with the account for the domain.
100 'domain': Metadata domain
102 'meta': Dictionary with metadata to update
104 'replace': Replace instead of update
107 NotAllowedError: Operation not permitted
111 def get_account_groups(self, user, account):
112 """Return a dictionary with the user groups defined for this account.
115 NotAllowedError: Operation not permitted
119 def update_account_groups(self, user, account, groups, replace=False):
120 """Update the groups associated with the account.
123 NotAllowedError: Operation not permitted
125 ValueError: Invalid data in groups
129 def get_account_policy(self, user, account):
130 """Return a dictionary with the account policy.
132 The keys returned are:
133 'quota': The maximum bytes allowed (default is 0 - unlimited)
135 'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
138 NotAllowedError: Operation not permitted
142 def update_account_policy(self, user, account, policy, replace=False):
143 """Update the policy associated with the account.
146 NotAllowedError: Operation not permitted
148 ValueError: Invalid policy defined
152 def put_account(self, user, account, policy={}):
153 """Create a new account with the given name.
156 NotAllowedError: Operation not permitted
158 ValueError: Invalid policy defined
162 def delete_account(self, user, account):
163 """Delete the account with the given name.
166 NotAllowedError: Operation not permitted
168 IndexError: Account is not empty
172 def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None):
173 """Return a list of container names existing under an account.
176 'marker': Start list from the next item after 'marker'
178 'limit': Number of containers to return
180 'shared': Only list containers with permissions set
184 NotAllowedError: Operation not permitted
188 def get_container_meta(self, user, account, container, domain, until=None):
189 """Return a dictionary with the container metadata for the domain.
191 The keys returned are all user-defined, except:
192 'name': The container name
194 'count': The number of objects
196 'bytes': The total data size
198 'modified': Last modification timestamp (overall)
200 'until_timestamp': Last modification until the timestamp provided
203 NotAllowedError: Operation not permitted
205 NameError: Container does not exist
209 def update_container_meta(self, user, account, container, domain, meta, replace=False):
210 """Update the metadata associated with the container for the domain.
213 'domain': Metadata domain
215 'meta': Dictionary with metadata to update
217 'replace': Replace instead of update
220 NotAllowedError: Operation not permitted
222 NameError: Container does not exist
226 def get_container_policy(self, user, account, container):
227 """Return a dictionary with the container policy.
229 The keys returned are:
230 'quota': The maximum bytes allowed (default is 0 - unlimited)
232 'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
235 NotAllowedError: Operation not permitted
237 NameError: Container does not exist
241 def update_container_policy(self, user, account, container, policy, replace=False):
242 """Update the policy associated with the container.
245 NotAllowedError: Operation not permitted
247 NameError: Container does not exist
249 ValueError: Invalid policy defined
253 def put_container(self, user, account, container, policy={}):
254 """Create a new container with the given name.
257 NotAllowedError: Operation not permitted
259 NameError: Container already exists
261 ValueError: Invalid policy defined
265 def delete_container(self, user, account, container, until=None):
266 """Delete/purge the container with the given name.
269 NotAllowedError: Operation not permitted
271 NameError: Container does not exist
273 IndexError: Container is not empty
277 def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None):
278 """Return a list of object (name, version_id) tuples existing under a container.
281 'prefix': List objects starting with 'prefix'
283 'delimiter': Return unique names before 'delimiter' and after 'prefix'
285 'marker': Start list from the next item after 'marker'
287 'limit': Number of objects to return
289 'virtual': If not set, the result will only include names starting
290 with 'prefix' and ending without a 'delimiter' or with
291 the first occurance of the 'delimiter' after 'prefix'.
292 If set, the result will include all names after 'prefix',
293 up to and including the 'delimiter' if it is found
295 'domain': Metadata domain for keys
297 'keys': Include objects that satisfy the key queries in the list.
298 Use 'key', '!key' for existence queries, 'key op value' for
299 value queries, where 'op' can be one of =, !=, <=, >=, <, >
301 'shared': Only list objects with permissions set
304 NotAllowedError: Operation not permitted
306 NameError: Container does not exist
310 def list_object_meta(self, user, account, container, domain, until=None):
311 """Return a list with all the container's object meta keys for the domain.
314 NotAllowedError: Operation not permitted
316 NameError: Container does not exist
320 def get_object_meta(self, user, account, container, name, domain, version=None):
321 """Return a dictionary with the object metadata for the domain.
323 The keys returned are all user-defined, except:
324 'name': The object name
326 'bytes': The total data size
328 'hash': The hashmap hash
330 'modified': Last modification timestamp (overall)
332 'modified_by': The user that committed the object (version requested)
334 'version': The version identifier
336 'version_timestamp': The version's modification timestamp
338 'uuid': A unique identifier that persists data or metadata updates and renames
341 NotAllowedError: Operation not permitted
343 NameError: Container/object does not exist
345 IndexError: Version does not exist
349 def update_object_meta(self, user, account, container, name, domain, meta, replace=False):
350 """Update the metadata associated with the object for the domain and return the new version.
353 'domain': Metadata domain
355 'meta': Dictionary with metadata to update
357 'replace': Replace instead of update
360 NotAllowedError: Operation not permitted
362 NameError: Container/object does not exist
366 def get_object_permissions(self, user, account, container, name):
367 """Return the action allowed on the object, the path
368 from which the object gets its permissions from,
369 along with a dictionary containing the permissions.
371 The dictionary keys are (also used for defining the action):
372 'read': The object is readable by the users/groups in the list
374 'write': The object is writable by the users/groups in the list
377 NotAllowedError: Operation not permitted
379 NameError: Container/object does not exist
383 def update_object_permissions(self, user, account, container, name, permissions):
384 """Update the permissions associated with the object.
387 'permissions': Dictionary with permissions to update
390 NotAllowedError: Operation not permitted
392 NameError: Container/object does not exist
394 ValueError: Invalid users/groups in permissions
396 AttributeError: Can not set permissions, as this object
397 is already shared/private by another object higher
398 in the hierarchy, or setting permissions here will
399 invalidate other permissions deeper in the hierarchy
403 def get_object_public(self, user, account, container, name):
404 """Return the public id of the object if applicable.
407 NotAllowedError: Operation not permitted
409 NameError: Container/object does not exist
413 def update_object_public(self, user, account, container, name, public):
414 """Update the public status of the object.
417 'public': Boolean value
420 NotAllowedError: Operation not permitted
422 NameError: Container/object does not exist
426 def get_object_hashmap(self, user, account, container, name, version=None):
427 """Return the object's size and a list with partial hashes.
430 NotAllowedError: Operation not permitted
432 NameError: Container/object does not exist
434 IndexError: Version does not exist
438 def update_object_hashmap(self, user, account, container, name, size, hashmap, domain, meta={}, replace_meta=False, permissions=None):
439 """Create/update an object with the specified size and partial hashes and return the new version.
442 'domain': Metadata domain
444 'meta': Dictionary with metadata to change
446 'replace_meta': Replace metadata instead of update
448 'permissions': Updated object permissions
451 NotAllowedError: Operation not permitted
453 NameError: Container does not exist
455 ValueError: Invalid users/groups in permissions
457 AttributeError: Can not set permissions
459 QuotaError: Account or container quota exceeded
463 def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, domain, meta={}, replace_meta=False, permissions=None, src_version=None):
464 """Copy an object's data and metadata and return the new version.
467 'domain': Metadata domain
469 'meta': Dictionary with metadata to change from source to destination
471 'replace_meta': Replace metadata instead of update
473 'permissions': New object permissions
475 'src_version': Copy from the version provided
478 NotAllowedError: Operation not permitted
480 NameError: Container/object does not exist
482 IndexError: Version does not exist
484 ValueError: Invalid users/groups in permissions
486 AttributeError: Can not set permissions
488 QuotaError: Account or container quota exceeded
492 def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, domain, meta={}, replace_meta=False, permissions=None):
493 """Move an object's data and metadata and return the new version.
496 'domain': Metadata domain
498 'meta': Dictionary with metadata to change from source to destination
500 'replace_meta': Replace metadata instead of update
502 'permissions': New object permissions
505 NotAllowedError: Operation not permitted
507 NameError: Container/object does not exist
509 ValueError: Invalid users/groups in permissions
511 AttributeError: Can not set permissions
513 QuotaError: Account or container quota exceeded
517 def delete_object(self, user, account, container, name, until=None):
518 """Delete/purge an object.
521 NotAllowedError: Operation not permitted
523 NameError: Container/object does not exist
527 def list_versions(self, user, account, container, name):
528 """Return a list of all (version, version_timestamp) tuples for an object.
531 NotAllowedError: Operation not permitted
535 def get_uuid(self, user, uuid):
536 """Return the (account, container, name) for the UUID given.
539 NotAllowedError: Operation not permitted
541 NameError: UUID does not exist
545 def get_public(self, user, public):
546 """Return the (account, container, name) for the public id given.
549 NotAllowedError: Operation not permitted
551 NameError: Public id does not exist
555 def get_block(self, hash):
556 """Return a block's data.
559 NameError: Block does not exist
563 def put_block(self, data):
564 """Store a block and return the hash."""
567 def update_block(self, hash, data, offset=0):
568 """Update a known block and return the hash.
571 IndexError: Offset or data outside block limits