Statistics
| Branch: | Tag: | Revision:

root / pithos / backends / base.py @ 3f839f59

History | View | Annotate | Download (8.6 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
    The following variables should be available:
43
        'hash_algorithm': Suggested is 'sha256'
44
        'block_size': Suggested is 4MB
45
    """
46
    
47
    def get_account_meta(self, account):
48
        """Return a dictionary with the account metadata.
49
        
50
        The keys returned are all user-defined, except:
51
            'name': The account name
52
            'count': The number of containers (or 0)
53
            'bytes': The total data size (or 0)
54
            'modified': Last modification timestamp
55
        """
56
        return {}
57
    
58
    def update_account_meta(self, account, meta, replace=False):
59
        """Update the metadata associated with the account.
60
        
61
        Parameters:
62
            'meta': Dictionary with metadata to update
63
            'replace': Replace instead of update
64
        """
65
        return
66
    
67
    def put_container(self, account, name):
68
        """Create a new container with the given name.
69

70
        Raises:
71
            NameError: Container already exists
72
        """
73
        return
74
    
75
    def delete_container(self, account, name):
76
        """Delete the container with the given name.
77

78
        Raises:
79
            NameError: Container does not exist
80
            IndexError: Container is not empty
81
        """
82
        return
83
    
84
    def get_container_meta(self, account, name):
85
        """Return a dictionary with the container metadata.
86

87
        The keys returned are all user-defined, except:
88
            'name': The container name
89
            'count': The number of objects
90
            'bytes': The total data size
91
            'created': Creation timestamp
92
            'modified': Last modification timestamp
93
        
94
        Raises:
95
            NameError: Container does not exist
96
        """
97
        return {}
98
    
99
    def update_container_meta(self, account, name, meta, replace=False):
100
        """Update the metadata associated with the container.
101
        
102
        Parameters:
103
            'meta': Dictionary with metadata to update
104
            'replace': Replace instead of update
105
        
106
        Raises:
107
            NameError: Container does not exist
108
        """
109
        return
110
    
111
    def list_containers(self, account, marker=None, limit=10000):
112
        """Return a list of containers existing under an account.
113
        
114
        Parameters:
115
            'marker': Start list from the next item after 'marker'
116
            'limit': Number of containers to return
117
        """
118
        return []
119
    
120
    def list_objects(self, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[]):
121
        """Return a list of objects existing under a container.
122
        
123
        Parameters:
124
            'prefix': List objects starting with 'prefix'
125
            'delimiter': Return unique names before 'delimiter' and after 'prefix'
126
            'marker': Start list from the next item after 'marker'
127
            'limit': Number of objects to return
128
            'virtual': If not set, the result will only include names starting\
129
                       with 'prefix' and ending without a 'delimiter' or with\
130
                       the first occurance of the 'delimiter' after 'prefix'.\
131
                       If set, the result will include all names after 'prefix',\
132
                       up to and including the 'delimiter' if it is found
133
            'keys': Include objects that have meta with the keys in the list
134
        
135
        Raises:
136
            NameError: Container does not exist
137
        """
138
        return []
139
    
140
    def list_object_meta(self, account, name):
141
        """Return a list with all the container's object meta keys.
142
        
143
        Raises:
144
            NameError: Container does not exist
145
        """
146
        return []
147
    
148
    def get_object_meta(self, account, container, name):
149
        """Return a dictionary with the object metadata.
150
        
151
        The keys returned are all user-defined, except:
152
            'name': The account name
153
            'bytes': The total data size
154
            'version': The latest version (zero if not versioned)
155
            'created': Creation timestamp
156
            'modified': Last modification timestamp
157
        
158
        Raises:
159
            NameError: Container/object does not exist
160
        """
161
        return {}
162
    
163
    def update_object_meta(self, account, container, name, meta, replace=False):
164
        """Update the metadata associated with the object.
165
        
166
        Parameters:
167
            'meta': Dictionary with metadata to update.\
168
                    Use the 'versioned' key to control versioning
169
            'replace': Replace instead of update
170
        
171
        Raises:
172
            NameError: Container/object does not exist
173
        """
174
        return
175
    
176
    def get_object_hashmap(self, account, container, name, version=None):
177
        """Return the object's size and a list with partial hashes.
178
        
179
        Raises:
180
            NameError: Container/object does not exist
181
            IndexError: Version does not exist
182
        """
183
        return 0, []
184
    
185
    def update_object_hashmap(self, account, container, name, size, hashmap):
186
        """Create/update an object with the specified size and partial hashes.
187
        
188
        Raises:
189
            NameError: Container/block does not exist
190
        """
191
        return
192
    
193
    def copy_object(self, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False):
194
        """Copy an object's data and metadata.
195
        
196
        Parameters:
197
            'dest_meta': Dictionary with metadata to changes from source to destination
198
            'replace_meta': Replace metadata instead of update
199
        
200
        Raises:
201
            NameError: Container/object does not exist
202
        """
203
        return
204
    
205
    def move_object(self, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False):
206
        """Move an object's data and metadata.
207
        
208
        Parameters:
209
            'dest_meta': Dictionary with metadata to changes from source to destination
210
            'replace_meta': Replace metadata instead of update
211
        
212
        Raises:
213
            NameError: Container/object does not exist
214
        """
215
        return
216
    
217
    def delete_object(self, account, container, name):
218
        """Delete an object.
219
        
220
        Raises:
221
            NameError: Container/object does not exist
222
        """
223
        return
224
    
225
    def get_block(self, hash):
226
        """Return a block's data.
227
        
228
        Raises:
229
            NameError: Block does not exist
230
        """
231
        return ''
232
    
233
    def put_block(self, data):
234
        """Store a block and return the hash."""
235
        return 0
236
    
237
    def update_block(self, hash, data, offset=0):
238
        """Update a known block and return the hash.
239
        
240
        Raises:
241
            IndexError: Offset or data outside block limits
242
        """
243
        return 0