Merge branch 'master' of https://code.grnet.gr/git/pithos
[pithos] / snf-pithos-backend / pithos / backends / base.py
index daf789d..7270e7e 100644 (file)
@@ -42,6 +42,24 @@ class NotAllowedError(Exception):
 class QuotaError(Exception):
     pass
 
+class AccountExists(NameError):
+    pass
+    
+class ContainerExists(NameError):
+    pass
+
+class AccountNotEmpty(IndexError):
+    pass
+
+class ContainerNotEmpty(IndexError):
+    pass
+
+class ItemNotExists(NameError):
+    pass
+
+class VersionNotExists(IndexError):
+    pass
+
 class BaseBackend(object):
     """Abstract backend class that serves as a reference for actual implementations.
     
@@ -74,7 +92,7 @@ class BaseBackend(object):
         """
         return []
     
-    def get_account_meta(self, user, account, domain, until=None):
+    def get_account_meta(self, user, account, domain, until=None, include_user_defined=True):
         """Return a dictionary with the account metadata for the domain.
         
         The keys returned are all user-defined, except:
@@ -165,11 +183,11 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            IndexError: Account is not empty
+            AccountNotEmpty: Account is not empty
         """
         return
     
-    def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None):
+    def list_containers(self, user, account, marker=None, limit=10000, shared=False, until=None, public=False):
         """Return a list of container names existing under an account.
         
         Parameters:
@@ -179,13 +197,25 @@ class BaseBackend(object):
             
             'shared': Only list containers with permissions set
             
+            'public': Only list containers containing public objects
+            
+        
+        Raises:
+            NotAllowedError: Operation not permitted
+        """
+        return []
+    
+    def list_container_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
+            
+            ItemNotExists: Container does not exist
         """
         return []
     
-    def get_container_meta(self, user, account, container, domain, until=None):
+    def get_container_meta(self, user, account, container, domain, until=None, include_user_defined=True):
         """Return a dictionary with the container metadata for the domain.
         
         The keys returned are all user-defined, except:
@@ -202,7 +232,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return {}
     
@@ -219,7 +249,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return
     
@@ -234,7 +264,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return {}
     
@@ -244,19 +274,22 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
             ValueError: Invalid policy defined
         """
         return
     
-    def put_container(self, user, account, container, policy={}):
+    def put_container(self, user, account, container, policy={}, delimiter=None):
         """Create a new container with the given name.
         
+        Parameters:
+            'delimiter': If present deletes container contents instead of the container
+        
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container already exists
+            ContainerExists: Container already exists
             
             ValueError: Invalid policy defined
         """
@@ -268,13 +301,13 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
-            IndexError: Container is not empty
+            ContainerNotEmpty: Container is not empty
         """
         return
     
-    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None):
+    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None, public=False):
         """Return a list of object (name, version_id) tuples existing under a container.
         
         Parameters:
@@ -302,25 +335,43 @@ class BaseBackend(object):
              
             'size_range': Include objects with byte size in (from, to).
                           Use None to specify unlimited
+            
+            'public': Only list public objects
+             
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
         """
         return []
     
-    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.
+    def list_object_meta(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, domain=None, keys=[], shared=False, until=None, size_range=None):
+        """Return a list of object metadata dicts existing under a container.
+        
+        Same parameters with list_objects. Returned dicts have no user-defined
+        metadata and, if until is not None, a None 'modified' timestamp.
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
+        """
+        return []
+    
+    def list_object_permissions(self, user, account, container, prefix=''):
+        """Return a list of paths that enforce permissions under a container.
+        
+        Raises:
+            NotAllowedError: Operation not permitted
         """
         return []
     
-    def get_object_meta(self, user, account, container, name, domain, version=None):
+    def list_object_public(self, user, account, container, prefix=''):
+        """Return a dict mapping paths to public ids for objects that are public under a container."""
+        return {}
+    
+    def get_object_meta(self, user, account, container, name, domain, version=None, include_user_defined=True):
         """Return a dictionary with the object metadata for the domain.
         
         The keys returned are all user-defined, except:
@@ -328,6 +379,8 @@ class BaseBackend(object):
             
             'bytes': The total data size
             
+            'type': The content type
+            
             'hash': The hashmap hash
             
             'modified': Last modification timestamp (overall)
@@ -339,13 +392,15 @@ class BaseBackend(object):
             'version_timestamp': The version's modification timestamp
             
             'uuid': A unique identifier that persists data or metadata updates and renames
+            
+            'checksum': The MD5 sum of the object (may be empty)
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
         """
         return {}
     
@@ -362,7 +417,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return ''
     
@@ -379,27 +434,22 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return {}
     
     def update_object_permissions(self, user, account, container, name, permissions):
-        """Update the permissions associated with the object.
+        """Update (set) the permissions associated with the object.
         
         Parameters:
-            'permissions': Dictionary with permissions to update
+            'permissions': Dictionary with permissions to set
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
             ValueError: Invalid users/groups in permissions
-            
-            AttributeError: Can not set permissions, as this object
-                is already shared/private by another object higher
-                in the hierarchy, or setting permissions here will
-                invalidate other permissions deeper in the hierarchy
         """
         return
     
@@ -409,7 +459,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return None
     
@@ -422,7 +472,7 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return
     
@@ -432,13 +482,13 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
         """
         return 0, []
     
-    def update_object_hashmap(self, user, account, container, name, size, hashmap, domain, meta={}, replace_meta=False, permissions=None):
+    def update_object_hashmap(self, user, account, container, name, size, type, hashmap, checksum, domain, meta={}, replace_meta=False, permissions=None):
         """Create/update an object with the specified size and partial hashes and return the new version.
         
         Parameters:
@@ -453,17 +503,19 @@ class BaseBackend(object):
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container does not exist
+            ItemNotExists: Container does not exist
             
             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, domain, meta={}, replace_meta=False, permissions=None, src_version=None):
+    def update_object_checksum(self, user, account, container, name, version, checksum):
+        """Update an object's checksum."""
+        return
+    
+    def copy_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, src_version=None, delimiter=None):
         """Copy an object's data and metadata and return the new version.
         
         Parameters:
@@ -476,23 +528,23 @@ class BaseBackend(object):
             'permissions': New object permissions
             
             'src_version': Copy from the version provided
+            
+            'delimiter': Copy objects whose path starts with src_name + delimiter
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
-            IndexError: Version does not exist
+            VersionNotExists: Version does not exist
             
             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, domain, meta={}, replace_meta=False, permissions=None):
+    def move_object(self, user, src_account, src_container, src_name, dest_account, dest_container, dest_name, type, domain, meta={}, replace_meta=False, permissions=None, delimiter=None):
         """Move an object's data and metadata and return the new version.
         
         Parameters:
@@ -503,27 +555,30 @@ class BaseBackend(object):
             'replace_meta': Replace metadata instead of update
             
             'permissions': New object permissions
+            
+            'delimiter': Move objects whose path starts with src_name + delimiter
         
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
             
             ValueError: Invalid users/groups in permissions
             
-            AttributeError: Can not set permissions
-            
             QuotaError: Account or container quota exceeded
         """
         return ''
     
-    def delete_object(self, user, account, container, name, until=None):
+    def delete_object(self, user, account, container, name, until=None, delimiter=None):
         """Delete/purge an object.
         
+        Parameters:
+            'delimiter': Delete objects whose path starting with name + delimiter
+        
         Raises:
             NotAllowedError: Operation not permitted
             
-            NameError: Container/object does not exist
+            ItemNotExists: Container/object does not exist
         """
         return
     
@@ -559,7 +614,7 @@ class BaseBackend(object):
         """Return a block's data.
         
         Raises:
-            NameError: Block does not exist
+            ItemNotExists: Block does not exist
         """
         return ''