Unique object identifiers in the backend.
[pithos] / pithos / backends / base.py
index 2bd5eab..e218308 100644 (file)
@@ -34,6 +34,9 @@
 class NotAllowedError(Exception):
     pass
 
+class QuotaError(Exception):
+    pass
+
 class BaseBackend(object):
     """Abstract backend class that serves as a reference for actual implementations.
     
@@ -48,8 +51,18 @@ class BaseBackend(object):
         'hash_algorithm': Suggested is 'sha256'
         
         'block_size': Suggested is 4MB
+        
+        'default_policy': A dictionary with default policy settings
     """
     
+    def __init__(self, db_module, db_connection, block_module, block_path):
+        """Initialize backend with supplied modules and options."""
+        pass
+    
+    def close(self):
+        """Close the backend connection."""
+        pass
+    
     def list_accounts(self, user, marker=None, limit=10000):
         """Return a list of accounts the user can access.
         
@@ -60,8 +73,8 @@ class BaseBackend(object):
         """
         return []
     
-    def get_account_meta(self, user, account, until=None):
-        """Return a dictionary with the account metadata.
+    def get_account_meta(self, user, account, domain, until=None):
+        """Return a dictionary with the account metadata for the domain.
         
         The keys returned are all user-defined, except:
             'name': The account name
@@ -79,10 +92,12 @@ class BaseBackend(object):
         """
         return {}
     
-    def update_account_meta(self, user, account, meta, replace=False):
-        """Update the metadata associated with the account.
+    def update_account_meta(self, user, account, domain, meta, replace=False):
+        """Update the metadata associated with the account for the domain.
         
         Parameters:
+            'domain': Metadata domain
+            
             'meta': Dictionary with metadata to update
             
             'replace': Replace instead of update
@@ -110,11 +125,36 @@ class BaseBackend(object):
         """
         return
     
-    def put_account(self, user, account):
+    def get_account_policy(self, user, account):
+        """Return a dictionary with the account policy.
+        
+        The keys returned are:
+            'quota': The maximum bytes allowed (default is 0 - unlimited)
+            
+            'versioning': Can be 'auto', 'manual' or 'none' (default is 'manual')
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+        """
+        return {}
+    
+    def update_account_policy(self, user, account, policy, replace=False):
+        """Update the policy associated with the account.
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+            
+            ValueError: Invalid policy defined
+        """
+        return
+    
+    def put_account(self, user, account, policy={}):
         """Create a new account with the given name.
         
         Raises:
             NotAllowedError: Operation not permitted
+            
+            ValueError: Invalid policy defined
         """
         return
     
@@ -144,8 +184,8 @@ class BaseBackend(object):
         """
         return []
     
-    def get_container_meta(self, user, account, container, until=None):
-        """Return a dictionary with the container metadata.
+    def get_container_meta(self, user, account, container, domain, until=None):
+        """Return a dictionary with the container metadata for the domain.
         
         The keys returned are all user-defined, except:
             'name': The container name
@@ -165,10 +205,12 @@ class BaseBackend(object):
         """
         return {}
     
-    def update_container_meta(self, user, account, container, meta, replace=False):
-        """Update the metadata associated with the container.
+    def update_container_meta(self, user, account, container, domain, meta, replace=False):
+        """Update the metadata associated with the container for the domain.
         
         Parameters:
+            'domain': Metadata domain
+            
             'meta': Dictionary with metadata to update
             
             'replace': Replace instead of update
@@ -196,7 +238,7 @@ class BaseBackend(object):
         return {}
     
     def update_container_policy(self, user, account, container, policy, replace=False):
-        """Update the policy associated with the account.
+        """Update the policy associated with the container.
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -207,7 +249,7 @@ class BaseBackend(object):
         """
         return
     
-    def put_container(self, user, account, container, policy=None):
+    def put_container(self, user, account, container, policy={}):
         """Create a new container with the given name.
         
         Raises:
@@ -231,7 +273,7 @@ class BaseBackend(object):
         """
         return
     
-    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], shared=False, until=None):
+    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None):
         """Return a list of object (name, version_id) tuples existing under a container.
         
         Parameters:
@@ -249,7 +291,11 @@ class BaseBackend(object):
                        If set, the result will include all names after 'prefix',
                        up to and including the 'delimiter' if it is found
             
-            'keys': Include objects that have meta with the keys in the list
+            'domain': Metadata domain for keys
+            
+            'keys': Include objects that satisfy the key queries in the list.
+                    Use 'key', '!key' for existence queries, 'key op value' for
+                    value queries, where 'op' can be one of =, !=, <=, >=, <, >
             
             'shared': Only list objects with permissions set
         
@@ -260,8 +306,8 @@ class BaseBackend(object):
         """
         return []
     
-    def list_object_meta(self, user, account, container, until=None):
-        """Return a list with all the container's object meta keys.
+    def list_object_meta(self, user, account, container, domain, until=None):
+        """Return a list with all the container's object meta keys for the domain.
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -270,14 +316,16 @@ class BaseBackend(object):
         """
         return []
     
-    def get_object_meta(self, user, account, container, name, version=None):
-        """Return a dictionary with the object metadata.
+    def get_object_meta(self, user, account, container, name, domain, version=None):
+        """Return a dictionary with the object metadata for the domain.
         
         The keys returned are all user-defined, except:
             'name': The object name
             
             'bytes': The total data size
             
+            'hash': The hashmap hash
+            
             'modified': Last modification timestamp (overall)
             
             'modified_by': The user that committed the object (version requested)
@@ -285,6 +333,8 @@ class BaseBackend(object):
             'version': The version identifier
             
             'version_timestamp': The version's modification timestamp
+            
+            'uuid': A unique identifier that persists data or metadata updates and renames
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -295,10 +345,12 @@ class BaseBackend(object):
         """
         return {}
     
-    def update_object_meta(self, user, account, container, name, meta, replace=False):
-        """Update the metadata associated with the object and return the new version.
+    def update_object_meta(self, user, account, container, name, domain, meta, replace=False):
+        """Update the metadata associated with the object for the domain and return the new version.
         
         Parameters:
+            'domain': Metadata domain
+            
             'meta': Dictionary with metadata to update
             
             'replace': Replace instead of update
@@ -348,7 +400,7 @@ class BaseBackend(object):
         return
     
     def get_object_public(self, user, account, container, name):
-        """Return the public URL of the object if applicable.
+        """Return the public id of the object if applicable.
         
         Raises:
             NotAllowedError: Operation not permitted
@@ -382,11 +434,13 @@ class BaseBackend(object):
         """
         return 0, []
     
-    def update_object_hashmap(self, user, account, container, name, size, hashmap, meta={}, replace_meta=False, permissions=None):
+    def update_object_hashmap(self, user, account, container, name, size, hashmap, domain, meta={}, replace_meta=False, permissions=None):
         """Create/update an object with the specified size and partial hashes and return the new version.
         
         Parameters:
-            'dest_meta': Dictionary with metadata to change
+            'domain': Metadata domain
+            
+            'meta': Dictionary with metadata to change
             
             'replace_meta': Replace metadata instead of update
             
@@ -400,14 +454,18 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''
     
-    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):
+    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):
         """Copy an object's data and metadata and return the new version.
         
         Parameters:
-            'dest_meta': Dictionary with metadata to change from source to destination
+            'domain': Metadata domain
+            
+            'meta': Dictionary with metadata to change from source to destination
             
             'replace_meta': Replace metadata instead of update
             
@@ -425,14 +483,18 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''
     
-    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions=None):
+    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, domain, meta={}, replace_meta=False, permissions=None):
         """Move an object's data and metadata and return the new version.
         
         Parameters:
-            'dest_meta': Dictionary with metadata to change from source to destination
+            'domain': Metadata domain
+            
+            'meta': Dictionary with metadata to change from source to destination
             
             'replace_meta': Replace metadata instead of update
             
@@ -446,6 +508,8 @@ class BaseBackend(object):
             ValueError: Invalid users/groups in permissions
             
             AttributeError: Can not set permissions
+            
+            QuotaError: Account or container quota exceeded
         """
         return ''
     
@@ -467,6 +531,16 @@ class BaseBackend(object):
         """
         return []
     
+    def get_public(self, user, public):
+        """Return the (account, container, name) for the public id given.
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+            
+            NameError: Public id does not exist
+        """
+        return None
+    
     def get_block(self, hash):
         """Return a block's data.