root / pithos / backends / base.py @ 3436eeb0
History | View | Annotate | Download (11.4 kB)
1 | 5635f9ef | Antony Chazapis | # Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 5635f9ef | Antony Chazapis | #
|
3 | 5635f9ef | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | 5635f9ef | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | 5635f9ef | Antony Chazapis | # conditions are met:
|
6 | 5635f9ef | Antony Chazapis | #
|
7 | 5635f9ef | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | 5635f9ef | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | 5635f9ef | Antony Chazapis | # disclaimer.
|
10 | 5635f9ef | Antony Chazapis | #
|
11 | 5635f9ef | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | 5635f9ef | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | 5635f9ef | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | 5635f9ef | Antony Chazapis | # provided with the distribution.
|
15 | 5635f9ef | Antony Chazapis | #
|
16 | 5635f9ef | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 5635f9ef | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 5635f9ef | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 5635f9ef | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 5635f9ef | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 5635f9ef | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 5635f9ef | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 5635f9ef | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 5635f9ef | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 5635f9ef | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 5635f9ef | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 5635f9ef | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 5635f9ef | Antony Chazapis | #
|
29 | 5635f9ef | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | 5635f9ef | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | 5635f9ef | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | 5635f9ef | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | 5635f9ef | Antony Chazapis | |
34 | b956618e | Antony Chazapis | class BaseBackend(object): |
35 | 22dab079 | Antony Chazapis | """Abstract backend class that serves as a reference for actual implementations.
|
36 | b956618e | Antony Chazapis |
|
37 | b956618e | Antony Chazapis | The purpose of the backend is to provide the necessary functions for handling data
|
38 | b956618e | Antony Chazapis | and metadata. It is responsible for the actual storage and retrieval of information.
|
39 | b956618e | Antony Chazapis |
|
40 | b956618e | Antony Chazapis | Note that the account level is always valid as it is checked from another subsystem.
|
41 | 22dab079 | Antony Chazapis |
|
42 | 22dab079 | Antony Chazapis | The following variables should be available:
|
43 | 22dab079 | Antony Chazapis | 'hash_algorithm': Suggested is 'sha256'
|
44 | 22dab079 | Antony Chazapis | 'block_size': Suggested is 4MB
|
45 | b956618e | Antony Chazapis | """
|
46 | b956618e | Antony Chazapis | |
47 | 83dd59c5 | Antony Chazapis | def delete_account(self, user, account): |
48 | 58a6c894 | Antony Chazapis | """Delete the account with the given name.
|
49 | 83dd59c5 | Antony Chazapis |
|
50 | 58a6c894 | Antony Chazapis | Raises:
|
51 | 58a6c894 | Antony Chazapis | IndexError: Account is not empty
|
52 | 58a6c894 | Antony Chazapis | """
|
53 | 58a6c894 | Antony Chazapis | return
|
54 | 58a6c894 | Antony Chazapis | |
55 | 83dd59c5 | Antony Chazapis | def get_account_meta(self, user, account, until=None): |
56 | 22dab079 | Antony Chazapis | """Return a dictionary with the account metadata.
|
57 | b956618e | Antony Chazapis |
|
58 | b956618e | Antony Chazapis | The keys returned are all user-defined, except:
|
59 | b956618e | Antony Chazapis | 'name': The account name
|
60 | b956618e | Antony Chazapis | 'count': The number of containers (or 0)
|
61 | b956618e | Antony Chazapis | 'bytes': The total data size (or 0)
|
62 | 58a6c894 | Antony Chazapis | 'modified': Last modification timestamp (overall)
|
63 | 58a6c894 | Antony Chazapis | 'until_timestamp': Last modification until the timestamp provided
|
64 | b956618e | Antony Chazapis | """
|
65 | b956618e | Antony Chazapis | return {}
|
66 | b956618e | Antony Chazapis | |
67 | 83dd59c5 | Antony Chazapis | def update_account_meta(self, user, account, meta, replace=False): |
68 | 22dab079 | Antony Chazapis | """Update the metadata associated with the account.
|
69 | b956618e | Antony Chazapis |
|
70 | b956618e | Antony Chazapis | Parameters:
|
71 | b956618e | Antony Chazapis | 'meta': Dictionary with metadata to update
|
72 | 22dab079 | Antony Chazapis | 'replace': Replace instead of update
|
73 | b956618e | Antony Chazapis | """
|
74 | b956618e | Antony Chazapis | return
|
75 | b956618e | Antony Chazapis | |
76 | 83dd59c5 | Antony Chazapis | def list_containers(self, user, account, marker=None, limit=10000, until=None): |
77 | 58a6c894 | Antony Chazapis | """Return a list of container (name, version_id) tuples existing under an account.
|
78 | 58a6c894 | Antony Chazapis |
|
79 | 58a6c894 | Antony Chazapis | Parameters:
|
80 | 58a6c894 | Antony Chazapis | 'marker': Start list from the next item after 'marker'
|
81 | 58a6c894 | Antony Chazapis | 'limit': Number of containers to return
|
82 | 58a6c894 | Antony Chazapis | """
|
83 | 58a6c894 | Antony Chazapis | return []
|
84 | 58a6c894 | Antony Chazapis | |
85 | 83dd59c5 | Antony Chazapis | def put_container(self, user, account, container): |
86 | 22dab079 | Antony Chazapis | """Create a new container with the given name.
|
87 | 83dd59c5 | Antony Chazapis |
|
88 | b956618e | Antony Chazapis | Raises:
|
89 | b956618e | Antony Chazapis | NameError: Container already exists
|
90 | b956618e | Antony Chazapis | """
|
91 | b956618e | Antony Chazapis | return
|
92 | b956618e | Antony Chazapis | |
93 | 83dd59c5 | Antony Chazapis | def delete_container(self, user, account, container): |
94 | 22dab079 | Antony Chazapis | """Delete the container with the given name.
|
95 | 83dd59c5 | Antony Chazapis |
|
96 | b956618e | Antony Chazapis | Raises:
|
97 | b956618e | Antony Chazapis | NameError: Container does not exist
|
98 | b956618e | Antony Chazapis | IndexError: Container is not empty
|
99 | b956618e | Antony Chazapis | """
|
100 | b956618e | Antony Chazapis | return
|
101 | b956618e | Antony Chazapis | |
102 | 83dd59c5 | Antony Chazapis | def get_container_meta(self, user, account, container, until=None): |
103 | 22dab079 | Antony Chazapis | """Return a dictionary with the container metadata.
|
104 | 83dd59c5 | Antony Chazapis |
|
105 | b956618e | Antony Chazapis | The keys returned are all user-defined, except:
|
106 | b956618e | Antony Chazapis | 'name': The container name
|
107 | b956618e | Antony Chazapis | 'count': The number of objects
|
108 | b956618e | Antony Chazapis | 'bytes': The total data size
|
109 | 58a6c894 | Antony Chazapis | 'modified': Last modification timestamp (overall)
|
110 | 58a6c894 | Antony Chazapis | 'until_timestamp': Last modification until the timestamp provided
|
111 | b956618e | Antony Chazapis |
|
112 | b956618e | Antony Chazapis | Raises:
|
113 | b956618e | Antony Chazapis | NameError: Container does not exist
|
114 | b956618e | Antony Chazapis | """
|
115 | b956618e | Antony Chazapis | return {}
|
116 | b956618e | Antony Chazapis | |
117 | 83dd59c5 | Antony Chazapis | def update_container_meta(self, user, account, container, meta, replace=False): |
118 | 22dab079 | Antony Chazapis | """Update the metadata associated with the container.
|
119 | b956618e | Antony Chazapis |
|
120 | b956618e | Antony Chazapis | Parameters:
|
121 | b956618e | Antony Chazapis | 'meta': Dictionary with metadata to update
|
122 | 22dab079 | Antony Chazapis | 'replace': Replace instead of update
|
123 | b956618e | Antony Chazapis |
|
124 | b956618e | Antony Chazapis | Raises:
|
125 | b956618e | Antony Chazapis | NameError: Container does not exist
|
126 | b956618e | Antony Chazapis | """
|
127 | b956618e | Antony Chazapis | return
|
128 | b956618e | Antony Chazapis | |
129 | 83dd59c5 | Antony Chazapis | def list_objects(self, user, account, container, prefix='', delimiter=None, marker=None, limit=10000, virtual=True, keys=[], until=None): |
130 | 58a6c894 | Antony Chazapis | """Return a list of object (name, version_id) tuples existing under a container.
|
131 | b956618e | Antony Chazapis |
|
132 | b956618e | Antony Chazapis | Parameters:
|
133 | b956618e | Antony Chazapis | 'prefix': List objects starting with 'prefix'
|
134 | b956618e | Antony Chazapis | 'delimiter': Return unique names before 'delimiter' and after 'prefix'
|
135 | b956618e | Antony Chazapis | 'marker': Start list from the next item after 'marker'
|
136 | b956618e | Antony Chazapis | 'limit': Number of objects to return
|
137 | 3f839f59 | Antony Chazapis | 'virtual': If not set, the result will only include names starting\
|
138 | 3f839f59 | Antony Chazapis | with 'prefix' and ending without a 'delimiter' or with\
|
139 | 3f839f59 | Antony Chazapis | the first occurance of the 'delimiter' after 'prefix'.\
|
140 | 3f839f59 | Antony Chazapis | If set, the result will include all names after 'prefix',\
|
141 | 3f839f59 | Antony Chazapis | up to and including the 'delimiter' if it is found
|
142 | 22dab079 | Antony Chazapis | 'keys': Include objects that have meta with the keys in the list
|
143 | 22dab079 | Antony Chazapis |
|
144 | 22dab079 | Antony Chazapis | Raises:
|
145 | 22dab079 | Antony Chazapis | NameError: Container does not exist
|
146 | 22dab079 | Antony Chazapis | """
|
147 | 22dab079 | Antony Chazapis | return []
|
148 | 22dab079 | Antony Chazapis | |
149 | 83dd59c5 | Antony Chazapis | def list_object_meta(self, user, account, container, until=None): |
150 | 22dab079 | Antony Chazapis | """Return a list with all the container's object meta keys.
|
151 | b956618e | Antony Chazapis |
|
152 | b956618e | Antony Chazapis | Raises:
|
153 | b956618e | Antony Chazapis | NameError: Container does not exist
|
154 | b956618e | Antony Chazapis | """
|
155 | b956618e | Antony Chazapis | return []
|
156 | b956618e | Antony Chazapis | |
157 | 83dd59c5 | Antony Chazapis | def get_object_meta(self, user, account, container, name, version=None): |
158 | 22dab079 | Antony Chazapis | """Return a dictionary with the object metadata.
|
159 | b956618e | Antony Chazapis |
|
160 | b956618e | Antony Chazapis | The keys returned are all user-defined, except:
|
161 | 58a6c894 | Antony Chazapis | 'name': The object name
|
162 | b956618e | Antony Chazapis | 'bytes': The total data size
|
163 | 58a6c894 | Antony Chazapis | 'modified': Last modification timestamp (overall)
|
164 | 58a6c894 | Antony Chazapis | 'version': The version identifier
|
165 | 58a6c894 | Antony Chazapis | 'version_timestamp': The version's modification timestamp
|
166 | b956618e | Antony Chazapis |
|
167 | b956618e | Antony Chazapis | Raises:
|
168 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
169 | 58a6c894 | Antony Chazapis | IndexError: Version does not exist
|
170 | b956618e | Antony Chazapis | """
|
171 | b956618e | Antony Chazapis | return {}
|
172 | b956618e | Antony Chazapis | |
173 | 83dd59c5 | Antony Chazapis | def update_object_meta(self, user, account, container, name, meta, replace=False): |
174 | 22dab079 | Antony Chazapis | """Update the metadata associated with the object.
|
175 | b956618e | Antony Chazapis |
|
176 | b956618e | Antony Chazapis | Parameters:
|
177 | 58a6c894 | Antony Chazapis | 'meta': Dictionary with metadata to update.
|
178 | 22dab079 | Antony Chazapis | 'replace': Replace instead of update
|
179 | b956618e | Antony Chazapis |
|
180 | b956618e | Antony Chazapis | Raises:
|
181 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
182 | b956618e | Antony Chazapis | """
|
183 | b956618e | Antony Chazapis | return
|
184 | b956618e | Antony Chazapis | |
185 | 3436eeb0 | Antony Chazapis | def get_object_permissions(self, user, account, container, name): |
186 | 3436eeb0 | Antony Chazapis | """Return a dictionary with the object permissions.
|
187 | 3436eeb0 | Antony Chazapis |
|
188 | 3436eeb0 | Antony Chazapis | The keys are:
|
189 | 3436eeb0 | Antony Chazapis | 'public': The object is readable by all and available at a public URL
|
190 | 3436eeb0 | Antony Chazapis | 'private': No permissions set
|
191 | 3436eeb0 | Antony Chazapis | 'read': The object is readable by the users/groups in the list
|
192 | 3436eeb0 | Antony Chazapis | 'write': The object is writable by the users/groups in the list
|
193 | 3436eeb0 | Antony Chazapis |
|
194 | 3436eeb0 | Antony Chazapis | Raises:
|
195 | 3436eeb0 | Antony Chazapis | NameError: Container/object does not exist
|
196 | 3436eeb0 | Antony Chazapis | """
|
197 | 3436eeb0 | Antony Chazapis | return {}
|
198 | 3436eeb0 | Antony Chazapis | |
199 | 3436eeb0 | Antony Chazapis | def update_object_permissions(self, user, account, container, name, permissions): |
200 | 3436eeb0 | Antony Chazapis | """Update the permissions associated with the object.
|
201 | 3436eeb0 | Antony Chazapis |
|
202 | 3436eeb0 | Antony Chazapis | Parameters:
|
203 | 3436eeb0 | Antony Chazapis | 'permissions': Dictionary with permissions to update
|
204 | 3436eeb0 | Antony Chazapis |
|
205 | 3436eeb0 | Antony Chazapis | Raises:
|
206 | 3436eeb0 | Antony Chazapis | NameError: Container/object does not exist
|
207 | 3436eeb0 | Antony Chazapis | ValueError: Invalid users/groups in permissions
|
208 | 3436eeb0 | Antony Chazapis | AttributeError: Can not set permissions, as this object\
|
209 | 3436eeb0 | Antony Chazapis | is already shared/private by another object higher\
|
210 | 3436eeb0 | Antony Chazapis | in the hierarchy, or setting permissions here will\
|
211 | 3436eeb0 | Antony Chazapis | invalidate other permissions deeper in the hierarchy
|
212 | 3436eeb0 | Antony Chazapis | """
|
213 | 3436eeb0 | Antony Chazapis | return
|
214 | 3436eeb0 | Antony Chazapis | |
215 | 83dd59c5 | Antony Chazapis | def get_object_hashmap(self, user, account, container, name, version=None): |
216 | 22dab079 | Antony Chazapis | """Return the object's size and a list with partial hashes.
|
217 | b956618e | Antony Chazapis |
|
218 | b956618e | Antony Chazapis | Raises:
|
219 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
220 | 22dab079 | Antony Chazapis | IndexError: Version does not exist
|
221 | b956618e | Antony Chazapis | """
|
222 | 22dab079 | Antony Chazapis | return 0, [] |
223 | b956618e | Antony Chazapis | |
224 | 3436eeb0 | Antony Chazapis | def update_object_hashmap(self, user, account, container, name, size, hashmap, meta={}, replace_meta=False, permissions={}): |
225 | 22dab079 | Antony Chazapis | """Create/update an object with the specified size and partial hashes.
|
226 | b956618e | Antony Chazapis |
|
227 | 3436eeb0 | Antony Chazapis | Parameters:
|
228 | 3436eeb0 | Antony Chazapis | 'dest_meta': Dictionary with metadata to change
|
229 | 3436eeb0 | Antony Chazapis | 'replace_meta': Replace metadata instead of update
|
230 | 3436eeb0 | Antony Chazapis | 'permissions': Updated object permissions
|
231 | 3436eeb0 | Antony Chazapis |
|
232 | b956618e | Antony Chazapis | Raises:
|
233 | 58a6c894 | Antony Chazapis | NameError: Container does not exist
|
234 | 3436eeb0 | Antony Chazapis | ValueError: Invalid users/groups in permissions
|
235 | 3436eeb0 | Antony Chazapis | AttributeError: Can not set permissions
|
236 | b956618e | Antony Chazapis | """
|
237 | b956618e | Antony Chazapis | return
|
238 | b956618e | Antony Chazapis | |
239 | 3436eeb0 | Antony Chazapis | def copy_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions={}, src_version=None): |
240 | 22dab079 | Antony Chazapis | """Copy an object's data and metadata.
|
241 | b956618e | Antony Chazapis |
|
242 | b956618e | Antony Chazapis | Parameters:
|
243 | 3436eeb0 | Antony Chazapis | 'dest_meta': Dictionary with metadata to change from source to destination
|
244 | 22dab079 | Antony Chazapis | 'replace_meta': Replace metadata instead of update
|
245 | 3436eeb0 | Antony Chazapis | 'permissions': New object permissions
|
246 | 3436eeb0 | Antony Chazapis | 'src_version': Copy from the version provided
|
247 | b956618e | Antony Chazapis |
|
248 | b956618e | Antony Chazapis | Raises:
|
249 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
250 | 58a6c894 | Antony Chazapis | IndexError: Version does not exist
|
251 | 3436eeb0 | Antony Chazapis | ValueError: Invalid users/groups in permissions
|
252 | 3436eeb0 | Antony Chazapis | AttributeError: Can not set permissions
|
253 | b956618e | Antony Chazapis | """
|
254 | b956618e | Antony Chazapis | return
|
255 | b956618e | Antony Chazapis | |
256 | 3436eeb0 | Antony Chazapis | def move_object(self, user, account, src_container, src_name, dest_container, dest_name, dest_meta={}, replace_meta=False, permissions={}): |
257 | 22dab079 | Antony Chazapis | """Move an object's data and metadata.
|
258 | b956618e | Antony Chazapis |
|
259 | b956618e | Antony Chazapis | Parameters:
|
260 | 3436eeb0 | Antony Chazapis | 'dest_meta': Dictionary with metadata to change from source to destination
|
261 | 22dab079 | Antony Chazapis | 'replace_meta': Replace metadata instead of update
|
262 | 3436eeb0 | Antony Chazapis | 'permissions': New object permissions
|
263 | b956618e | Antony Chazapis |
|
264 | b956618e | Antony Chazapis | Raises:
|
265 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
266 | 3436eeb0 | Antony Chazapis | ValueError: Invalid users/groups in permissions
|
267 | 3436eeb0 | Antony Chazapis | AttributeError: Can not set permissions
|
268 | b956618e | Antony Chazapis | """
|
269 | b956618e | Antony Chazapis | return
|
270 | b956618e | Antony Chazapis | |
271 | 83dd59c5 | Antony Chazapis | def delete_object(self, user, account, container, name): |
272 | 22dab079 | Antony Chazapis | """Delete an object.
|
273 | b956618e | Antony Chazapis |
|
274 | b956618e | Antony Chazapis | Raises:
|
275 | b956618e | Antony Chazapis | NameError: Container/object does not exist
|
276 | b956618e | Antony Chazapis | """
|
277 | b956618e | Antony Chazapis | return
|
278 | 22dab079 | Antony Chazapis | |
279 | 83dd59c5 | Antony Chazapis | def list_versions(self, user, account, container, name): |
280 | 83dd59c5 | Antony Chazapis | """Return a list of all (version, version_timestamp) tuples for an object."""
|
281 | 58a6c894 | Antony Chazapis | return []
|
282 | 58a6c894 | Antony Chazapis | |
283 | 22dab079 | Antony Chazapis | def get_block(self, hash): |
284 | 22dab079 | Antony Chazapis | """Return a block's data.
|
285 | 22dab079 | Antony Chazapis |
|
286 | 22dab079 | Antony Chazapis | Raises:
|
287 | 22dab079 | Antony Chazapis | NameError: Block does not exist
|
288 | 22dab079 | Antony Chazapis | """
|
289 | 22dab079 | Antony Chazapis | return '' |
290 | 22dab079 | Antony Chazapis | |
291 | 22dab079 | Antony Chazapis | def put_block(self, data): |
292 | 22dab079 | Antony Chazapis | """Store a block and return the hash."""
|
293 | 22dab079 | Antony Chazapis | return 0 |
294 | 22dab079 | Antony Chazapis | |
295 | 22dab079 | Antony Chazapis | def update_block(self, hash, data, offset=0): |
296 | 22dab079 | Antony Chazapis | """Update a known block and return the hash.
|
297 | 22dab079 | Antony Chazapis |
|
298 | 22dab079 | Antony Chazapis | Raises:
|
299 | 22dab079 | Antony Chazapis | IndexError: Offset or data outside block limits
|
300 | 22dab079 | Antony Chazapis | """
|
301 | 22dab079 | Antony Chazapis | return 0 |