Statistics
| Branch: | Tag: | Revision:

root / pithos / backends / base.py @ a6eb13e9

History | View | Annotate | Download (11.5 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 BaseBackend(object):
35
    """Abstract backend class that serves as a reference for actual implementations.
36
    
37
    The purpose of the backend is to provide the necessary functions for handling data
38
    and metadata. It is responsible for the actual storage and retrieval of information.
39
    
40
    Note that the account level is always valid as it is checked from another subsystem.
41
    
42
    When not replacing metadata, keys with empty values should be deleted.
43
    
44
    The following variables should be available:
45
        'hash_algorithm': Suggested is 'sha256'
46
        'block_size': Suggested is 4MB
47
    """
48
    
49
    def delete_account(self, user, account):
50
        """Delete the account with the given name.
51
        
52
        Raises:
53
            IndexError: Account is not empty
54
        """
55
        return
56
    
57
    def get_account_meta(self, user, account, until=None):
58
        """Return a dictionary with the account metadata.
59
        
60
        The keys returned are all user-defined, except:
61
            'name': The account name
62
            'count': The number of containers (or 0)
63
            'bytes': The total data size (or 0)
64
            'modified': Last modification timestamp (overall)
65
            'until_timestamp': Last modification until the timestamp provided
66
        """
67
        return {}
68
    
69
    def update_account_meta(self, user, account, meta, replace=False):
70
        """Update the metadata associated with the account.
71
        
72
        Parameters:
73
            'meta': Dictionary with metadata to update
74
            'replace': Replace instead of update
75
        """
76
        return
77
    
78
    def list_containers(self, user, account, marker=None, limit=10000, until=None):
79
        """Return a list of container (name, version_id) tuples existing under an account.
80
        
81
        Parameters:
82
            'marker': Start list from the next item after 'marker'
83
            'limit': Number of containers to return
84
        """
85
        return []
86
    
87
    def put_container(self, user, account, container):
88
        """Create a new container with the given name.
89
        
90
        Raises:
91
            NameError: Container already exists
92
        """
93
        return
94
    
95
    def delete_container(self, user, account, container):
96
        """Delete the container with the given name.
97
        
98
        Raises:
99
            NameError: Container does not exist
100
            IndexError: Container is not empty
101
        """
102
        return
103
    
104
    def get_container_meta(self, user, account, container, until=None):
105
        """Return a dictionary with the container metadata.
106
        
107
        The keys returned are all user-defined, except:
108
            'name': The container name
109
            'count': The number of objects
110
            'bytes': The total data size
111
            'modified': Last modification timestamp (overall)
112
            'until_timestamp': Last modification until the timestamp provided
113
        
114
        Raises:
115
            NameError: Container does not exist
116
        """
117
        return {}
118
    
119
    def update_container_meta(self, user, account, container, meta, replace=False):
120
        """Update the metadata associated with the container.
121
        
122
        Parameters:
123
            'meta': Dictionary with metadata to update
124
            'replace': Replace instead of update
125
        
126
        Raises:
127
            NameError: Container does not exist
128
        """
129
        return
130
    
131
    def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], until=None):
132
        """Return a list of object (name, version_id) tuples existing under a container.
133
        
134
        Parameters:
135
            'prefix': List objects starting with 'prefix'
136
            'delimiter': Return unique names before 'delimiter' and after 'prefix'
137
            'marker': Start list from the next item after 'marker'
138
            'limit': Number of objects to return
139
            'virtual': If not set, the result will only include names starting\
140
                       with 'prefix' and ending without a 'delimiter' or with\
141
                       the first occurance of the 'delimiter' after 'prefix'.\
142
                       If set, the result will include all names after 'prefix',\
143
                       up to and including the 'delimiter' if it is found
144
            'keys': Include objects that have meta with the keys in the list
145
        
146
        Raises:
147
            NameError: Container does not exist
148
        """
149
        return []
150
    
151
    def list_object_meta(self, user, account, container, until=None):
152
        """Return a list with all the container's object meta keys.
153
        
154
        Raises:
155
            NameError: Container does not exist
156
        """
157
        return []
158
    
159
    def get_object_meta(self, user, account, container, name, version=None):
160
        """Return a dictionary with the object metadata.
161
        
162
        The keys returned are all user-defined, except:
163
            'name': The object name
164
            'bytes': The total data size
165
            'modified': Last modification timestamp (overall)
166
            'version': The version identifier
167
            'version_timestamp': The version's modification timestamp
168
        
169
        Raises:
170
            NameError: Container/object does not exist
171
            IndexError: Version does not exist
172
        """
173
        return {}
174
    
175
    def update_object_meta(self, user, account, container, name, meta, replace=False):
176
        """Update the metadata associated with the object.
177
        
178
        Parameters:
179
            'meta': Dictionary with metadata to update
180
            'replace': Replace instead of update
181
        
182
        Raises:
183
            NameError: Container/object does not exist
184
        """
185
        return
186
    
187
    def get_object_permissions(self, user, account, container, name):
188
        """Return a dictionary with the object permissions.
189
        
190
        The keys are:
191
            'public': The object is readable by all and available at a public URL
192
            'private': No permissions set
193
            'read': The object is readable by the users/groups in the list
194
            'write': The object is writable by the users/groups in the list
195
        
196
        Raises:
197
            NameError: Container/object does not exist
198
        """
199
        return {}
200
    
201
    def update_object_permissions(self, user, account, container, name, permissions):
202
        """Update the permissions associated with the object.
203
        
204
        Parameters:
205
            'permissions': Dictionary with permissions to update
206
        
207
        Raises:
208
            NameError: Container/object does not exist
209
            ValueError: Invalid users/groups in permissions
210
            AttributeError: Can not set permissions, as this object\
211
                is already shared/private by another object higher\
212
                in the hierarchy, or setting permissions here will\
213
                invalidate other permissions deeper in the hierarchy
214
        """
215
        return
216
    
217
    def get_object_hashmap(self, user, account, container, name, version=None):
218
        """Return the object's size and a list with partial hashes.
219
        
220
        Raises:
221
            NameError: Container/object does not exist
222
            IndexError: Version does not exist
223
        """
224
        return 0, []
225
    
226
    def update_object_hashmap(self, user, account, container, name, size, hashmap, meta={}, replace_meta=False, permissions={}):
227
        """Create/update an object with the specified size and partial hashes.
228
        
229
        Parameters:
230
            'dest_meta': Dictionary with metadata to change
231
            'replace_meta': Replace metadata instead of update
232
            'permissions': Updated object permissions
233
        
234
        Raises:
235
            NameError: Container does not exist
236
            ValueError: Invalid users/groups in permissions
237
            AttributeError: Can not set permissions
238
        """
239
        return
240
    
241
    def copy_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions={}, src_version=None):
242
        """Copy an object's data and metadata.
243
        
244
        Parameters:
245
            'dest_meta': Dictionary with metadata to change from source to destination
246
            'replace_meta': Replace metadata instead of update
247
            'permissions': New object permissions
248
            'src_version': Copy from the version provided
249
        
250
        Raises:
251
            NameError: Container/object does not exist
252
            IndexError: Version does not exist
253
            ValueError: Invalid users/groups in permissions
254
            AttributeError: Can not set permissions
255
        """
256
        return
257
    
258
    def move_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions={}):
259
        """Move an object's data and metadata.
260
        
261
        Parameters:
262
            'dest_meta': Dictionary with metadata to change from source to destination
263
            'replace_meta': Replace metadata instead of update
264
            'permissions': New object permissions
265
        
266
        Raises:
267
            NameError: Container/object does not exist
268
            ValueError: Invalid users/groups in permissions
269
            AttributeError: Can not set permissions
270
        """
271
        return
272
    
273
    def delete_object(self, user, account, container, name):
274
        """Delete an object.
275
        
276
        Raises:
277
            NameError: Container/object does not exist
278
        """
279
        return
280
    
281
    def list_versions(self, user, account, container, name):
282
        """Return a list of all (version, version_timestamp) tuples for an object."""
283
        return []
284
    
285
    def get_block(self, hash):
286
        """Return a block's data.
287
        
288
        Raises:
289
            NameError: Block does not exist
290
        """
291
        return ''
292
    
293
    def put_block(self, data):
294
        """Store a block and return the hash."""
295
        return 0
296
    
297
    def update_block(self, hash, data, offset=0):
298
        """Update a known block and return the hash.
299
        
300
        Raises:
301
            IndexError: Offset or data outside block limits
302
        """
303
        return 0