root / kamaki / clients / pithos / __init__.py @ 6e50fed4
History | View | Annotate | Download (48.1 kB)
1 | fce31e83 | Stavros Sachtouris | # Copyright 2011-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | d2cea1e2 | Giorgos Verigakis | #
|
3 | d2cea1e2 | Giorgos Verigakis | # Redistribution and use in source and binary forms, with or
|
4 | d2cea1e2 | Giorgos Verigakis | # without modification, are permitted provided that the following
|
5 | d2cea1e2 | Giorgos Verigakis | # conditions are met:
|
6 | d2cea1e2 | Giorgos Verigakis | #
|
7 | d2cea1e2 | Giorgos Verigakis | # 1. Redistributions of source code must retain the above
|
8 | d2cea1e2 | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
9 | d2cea1e2 | Giorgos Verigakis | # disclaimer.
|
10 | d2cea1e2 | Giorgos Verigakis | #
|
11 | d2cea1e2 | Giorgos Verigakis | # 2. Redistributions in binary form must reproduce the above
|
12 | d2cea1e2 | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
13 | d2cea1e2 | Giorgos Verigakis | # disclaimer in the documentation and/or other materials
|
14 | d2cea1e2 | Giorgos Verigakis | # provided with the distribution.
|
15 | d2cea1e2 | Giorgos Verigakis | #
|
16 | d2cea1e2 | Giorgos Verigakis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | d2cea1e2 | Giorgos Verigakis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | d2cea1e2 | Giorgos Verigakis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | d2cea1e2 | Giorgos Verigakis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | d2cea1e2 | Giorgos Verigakis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | d2cea1e2 | Giorgos Verigakis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | d2cea1e2 | Giorgos Verigakis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | d2cea1e2 | Giorgos Verigakis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | d2cea1e2 | Giorgos Verigakis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | d2cea1e2 | Giorgos Verigakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | d2cea1e2 | Giorgos Verigakis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | d2cea1e2 | Giorgos Verigakis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | d2cea1e2 | Giorgos Verigakis | #
|
29 | d2cea1e2 | Giorgos Verigakis | # The views and conclusions contained in the software and
|
30 | d2cea1e2 | Giorgos Verigakis | # documentation are those of the authors and should not be
|
31 | d2cea1e2 | Giorgos Verigakis | # interpreted as representing official policies, either expressed
|
32 | d2cea1e2 | Giorgos Verigakis | # or implied, of GRNET S.A.
|
33 | d2cea1e2 | Giorgos Verigakis | |
34 | f27ed9a0 | Stavros Sachtouris | from threading import enumerate as activethreads |
35 | 435008b6 | Stavros Sachtouris | |
36 | 3dabe5d2 | Stavros Sachtouris | from os import fstat |
37 | 64ab4c13 | Stavros Sachtouris | from hashlib import new as newhashlib |
38 | e02728f9 | Stavros Sachtouris | from time import time |
39 | 49cc29b2 | Stavros Sachtouris | from StringIO import StringIO |
40 | a91e0293 | Giorgos Verigakis | |
41 | 64ab4c13 | Stavros Sachtouris | from binascii import hexlify |
42 | 6a0b1658 | Giorgos Verigakis | |
43 | 6069b53b | Stavros Sachtouris | from kamaki.clients import SilentEvent, sendlog |
44 | 55faa0bc | Stavros Sachtouris | from kamaki.clients.pithos.rest_api import PithosRestClient |
45 | c270fe96 | Stavros Sachtouris | from kamaki.clients.storage import ClientError |
46 | c270fe96 | Stavros Sachtouris | from kamaki.clients.utils import path4url, filter_in |
47 | 6a0b1658 | Giorgos Verigakis | |
48 | 3dabe5d2 | Stavros Sachtouris | |
49 | 4375e020 | Stavros Sachtouris | def _pithos_hash(block, blockhash): |
50 | 64ab4c13 | Stavros Sachtouris | h = newhashlib(blockhash) |
51 | 6a0b1658 | Giorgos Verigakis | h.update(block.rstrip('\x00'))
|
52 | 6a0b1658 | Giorgos Verigakis | return h.hexdigest()
|
53 | 6a0b1658 | Giorgos Verigakis | |
54 | 3dabe5d2 | Stavros Sachtouris | |
55 | 642f1bbd | Stavros Sachtouris | def _range_up(start, end, a_range): |
56 | 642f1bbd | Stavros Sachtouris | if a_range:
|
57 | 6e50fed4 | Stavros Sachtouris | rstart, sep, rend = a_range.partition('-')
|
58 | 6e50fed4 | Stavros Sachtouris | if rstart:
|
59 | 6e50fed4 | Stavros Sachtouris | if sep:
|
60 | 6e50fed4 | Stavros Sachtouris | rstart, rend = int(rstart), int(rend) |
61 | 6e50fed4 | Stavros Sachtouris | else:
|
62 | 6e50fed4 | Stavros Sachtouris | rstart, rend = 0, int(rstart) |
63 | 6e50fed4 | Stavros Sachtouris | elif sep:
|
64 | 6e50fed4 | Stavros Sachtouris | return (0, - int(rend)) |
65 | 6e50fed4 | Stavros Sachtouris | else:
|
66 | 6e50fed4 | Stavros Sachtouris | return (0, 0) |
67 | 642f1bbd | Stavros Sachtouris | if rstart > end or rend < start: |
68 | 3dabe5d2 | Stavros Sachtouris | return (0, 0) |
69 | 642f1bbd | Stavros Sachtouris | if rstart > start:
|
70 | 642f1bbd | Stavros Sachtouris | start = rstart |
71 | 642f1bbd | Stavros Sachtouris | if rend < end:
|
72 | 642f1bbd | Stavros Sachtouris | end = rend |
73 | 642f1bbd | Stavros Sachtouris | return (start, end)
|
74 | 642f1bbd | Stavros Sachtouris | |
75 | 3dabe5d2 | Stavros Sachtouris | |
76 | 55faa0bc | Stavros Sachtouris | class PithosClient(PithosRestClient): |
77 | 76e7661e | Stavros Sachtouris | """Synnefo Pithos+ API client"""
|
78 | a91e0293 | Giorgos Verigakis | |
79 | 3dabe5d2 | Stavros Sachtouris | def __init__(self, base_url, token, account=None, container=None): |
80 | 3dabe5d2 | Stavros Sachtouris | super(PithosClient, self).__init__(base_url, token, account, container) |
81 | 435008b6 | Stavros Sachtouris | |
82 | 94bedc5b | Stavros Sachtouris | def create_container( |
83 | 94bedc5b | Stavros Sachtouris | self,
|
84 | 94bedc5b | Stavros Sachtouris | container=None, sizelimit=None, versioning=None, metadata=None): |
85 | 94bedc5b | Stavros Sachtouris | """
|
86 | 94bedc5b | Stavros Sachtouris | :param container: (str) if not given, self.container is used instead
|
87 | 94bedc5b | Stavros Sachtouris |
|
88 | 94bedc5b | Stavros Sachtouris | :param sizelimit: (int) container total size limit in bytes
|
89 | 94bedc5b | Stavros Sachtouris |
|
90 | 94bedc5b | Stavros Sachtouris | :param versioning: (str) can be auto or whatever supported by server
|
91 | 94bedc5b | Stavros Sachtouris |
|
92 | 94bedc5b | Stavros Sachtouris | :param metadata: (dict) Custom user-defined metadata of the form
|
93 | 94bedc5b | Stavros Sachtouris | { 'name1': 'value1', 'name2': 'value2', ... }
|
94 | 94bedc5b | Stavros Sachtouris |
|
95 | 94bedc5b | Stavros Sachtouris | :returns: (dict) response headers
|
96 | 94bedc5b | Stavros Sachtouris | """
|
97 | 94bedc5b | Stavros Sachtouris | cnt_back_up = self.container
|
98 | 94bedc5b | Stavros Sachtouris | try:
|
99 | 94bedc5b | Stavros Sachtouris | self.container = container or cnt_back_up |
100 | 94bedc5b | Stavros Sachtouris | r = self.container_put(
|
101 | 94bedc5b | Stavros Sachtouris | quota=sizelimit, versioning=versioning, metadata=metadata) |
102 | 94bedc5b | Stavros Sachtouris | return r.headers
|
103 | 94bedc5b | Stavros Sachtouris | finally:
|
104 | 94bedc5b | Stavros Sachtouris | self.container = cnt_back_up
|
105 | 94bedc5b | Stavros Sachtouris | |
106 | 2a7292f1 | Stavros Sachtouris | def purge_container(self, container=None): |
107 | 4375e020 | Stavros Sachtouris | """Delete an empty container and destroy associated blocks
|
108 | 4375e020 | Stavros Sachtouris | """
|
109 | 2a7292f1 | Stavros Sachtouris | cnt_back_up = self.container
|
110 | 2a7292f1 | Stavros Sachtouris | try:
|
111 | 2a7292f1 | Stavros Sachtouris | self.container = container or cnt_back_up |
112 | 5655d560 | Stavros Sachtouris | r = self.container_delete(until=unicode(time())) |
113 | 2a7292f1 | Stavros Sachtouris | finally:
|
114 | 2a7292f1 | Stavros Sachtouris | self.container = cnt_back_up
|
115 | 5655d560 | Stavros Sachtouris | return r.headers
|
116 | 3dabe5d2 | Stavros Sachtouris | |
117 | 24ff0a35 | Stavros Sachtouris | def upload_object_unchunked( |
118 | 24ff0a35 | Stavros Sachtouris | self, obj, f,
|
119 | 24ff0a35 | Stavros Sachtouris | withHashFile=False,
|
120 | 24ff0a35 | Stavros Sachtouris | size=None,
|
121 | 24ff0a35 | Stavros Sachtouris | etag=None,
|
122 | 24ff0a35 | Stavros Sachtouris | content_encoding=None,
|
123 | 24ff0a35 | Stavros Sachtouris | content_disposition=None,
|
124 | 24ff0a35 | Stavros Sachtouris | content_type=None,
|
125 | 24ff0a35 | Stavros Sachtouris | sharing=None,
|
126 | 24ff0a35 | Stavros Sachtouris | public=None):
|
127 | 4375e020 | Stavros Sachtouris | """
|
128 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
129 | 4375e020 | Stavros Sachtouris |
|
130 | 4375e020 | Stavros Sachtouris | :param f: open file descriptor
|
131 | 4375e020 | Stavros Sachtouris |
|
132 | 4375e020 | Stavros Sachtouris | :param withHashFile: (bool)
|
133 | 4375e020 | Stavros Sachtouris |
|
134 | 4375e020 | Stavros Sachtouris | :param size: (int) size of data to upload
|
135 | 4375e020 | Stavros Sachtouris |
|
136 | 4375e020 | Stavros Sachtouris | :param etag: (str)
|
137 | 4375e020 | Stavros Sachtouris |
|
138 | 4375e020 | Stavros Sachtouris | :param content_encoding: (str)
|
139 | 4375e020 | Stavros Sachtouris |
|
140 | 4375e020 | Stavros Sachtouris | :param content_disposition: (str)
|
141 | 4375e020 | Stavros Sachtouris |
|
142 | 4375e020 | Stavros Sachtouris | :param content_type: (str)
|
143 | 4375e020 | Stavros Sachtouris |
|
144 | 4375e020 | Stavros Sachtouris | :param sharing: {'read':[user and/or grp names],
|
145 | 4375e020 | Stavros Sachtouris | 'write':[usr and/or grp names]}
|
146 | 4375e020 | Stavros Sachtouris |
|
147 | 4375e020 | Stavros Sachtouris | :param public: (bool)
|
148 | 3c216009 | Stavros Sachtouris |
|
149 | 3c216009 | Stavros Sachtouris | :returns: (dict) created object metadata
|
150 | 4375e020 | Stavros Sachtouris | """
|
151 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
152 | 65a45524 | Stavros Sachtouris | |
153 | 65a45524 | Stavros Sachtouris | if withHashFile:
|
154 | 65a45524 | Stavros Sachtouris | data = f.read() |
155 | 65a45524 | Stavros Sachtouris | try:
|
156 | 65a45524 | Stavros Sachtouris | import json |
157 | 65a45524 | Stavros Sachtouris | data = json.dumps(json.loads(data)) |
158 | 65a45524 | Stavros Sachtouris | except ValueError: |
159 | 24ff0a35 | Stavros Sachtouris | raise ClientError('"%s" is not json-formated' % f.name, 1) |
160 | 65a45524 | Stavros Sachtouris | except SyntaxError: |
161 | 24ff0a35 | Stavros Sachtouris | msg = '"%s" is not a valid hashmap file' % f.name
|
162 | 24ff0a35 | Stavros Sachtouris | raise ClientError(msg, 1) |
163 | 65a45524 | Stavros Sachtouris | f = StringIO(data) |
164 | 2a7292f1 | Stavros Sachtouris | else:
|
165 | 975270f2 | Stavros Sachtouris | data = f.read(size) if size else f.read() |
166 | 3c216009 | Stavros Sachtouris | r = self.object_put(
|
167 | 24ff0a35 | Stavros Sachtouris | obj, |
168 | 3dabe5d2 | Stavros Sachtouris | data=data, |
169 | 3dabe5d2 | Stavros Sachtouris | etag=etag, |
170 | 3dabe5d2 | Stavros Sachtouris | content_encoding=content_encoding, |
171 | 3dabe5d2 | Stavros Sachtouris | content_disposition=content_disposition, |
172 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
173 | 3dabe5d2 | Stavros Sachtouris | permissions=sharing, |
174 | 3dabe5d2 | Stavros Sachtouris | public=public, |
175 | 3dabe5d2 | Stavros Sachtouris | success=201)
|
176 | 3c216009 | Stavros Sachtouris | return r.headers
|
177 | 3dabe5d2 | Stavros Sachtouris | |
178 | 24ff0a35 | Stavros Sachtouris | def create_object_by_manifestation( |
179 | 24ff0a35 | Stavros Sachtouris | self, obj,
|
180 | 24ff0a35 | Stavros Sachtouris | etag=None,
|
181 | 24ff0a35 | Stavros Sachtouris | content_encoding=None,
|
182 | 24ff0a35 | Stavros Sachtouris | content_disposition=None,
|
183 | 24ff0a35 | Stavros Sachtouris | content_type=None,
|
184 | 24ff0a35 | Stavros Sachtouris | sharing=None,
|
185 | 24ff0a35 | Stavros Sachtouris | public=None):
|
186 | 4375e020 | Stavros Sachtouris | """
|
187 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
188 | 4375e020 | Stavros Sachtouris |
|
189 | 4375e020 | Stavros Sachtouris | :param etag: (str)
|
190 | 4375e020 | Stavros Sachtouris |
|
191 | 4375e020 | Stavros Sachtouris | :param content_encoding: (str)
|
192 | 4375e020 | Stavros Sachtouris |
|
193 | 4375e020 | Stavros Sachtouris | :param content_disposition: (str)
|
194 | 4375e020 | Stavros Sachtouris |
|
195 | 4375e020 | Stavros Sachtouris | :param content_type: (str)
|
196 | 4375e020 | Stavros Sachtouris |
|
197 | 4375e020 | Stavros Sachtouris | :param sharing: {'read':[user and/or grp names],
|
198 | 4375e020 | Stavros Sachtouris | 'write':[usr and/or grp names]}
|
199 | 4375e020 | Stavros Sachtouris |
|
200 | 4375e020 | Stavros Sachtouris | :param public: (bool)
|
201 | 3c216009 | Stavros Sachtouris |
|
202 | 3c216009 | Stavros Sachtouris | :returns: (dict) created object metadata
|
203 | 4375e020 | Stavros Sachtouris | """
|
204 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
205 | 3c216009 | Stavros Sachtouris | r = self.object_put(
|
206 | 24ff0a35 | Stavros Sachtouris | obj, |
207 | 3dabe5d2 | Stavros Sachtouris | content_length=0,
|
208 | 3dabe5d2 | Stavros Sachtouris | etag=etag, |
209 | 3dabe5d2 | Stavros Sachtouris | content_encoding=content_encoding, |
210 | 3dabe5d2 | Stavros Sachtouris | content_disposition=content_disposition, |
211 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
212 | 3dabe5d2 | Stavros Sachtouris | permissions=sharing, |
213 | 3dabe5d2 | Stavros Sachtouris | public=public, |
214 | 3dabe5d2 | Stavros Sachtouris | manifest='%s/%s' % (self.container, obj)) |
215 | 3c216009 | Stavros Sachtouris | return r.headers
|
216 | 3dabe5d2 | Stavros Sachtouris | |
217 | 4375e020 | Stavros Sachtouris | # upload_* auxiliary methods
|
218 | 9d502497 | Stavros Sachtouris | def _put_block_async(self, data, hash): |
219 | 4375e020 | Stavros Sachtouris | event = SilentEvent(method=self._put_block, data=data, hash=hash) |
220 | 4375e020 | Stavros Sachtouris | event.start() |
221 | 4375e020 | Stavros Sachtouris | return event
|
222 | 4375e020 | Stavros Sachtouris | |
223 | 4375e020 | Stavros Sachtouris | def _put_block(self, data, hash): |
224 | 24ff0a35 | Stavros Sachtouris | r = self.container_post(
|
225 | 24ff0a35 | Stavros Sachtouris | update=True,
|
226 | 4375e020 | Stavros Sachtouris | content_type='application/octet-stream',
|
227 | 4375e020 | Stavros Sachtouris | content_length=len(data),
|
228 | 4375e020 | Stavros Sachtouris | data=data, |
229 | 4375e020 | Stavros Sachtouris | format='json')
|
230 | 4375e020 | Stavros Sachtouris | assert r.json[0] == hash, 'Local hash does not match server' |
231 | 4375e020 | Stavros Sachtouris | |
232 | 76ebf97c | Stavros Sachtouris | def _get_file_block_info(self, fileobj, size=None, cache=None): |
233 | 76ebf97c | Stavros Sachtouris | """
|
234 | 76ebf97c | Stavros Sachtouris | :param fileobj: (file descriptor) source
|
235 | 76ebf97c | Stavros Sachtouris |
|
236 | 76ebf97c | Stavros Sachtouris | :param size: (int) size of data to upload from source
|
237 | 76ebf97c | Stavros Sachtouris |
|
238 | 76ebf97c | Stavros Sachtouris | :param cache: (dict) if provided, cache container info response to
|
239 | 76ebf97c | Stavros Sachtouris | avoid redundant calls
|
240 | 76ebf97c | Stavros Sachtouris | """
|
241 | 76ebf97c | Stavros Sachtouris | if isinstance(cache, dict): |
242 | 76ebf97c | Stavros Sachtouris | try:
|
243 | 76ebf97c | Stavros Sachtouris | meta = cache[self.container]
|
244 | 76ebf97c | Stavros Sachtouris | except KeyError: |
245 | 76ebf97c | Stavros Sachtouris | meta = self.get_container_info()
|
246 | 76ebf97c | Stavros Sachtouris | cache[self.container] = meta
|
247 | 76ebf97c | Stavros Sachtouris | else:
|
248 | 76ebf97c | Stavros Sachtouris | meta = self.get_container_info()
|
249 | 435008b6 | Stavros Sachtouris | blocksize = int(meta['x-container-block-size']) |
250 | 435008b6 | Stavros Sachtouris | blockhash = meta['x-container-block-hash']
|
251 | 64ab4c13 | Stavros Sachtouris | size = size if size is not None else fstat(fileobj.fileno()).st_size |
252 | 435008b6 | Stavros Sachtouris | nblocks = 1 + (size - 1) // blocksize |
253 | 64ab4c13 | Stavros Sachtouris | return (blocksize, blockhash, size, nblocks)
|
254 | 64ab4c13 | Stavros Sachtouris | |
255 | 9d502497 | Stavros Sachtouris | def _create_object_or_get_missing_hashes( |
256 | 24ff0a35 | Stavros Sachtouris | self, obj, json,
|
257 | 24ff0a35 | Stavros Sachtouris | size=None,
|
258 | 24ff0a35 | Stavros Sachtouris | format='json',
|
259 | 24ff0a35 | Stavros Sachtouris | hashmap=True,
|
260 | 24ff0a35 | Stavros Sachtouris | content_type=None,
|
261 | b349b84b | Stavros Sachtouris | if_etag_match=None,
|
262 | b349b84b | Stavros Sachtouris | if_etag_not_match=None,
|
263 | 24ff0a35 | Stavros Sachtouris | content_encoding=None,
|
264 | 24ff0a35 | Stavros Sachtouris | content_disposition=None,
|
265 | 24ff0a35 | Stavros Sachtouris | permissions=None,
|
266 | 24ff0a35 | Stavros Sachtouris | public=None,
|
267 | 24ff0a35 | Stavros Sachtouris | success=(201, 409)): |
268 | 24ff0a35 | Stavros Sachtouris | r = self.object_put(
|
269 | 24ff0a35 | Stavros Sachtouris | obj, |
270 | 3dabe5d2 | Stavros Sachtouris | format='json',
|
271 | 3dabe5d2 | Stavros Sachtouris | hashmap=True,
|
272 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
273 | 3dabe5d2 | Stavros Sachtouris | json=json, |
274 | b349b84b | Stavros Sachtouris | if_etag_match=if_etag_match, |
275 | b349b84b | Stavros Sachtouris | if_etag_not_match=if_etag_not_match, |
276 | 3dabe5d2 | Stavros Sachtouris | content_encoding=content_encoding, |
277 | 3dabe5d2 | Stavros Sachtouris | content_disposition=content_disposition, |
278 | 3dabe5d2 | Stavros Sachtouris | permissions=permissions, |
279 | 3dabe5d2 | Stavros Sachtouris | public=public, |
280 | 64ab4c13 | Stavros Sachtouris | success=success) |
281 | 3c216009 | Stavros Sachtouris | return (None if r.status_code == 201 else r.json), r.headers |
282 | 435008b6 | Stavros Sachtouris | |
283 | b349b84b | Stavros Sachtouris | def _calculate_blocks_for_upload( |
284 | 2005b18e | Stavros Sachtouris | self, blocksize, blockhash, size, nblocks, hashes, hmap, fileobj,
|
285 | 2005b18e | Stavros Sachtouris | hash_cb=None):
|
286 | 3dabe5d2 | Stavros Sachtouris | offset = 0
|
287 | 435008b6 | Stavros Sachtouris | if hash_cb:
|
288 | 435008b6 | Stavros Sachtouris | hash_gen = hash_cb(nblocks) |
289 | 435008b6 | Stavros Sachtouris | hash_gen.next() |
290 | 435008b6 | Stavros Sachtouris | |
291 | 435008b6 | Stavros Sachtouris | for i in range(nblocks): |
292 | 64ab4c13 | Stavros Sachtouris | block = fileobj.read(min(blocksize, size - offset))
|
293 | 435008b6 | Stavros Sachtouris | bytes = len(block)
|
294 | 4375e020 | Stavros Sachtouris | hash = _pithos_hash(block, blockhash) |
295 | 435008b6 | Stavros Sachtouris | hashes.append(hash)
|
296 | 5b263ba2 | Stavros Sachtouris | hmap[hash] = (offset, bytes) |
297 | 435008b6 | Stavros Sachtouris | offset += bytes
|
298 | 435008b6 | Stavros Sachtouris | if hash_cb:
|
299 | 435008b6 | Stavros Sachtouris | hash_gen.next() |
300 | fce31e83 | Stavros Sachtouris | msg = 'Failed to calculate uploaded blocks:'
|
301 | bcbf3cf0 | Stavros Sachtouris | ' Offset and object size do not match'
|
302 | fce31e83 | Stavros Sachtouris | assert offset == size, msg
|
303 | 435008b6 | Stavros Sachtouris | |
304 | 3e7d1e0e | Stavros Sachtouris | def _upload_missing_blocks(self, missing, hmap, fileobj, upload_gen=None): |
305 | 3e7d1e0e | Stavros Sachtouris | """upload missing blocks asynchronously"""
|
306 | 435008b6 | Stavros Sachtouris | |
307 | cad39033 | Stavros Sachtouris | self._init_thread_limit()
|
308 | e9abe82b | Stavros Sachtouris | |
309 | 435008b6 | Stavros Sachtouris | flying = [] |
310 | 7644c38e | Stavros Sachtouris | failures = [] |
311 | 435008b6 | Stavros Sachtouris | for hash in missing: |
312 | 5b263ba2 | Stavros Sachtouris | offset, bytes = hmap[hash]
|
313 | 64ab4c13 | Stavros Sachtouris | fileobj.seek(offset) |
314 | 64ab4c13 | Stavros Sachtouris | data = fileobj.read(bytes)
|
315 | 9d502497 | Stavros Sachtouris | r = self._put_block_async(data, hash) |
316 | 435008b6 | Stavros Sachtouris | flying.append(r) |
317 | 745d938b | Stavros Sachtouris | unfinished = self._watch_thread_limit(flying)
|
318 | 745d938b | Stavros Sachtouris | for thread in set(flying).difference(unfinished): |
319 | 7644c38e | Stavros Sachtouris | if thread.exception:
|
320 | 7644c38e | Stavros Sachtouris | failures.append(thread) |
321 | 24ff0a35 | Stavros Sachtouris | if isinstance( |
322 | 2005b18e | Stavros Sachtouris | thread.exception, |
323 | 2005b18e | Stavros Sachtouris | ClientError) and thread.exception.status == 502: |
324 | 2005b18e | Stavros Sachtouris | self.POOLSIZE = self._thread_limit |
325 | 7644c38e | Stavros Sachtouris | elif thread.isAlive():
|
326 | 745d938b | Stavros Sachtouris | flying.append(thread) |
327 | 3e7d1e0e | Stavros Sachtouris | elif upload_gen:
|
328 | 3e7d1e0e | Stavros Sachtouris | try:
|
329 | 3e7d1e0e | Stavros Sachtouris | upload_gen.next() |
330 | 3e7d1e0e | Stavros Sachtouris | except:
|
331 | 3e7d1e0e | Stavros Sachtouris | pass
|
332 | e02728f9 | Stavros Sachtouris | flying = unfinished |
333 | e02728f9 | Stavros Sachtouris | |
334 | e02728f9 | Stavros Sachtouris | for thread in flying: |
335 | e02728f9 | Stavros Sachtouris | thread.join() |
336 | 7644c38e | Stavros Sachtouris | if thread.exception:
|
337 | 7644c38e | Stavros Sachtouris | failures.append(thread) |
338 | 3e7d1e0e | Stavros Sachtouris | elif upload_gen:
|
339 | 3e7d1e0e | Stavros Sachtouris | try:
|
340 | 3e7d1e0e | Stavros Sachtouris | upload_gen.next() |
341 | 3e7d1e0e | Stavros Sachtouris | except:
|
342 | 3e7d1e0e | Stavros Sachtouris | pass
|
343 | 56f0908a | Stavros Sachtouris | |
344 | 7644c38e | Stavros Sachtouris | return [failure.kwargs['hash'] for failure in failures] |
345 | 3dabe5d2 | Stavros Sachtouris | |
346 | 24ff0a35 | Stavros Sachtouris | def upload_object( |
347 | 24ff0a35 | Stavros Sachtouris | self, obj, f,
|
348 | 24ff0a35 | Stavros Sachtouris | size=None,
|
349 | 24ff0a35 | Stavros Sachtouris | hash_cb=None,
|
350 | 24ff0a35 | Stavros Sachtouris | upload_cb=None,
|
351 | 24ff0a35 | Stavros Sachtouris | etag=None,
|
352 | e9ac514e | Stavros Sachtouris | if_etag_match=None,
|
353 | 524d9cdd | Stavros Sachtouris | if_not_exist=None,
|
354 | 24ff0a35 | Stavros Sachtouris | content_encoding=None,
|
355 | 24ff0a35 | Stavros Sachtouris | content_disposition=None,
|
356 | 24ff0a35 | Stavros Sachtouris | content_type=None,
|
357 | 24ff0a35 | Stavros Sachtouris | sharing=None,
|
358 | 76ebf97c | Stavros Sachtouris | public=None,
|
359 | 76ebf97c | Stavros Sachtouris | container_info_cache=None):
|
360 | 4375e020 | Stavros Sachtouris | """Upload an object using multiple connections (threads)
|
361 | 4375e020 | Stavros Sachtouris |
|
362 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
363 | 4375e020 | Stavros Sachtouris |
|
364 | 4375e020 | Stavros Sachtouris | :param f: open file descriptor (rb)
|
365 | 4375e020 | Stavros Sachtouris |
|
366 | 4375e020 | Stavros Sachtouris | :param hash_cb: optional progress.bar object for calculating hashes
|
367 | 4375e020 | Stavros Sachtouris |
|
368 | 4375e020 | Stavros Sachtouris | :param upload_cb: optional progress.bar object for uploading
|
369 | 4375e020 | Stavros Sachtouris |
|
370 | 4375e020 | Stavros Sachtouris | :param etag: (str)
|
371 | 4375e020 | Stavros Sachtouris |
|
372 | e9ac514e | Stavros Sachtouris | :param if_etag_match: (str) Push that value to if-match header at file
|
373 | e9ac514e | Stavros Sachtouris | creation
|
374 | e9ac514e | Stavros Sachtouris |
|
375 | 524d9cdd | Stavros Sachtouris | :param if_not_exist: (bool) If true, the file will be uploaded ONLY if
|
376 | 524d9cdd | Stavros Sachtouris | it does not exist remotely, otherwise the operation will fail.
|
377 | 524d9cdd | Stavros Sachtouris | Involves the case of an object with the same path is created while
|
378 | 524d9cdd | Stavros Sachtouris | the object is being uploaded.
|
379 | 524d9cdd | Stavros Sachtouris |
|
380 | 4375e020 | Stavros Sachtouris | :param content_encoding: (str)
|
381 | 4375e020 | Stavros Sachtouris |
|
382 | 4375e020 | Stavros Sachtouris | :param content_disposition: (str)
|
383 | 4375e020 | Stavros Sachtouris |
|
384 | 4375e020 | Stavros Sachtouris | :param content_type: (str)
|
385 | 4375e020 | Stavros Sachtouris |
|
386 | 4375e020 | Stavros Sachtouris | :param sharing: {'read':[user and/or grp names],
|
387 | 4375e020 | Stavros Sachtouris | 'write':[usr and/or grp names]}
|
388 | 4375e020 | Stavros Sachtouris |
|
389 | 4375e020 | Stavros Sachtouris | :param public: (bool)
|
390 | 76ebf97c | Stavros Sachtouris |
|
391 | 76ebf97c | Stavros Sachtouris | :param container_info_cache: (dict) if given, avoid redundant calls to
|
392 | 9dc6159f | Stavros Sachtouris | server for container info (block size and hash information)
|
393 | 4375e020 | Stavros Sachtouris | """
|
394 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
395 | 56f0908a | Stavros Sachtouris | |
396 | 14c72dbd | Stavros Sachtouris | block_info = ( |
397 | 14c72dbd | Stavros Sachtouris | blocksize, blockhash, size, nblocks) = self._get_file_block_info(
|
398 | 14c72dbd | Stavros Sachtouris | f, size, container_info_cache) |
399 | 64ab4c13 | Stavros Sachtouris | (hashes, hmap, offset) = ([], {}, 0)
|
400 | bcbf3cf0 | Stavros Sachtouris | if not content_type: |
401 | 3dabe5d2 | Stavros Sachtouris | content_type = 'application/octet-stream'
|
402 | 64ab4c13 | Stavros Sachtouris | |
403 | b349b84b | Stavros Sachtouris | self._calculate_blocks_for_upload(
|
404 | 24ff0a35 | Stavros Sachtouris | *block_info, |
405 | 3dabe5d2 | Stavros Sachtouris | hashes=hashes, |
406 | 3dabe5d2 | Stavros Sachtouris | hmap=hmap, |
407 | 3dabe5d2 | Stavros Sachtouris | fileobj=f, |
408 | 64ab4c13 | Stavros Sachtouris | hash_cb=hash_cb) |
409 | 64ab4c13 | Stavros Sachtouris | |
410 | 64ab4c13 | Stavros Sachtouris | hashmap = dict(bytes=size, hashes=hashes)
|
411 | 9d502497 | Stavros Sachtouris | missing, obj_headers = self._create_object_or_get_missing_hashes(
|
412 | 24ff0a35 | Stavros Sachtouris | obj, hashmap, |
413 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
414 | 3dabe5d2 | Stavros Sachtouris | size=size, |
415 | b349b84b | Stavros Sachtouris | if_etag_match=if_etag_match, |
416 | b349b84b | Stavros Sachtouris | if_etag_not_match='*' if if_not_exist else None, |
417 | 3dabe5d2 | Stavros Sachtouris | content_encoding=content_encoding, |
418 | 3dabe5d2 | Stavros Sachtouris | content_disposition=content_disposition, |
419 | 3dabe5d2 | Stavros Sachtouris | permissions=sharing, |
420 | 3dabe5d2 | Stavros Sachtouris | public=public) |
421 | 64ab4c13 | Stavros Sachtouris | |
422 | 64ab4c13 | Stavros Sachtouris | if missing is None: |
423 | 3c216009 | Stavros Sachtouris | return obj_headers
|
424 | 1d329d27 | Stavros Sachtouris | |
425 | 3e7d1e0e | Stavros Sachtouris | if upload_cb:
|
426 | 3e7d1e0e | Stavros Sachtouris | upload_gen = upload_cb(len(missing))
|
427 | 745d938b | Stavros Sachtouris | for i in range(len(missing), len(hashmap['hashes']) + 1): |
428 | 745d938b | Stavros Sachtouris | try:
|
429 | 745d938b | Stavros Sachtouris | upload_gen.next() |
430 | 745d938b | Stavros Sachtouris | except:
|
431 | 745d938b | Stavros Sachtouris | upload_gen = None
|
432 | 3e7d1e0e | Stavros Sachtouris | else:
|
433 | 3e7d1e0e | Stavros Sachtouris | upload_gen = None
|
434 | 3e7d1e0e | Stavros Sachtouris | |
435 | 7eda693f | Stavros Sachtouris | retries = 7
|
436 | f27ed9a0 | Stavros Sachtouris | try:
|
437 | 7644c38e | Stavros Sachtouris | while retries:
|
438 | 7eda693f | Stavros Sachtouris | sendlog.info('%s blocks missing' % len(missing)) |
439 | 7644c38e | Stavros Sachtouris | num_of_blocks = len(missing)
|
440 | 7644c38e | Stavros Sachtouris | missing = self._upload_missing_blocks(
|
441 | 7644c38e | Stavros Sachtouris | missing, |
442 | 7644c38e | Stavros Sachtouris | hmap, |
443 | 7644c38e | Stavros Sachtouris | f, |
444 | 3e7d1e0e | Stavros Sachtouris | upload_gen) |
445 | 16c895db | Stavros Sachtouris | if missing:
|
446 | 16c895db | Stavros Sachtouris | if num_of_blocks == len(missing): |
447 | 16c895db | Stavros Sachtouris | retries -= 1
|
448 | 16c895db | Stavros Sachtouris | else:
|
449 | 16c895db | Stavros Sachtouris | num_of_blocks = len(missing)
|
450 | 7644c38e | Stavros Sachtouris | else:
|
451 | 7644c38e | Stavros Sachtouris | break
|
452 | 7644c38e | Stavros Sachtouris | if missing:
|
453 | ecf0fc97 | Stavros Sachtouris | try:
|
454 | ecf0fc97 | Stavros Sachtouris | details = ['%s' % thread.exception for thread in missing] |
455 | ecf0fc97 | Stavros Sachtouris | except Exception: |
456 | 5c2058e7 | Stavros Sachtouris | details = ['Also, failed to read thread exceptions']
|
457 | 6fa30b1b | Stavros Sachtouris | raise ClientError(
|
458 | 6fa30b1b | Stavros Sachtouris | '%s blocks failed to upload' % len(missing), |
459 | ecf0fc97 | Stavros Sachtouris | details=details) |
460 | 9d502497 | Stavros Sachtouris | except KeyboardInterrupt: |
461 | 9d502497 | Stavros Sachtouris | sendlog.info('- - - wait for threads to finish')
|
462 | 9d502497 | Stavros Sachtouris | for thread in activethreads(): |
463 | 9d502497 | Stavros Sachtouris | thread.join() |
464 | 9d502497 | Stavros Sachtouris | raise
|
465 | 9d502497 | Stavros Sachtouris | |
466 | 9d502497 | Stavros Sachtouris | r = self.object_put(
|
467 | 9d502497 | Stavros Sachtouris | obj, |
468 | 9d502497 | Stavros Sachtouris | format='json',
|
469 | 9d502497 | Stavros Sachtouris | hashmap=True,
|
470 | 9d502497 | Stavros Sachtouris | content_type=content_type, |
471 | f8426b5c | Stavros Sachtouris | content_encoding=content_encoding, |
472 | 9d502497 | Stavros Sachtouris | if_etag_match=if_etag_match, |
473 | 9d502497 | Stavros Sachtouris | if_etag_not_match='*' if if_not_exist else None, |
474 | 9d502497 | Stavros Sachtouris | etag=etag, |
475 | 9d502497 | Stavros Sachtouris | json=hashmap, |
476 | 9d502497 | Stavros Sachtouris | permissions=sharing, |
477 | 9d502497 | Stavros Sachtouris | public=public, |
478 | 9d502497 | Stavros Sachtouris | success=201)
|
479 | 9d502497 | Stavros Sachtouris | return r.headers
|
480 | 9d502497 | Stavros Sachtouris | |
481 | 9d502497 | Stavros Sachtouris | def upload_from_string( |
482 | 9d502497 | Stavros Sachtouris | self, obj, input_str,
|
483 | 9d502497 | Stavros Sachtouris | hash_cb=None,
|
484 | 9d502497 | Stavros Sachtouris | upload_cb=None,
|
485 | 9d502497 | Stavros Sachtouris | etag=None,
|
486 | 9d502497 | Stavros Sachtouris | if_etag_match=None,
|
487 | 9d502497 | Stavros Sachtouris | if_not_exist=None,
|
488 | 9d502497 | Stavros Sachtouris | content_encoding=None,
|
489 | 9d502497 | Stavros Sachtouris | content_disposition=None,
|
490 | 9d502497 | Stavros Sachtouris | content_type=None,
|
491 | 9d502497 | Stavros Sachtouris | sharing=None,
|
492 | 9d502497 | Stavros Sachtouris | public=None,
|
493 | 9d502497 | Stavros Sachtouris | container_info_cache=None):
|
494 | 9d502497 | Stavros Sachtouris | """Upload an object using multiple connections (threads)
|
495 | 9d502497 | Stavros Sachtouris |
|
496 | 9d502497 | Stavros Sachtouris | :param obj: (str) remote object path
|
497 | 9d502497 | Stavros Sachtouris |
|
498 | 9d502497 | Stavros Sachtouris | :param input_str: (str) upload content
|
499 | 9d502497 | Stavros Sachtouris |
|
500 | 9d502497 | Stavros Sachtouris | :param hash_cb: optional progress.bar object for calculating hashes
|
501 | 9d502497 | Stavros Sachtouris |
|
502 | 9d502497 | Stavros Sachtouris | :param upload_cb: optional progress.bar object for uploading
|
503 | 9d502497 | Stavros Sachtouris |
|
504 | 9d502497 | Stavros Sachtouris | :param etag: (str)
|
505 | 9d502497 | Stavros Sachtouris |
|
506 | 9d502497 | Stavros Sachtouris | :param if_etag_match: (str) Push that value to if-match header at file
|
507 | 9d502497 | Stavros Sachtouris | creation
|
508 | 9d502497 | Stavros Sachtouris |
|
509 | 9d502497 | Stavros Sachtouris | :param if_not_exist: (bool) If true, the file will be uploaded ONLY if
|
510 | 9d502497 | Stavros Sachtouris | it does not exist remotely, otherwise the operation will fail.
|
511 | 9d502497 | Stavros Sachtouris | Involves the case of an object with the same path is created while
|
512 | 9d502497 | Stavros Sachtouris | the object is being uploaded.
|
513 | 9d502497 | Stavros Sachtouris |
|
514 | 9d502497 | Stavros Sachtouris | :param content_encoding: (str)
|
515 | 9d502497 | Stavros Sachtouris |
|
516 | 9d502497 | Stavros Sachtouris | :param content_disposition: (str)
|
517 | 9d502497 | Stavros Sachtouris |
|
518 | 9d502497 | Stavros Sachtouris | :param content_type: (str)
|
519 | 9d502497 | Stavros Sachtouris |
|
520 | 9d502497 | Stavros Sachtouris | :param sharing: {'read':[user and/or grp names],
|
521 | 9d502497 | Stavros Sachtouris | 'write':[usr and/or grp names]}
|
522 | 9d502497 | Stavros Sachtouris |
|
523 | 9d502497 | Stavros Sachtouris | :param public: (bool)
|
524 | 9d502497 | Stavros Sachtouris |
|
525 | 9d502497 | Stavros Sachtouris | :param container_info_cache: (dict) if given, avoid redundant calls to
|
526 | 9dc6159f | Stavros Sachtouris | server for container info (block size and hash information)
|
527 | 9d502497 | Stavros Sachtouris | """
|
528 | 9d502497 | Stavros Sachtouris | self._assert_container()
|
529 | 9d502497 | Stavros Sachtouris | |
530 | 9d502497 | Stavros Sachtouris | blocksize, blockhash, size, nblocks = self._get_file_block_info(
|
531 | 9d502497 | Stavros Sachtouris | fileobj=None, size=len(input_str), cache=container_info_cache) |
532 | 9d502497 | Stavros Sachtouris | (hashes, hmap, offset) = ([], {}, 0)
|
533 | 9d502497 | Stavros Sachtouris | if not content_type: |
534 | 9d502497 | Stavros Sachtouris | content_type = 'application/octet-stream'
|
535 | 9d502497 | Stavros Sachtouris | |
536 | 6fa30b1b | Stavros Sachtouris | hashes = [] |
537 | 9d502497 | Stavros Sachtouris | hmap = {} |
538 | f17121cd | Stavros Sachtouris | for blockid in range(nblocks): |
539 | 9d502497 | Stavros Sachtouris | start = blockid * blocksize |
540 | 9d502497 | Stavros Sachtouris | block = input_str[start: (start + blocksize)] |
541 | 6fa30b1b | Stavros Sachtouris | hashes.append(_pithos_hash(block, blockhash)) |
542 | 9d502497 | Stavros Sachtouris | hmap[hashes[blockid]] = (start, block) |
543 | 9d502497 | Stavros Sachtouris | |
544 | 9d502497 | Stavros Sachtouris | hashmap = dict(bytes=size, hashes=hashes)
|
545 | 9d502497 | Stavros Sachtouris | missing, obj_headers = self._create_object_or_get_missing_hashes(
|
546 | 9d502497 | Stavros Sachtouris | obj, hashmap, |
547 | 9d502497 | Stavros Sachtouris | content_type=content_type, |
548 | 9d502497 | Stavros Sachtouris | size=size, |
549 | 9d502497 | Stavros Sachtouris | if_etag_match=if_etag_match, |
550 | 9d502497 | Stavros Sachtouris | if_etag_not_match='*' if if_not_exist else None, |
551 | 9d502497 | Stavros Sachtouris | content_encoding=content_encoding, |
552 | 9d502497 | Stavros Sachtouris | content_disposition=content_disposition, |
553 | 9d502497 | Stavros Sachtouris | permissions=sharing, |
554 | 9d502497 | Stavros Sachtouris | public=public) |
555 | 9d502497 | Stavros Sachtouris | if missing is None: |
556 | 9d502497 | Stavros Sachtouris | return obj_headers
|
557 | 9d502497 | Stavros Sachtouris | num_of_missing = len(missing)
|
558 | 9d502497 | Stavros Sachtouris | |
559 | 9d502497 | Stavros Sachtouris | if upload_cb:
|
560 | f17121cd | Stavros Sachtouris | self.progress_bar_gen = upload_cb(nblocks)
|
561 | f17121cd | Stavros Sachtouris | for i in range(nblocks + 1 - num_of_missing): |
562 | 9d502497 | Stavros Sachtouris | self._cb_next()
|
563 | 9d502497 | Stavros Sachtouris | |
564 | 6fa30b1b | Stavros Sachtouris | tries = 7
|
565 | 6fa30b1b | Stavros Sachtouris | old_failures = 0
|
566 | 9d502497 | Stavros Sachtouris | try:
|
567 | 6fa30b1b | Stavros Sachtouris | while tries and missing: |
568 | 6fa30b1b | Stavros Sachtouris | flying = [] |
569 | 6fa30b1b | Stavros Sachtouris | failures = [] |
570 | 6fa30b1b | Stavros Sachtouris | for hash in missing: |
571 | 6fa30b1b | Stavros Sachtouris | offset, block = hmap[hash]
|
572 | 6fa30b1b | Stavros Sachtouris | bird = self._put_block_async(block, hash) |
573 | 6fa30b1b | Stavros Sachtouris | flying.append(bird) |
574 | 6fa30b1b | Stavros Sachtouris | unfinished = self._watch_thread_limit(flying)
|
575 | 6fa30b1b | Stavros Sachtouris | for thread in set(flying).difference(unfinished): |
576 | 6fa30b1b | Stavros Sachtouris | if thread.exception:
|
577 | 6fa30b1b | Stavros Sachtouris | failures.append(thread.kwargs['hash'])
|
578 | 6fa30b1b | Stavros Sachtouris | if thread.isAlive():
|
579 | 6fa30b1b | Stavros Sachtouris | flying.append(thread) |
580 | 6fa30b1b | Stavros Sachtouris | else:
|
581 | 6fa30b1b | Stavros Sachtouris | self._cb_next()
|
582 | 6fa30b1b | Stavros Sachtouris | flying = unfinished |
583 | 6fa30b1b | Stavros Sachtouris | for thread in flying: |
584 | 6fa30b1b | Stavros Sachtouris | thread.join() |
585 | 9d502497 | Stavros Sachtouris | if thread.exception:
|
586 | 6fa30b1b | Stavros Sachtouris | failures.append(thread.kwargs['hash'])
|
587 | 6fa30b1b | Stavros Sachtouris | self._cb_next()
|
588 | 6fa30b1b | Stavros Sachtouris | missing = failures |
589 | 6fa30b1b | Stavros Sachtouris | if missing and len(missing) == old_failures: |
590 | 6fa30b1b | Stavros Sachtouris | tries -= 1
|
591 | 6fa30b1b | Stavros Sachtouris | old_failures = len(missing)
|
592 | 6fa30b1b | Stavros Sachtouris | if missing:
|
593 | 6fa30b1b | Stavros Sachtouris | raise ClientError(
|
594 | 6fa30b1b | Stavros Sachtouris | '%s blocks failed to upload' % len(missing), |
595 | 6fa30b1b | Stavros Sachtouris | details=['%s' % thread.exception for thread in missing]) |
596 | f27ed9a0 | Stavros Sachtouris | except KeyboardInterrupt: |
597 | 6069b53b | Stavros Sachtouris | sendlog.info('- - - wait for threads to finish')
|
598 | f27ed9a0 | Stavros Sachtouris | for thread in activethreads(): |
599 | f27ed9a0 | Stavros Sachtouris | thread.join() |
600 | f27ed9a0 | Stavros Sachtouris | raise
|
601 | f27ed9a0 | Stavros Sachtouris | |
602 | 3c216009 | Stavros Sachtouris | r = self.object_put(
|
603 | f27ed9a0 | Stavros Sachtouris | obj, |
604 | 3dabe5d2 | Stavros Sachtouris | format='json',
|
605 | 3dabe5d2 | Stavros Sachtouris | hashmap=True,
|
606 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
607 | 5c2058e7 | Stavros Sachtouris | content_encoding=content_encoding, |
608 | e9ac514e | Stavros Sachtouris | if_etag_match=if_etag_match, |
609 | 524d9cdd | Stavros Sachtouris | if_etag_not_match='*' if if_not_exist else None, |
610 | 524d9cdd | Stavros Sachtouris | etag=etag, |
611 | 3dabe5d2 | Stavros Sachtouris | json=hashmap, |
612 | 50165863 | Stavros Sachtouris | permissions=sharing, |
613 | 50165863 | Stavros Sachtouris | public=public, |
614 | 3dabe5d2 | Stavros Sachtouris | success=201)
|
615 | 3c216009 | Stavros Sachtouris | return r.headers
|
616 | 3dabe5d2 | Stavros Sachtouris | |
617 | f27ed9a0 | Stavros Sachtouris | # download_* auxiliary methods
|
618 | fbfee225 | Stavros Sachtouris | def _get_remote_blocks_info(self, obj, **restargs): |
619 | 56f0908a | Stavros Sachtouris | #retrieve object hashmap
|
620 | 3dabe5d2 | Stavros Sachtouris | myrange = restargs.pop('data_range', None) |
621 | 319be41b | Stavros Sachtouris | hashmap = self.get_object_hashmap(obj, **restargs)
|
622 | 642f1bbd | Stavros Sachtouris | restargs['data_range'] = myrange
|
623 | 56f0908a | Stavros Sachtouris | blocksize = int(hashmap['block_size']) |
624 | 56f0908a | Stavros Sachtouris | blockhash = hashmap['block_hash']
|
625 | 56f0908a | Stavros Sachtouris | total_size = hashmap['bytes']
|
626 | fbfee225 | Stavros Sachtouris | #assert total_size/blocksize + 1 == len(hashmap['hashes'])
|
627 | 56f0908a | Stavros Sachtouris | map_dict = {} |
628 | fbfee225 | Stavros Sachtouris | for i, h in enumerate(hashmap['hashes']): |
629 | ca7f78c0 | Stavros Sachtouris | # map_dict[h] = i CHAGE
|
630 | ca7f78c0 | Stavros Sachtouris | if h in map_dict: |
631 | ca7f78c0 | Stavros Sachtouris | map_dict[h].append(i) |
632 | ca7f78c0 | Stavros Sachtouris | else:
|
633 | ca7f78c0 | Stavros Sachtouris | map_dict[h] = [i] |
634 | fbfee225 | Stavros Sachtouris | return (blocksize, blockhash, total_size, hashmap['hashes'], map_dict) |
635 | 64ab4c13 | Stavros Sachtouris | |
636 | 24ff0a35 | Stavros Sachtouris | def _dump_blocks_sync( |
637 | 7806f19d | Stavros Sachtouris | self, obj, remote_hashes, blocksize, total_size, dst, crange,
|
638 | 24ff0a35 | Stavros Sachtouris | **args): |
639 | fbfee225 | Stavros Sachtouris | for blockid, blockhash in enumerate(remote_hashes): |
640 | 24ff0a35 | Stavros Sachtouris | if blockhash:
|
641 | 24ff0a35 | Stavros Sachtouris | start = blocksize * blockid |
642 | 24ff0a35 | Stavros Sachtouris | is_last = start + blocksize > total_size |
643 | 24ff0a35 | Stavros Sachtouris | end = (total_size - 1) if is_last else (start + blocksize - 1) |
644 | 7806f19d | Stavros Sachtouris | (start, end) = _range_up(start, end, crange) |
645 | 6e50fed4 | Stavros Sachtouris | args['data_range'] = 'bytes=%s-%s' % ( |
646 | 6e50fed4 | Stavros Sachtouris | (start, end) if end >= 0 else ('', - end)) |
647 | 24ff0a35 | Stavros Sachtouris | r = self.object_get(obj, success=(200, 206), **args) |
648 | 24ff0a35 | Stavros Sachtouris | self._cb_next()
|
649 | 24ff0a35 | Stavros Sachtouris | dst.write(r.content) |
650 | 24ff0a35 | Stavros Sachtouris | dst.flush() |
651 | fbfee225 | Stavros Sachtouris | |
652 | 24ff0a35 | Stavros Sachtouris | def _get_block_async(self, obj, **args): |
653 | 24ff0a35 | Stavros Sachtouris | event = SilentEvent(self.object_get, obj, success=(200, 206), **args) |
654 | e02728f9 | Stavros Sachtouris | event.start() |
655 | e02728f9 | Stavros Sachtouris | return event
|
656 | fb0cd49a | Stavros Sachtouris | |
657 | 48c3782c | Stavros Sachtouris | def _hash_from_file(self, fp, start, size, blockhash): |
658 | 48c3782c | Stavros Sachtouris | fp.seek(start) |
659 | 48c3782c | Stavros Sachtouris | block = fp.read(size) |
660 | 48c3782c | Stavros Sachtouris | h = newhashlib(blockhash) |
661 | 48c3782c | Stavros Sachtouris | h.update(block.strip('\x00'))
|
662 | 48c3782c | Stavros Sachtouris | return hexlify(h.digest())
|
663 | 48c3782c | Stavros Sachtouris | |
664 | 28cbc3c2 | Stavros Sachtouris | def _thread2file(self, flying, blockids, local_file, offset=0, **restargs): |
665 | 22fc09fb | Stavros Sachtouris | """write the results of a greenleted rest call to a file
|
666 | f5f2dc53 | Stavros Sachtouris |
|
667 | f5f2dc53 | Stavros Sachtouris | :param offset: the offset of the file up to blocksize
|
668 | f5f2dc53 | Stavros Sachtouris | - e.g. if the range is 10-100, all blocks will be written to
|
669 | f5f2dc53 | Stavros Sachtouris | normal_position - 10
|
670 | f5f2dc53 | Stavros Sachtouris | """
|
671 | 0fbc8a52 | Stavros Sachtouris | for key, g in flying.items(): |
672 | 28cbc3c2 | Stavros Sachtouris | if g.isAlive():
|
673 | 28cbc3c2 | Stavros Sachtouris | continue
|
674 | 28cbc3c2 | Stavros Sachtouris | if g.exception:
|
675 | 28cbc3c2 | Stavros Sachtouris | raise g.exception
|
676 | 28cbc3c2 | Stavros Sachtouris | block = g.value.content |
677 | 28cbc3c2 | Stavros Sachtouris | for block_start in blockids[key]: |
678 | 28cbc3c2 | Stavros Sachtouris | local_file.seek(block_start + offset) |
679 | fbfee225 | Stavros Sachtouris | local_file.write(block) |
680 | fbfee225 | Stavros Sachtouris | self._cb_next()
|
681 | 28cbc3c2 | Stavros Sachtouris | flying.pop(key) |
682 | 28cbc3c2 | Stavros Sachtouris | blockids.pop(key) |
683 | fbfee225 | Stavros Sachtouris | local_file.flush() |
684 | fbfee225 | Stavros Sachtouris | |
685 | 24ff0a35 | Stavros Sachtouris | def _dump_blocks_async( |
686 | 24ff0a35 | Stavros Sachtouris | self, obj, remote_hashes, blocksize, total_size, local_file,
|
687 | 24ff0a35 | Stavros Sachtouris | blockhash=None, resume=False, filerange=None, **restargs): |
688 | 973fbcad | Stavros Sachtouris | file_size = fstat(local_file.fileno()).st_size if resume else 0 |
689 | 28cbc3c2 | Stavros Sachtouris | flying = dict()
|
690 | 28cbc3c2 | Stavros Sachtouris | blockid_dict = dict()
|
691 | 22fc09fb | Stavros Sachtouris | offset = 0
|
692 | 22fc09fb | Stavros Sachtouris | if filerange is not None: |
693 | 22fc09fb | Stavros Sachtouris | rstart = int(filerange.split('-')[0]) |
694 | 3dabe5d2 | Stavros Sachtouris | offset = rstart if blocksize > rstart else rstart % blocksize |
695 | f27ed9a0 | Stavros Sachtouris | |
696 | cad39033 | Stavros Sachtouris | self._init_thread_limit()
|
697 | ca7f78c0 | Stavros Sachtouris | for block_hash, blockids in remote_hashes.items(): |
698 | 28cbc3c2 | Stavros Sachtouris | blockids = [blk * blocksize for blk in blockids] |
699 | 28cbc3c2 | Stavros Sachtouris | unsaved = [blk for blk in blockids if not ( |
700 | 28cbc3c2 | Stavros Sachtouris | blk < file_size and block_hash == self._hash_from_file( |
701 | 28cbc3c2 | Stavros Sachtouris | local_file, blk, blocksize, blockhash))] |
702 | 28cbc3c2 | Stavros Sachtouris | self._cb_next(len(blockids) - len(unsaved)) |
703 | 28cbc3c2 | Stavros Sachtouris | if unsaved:
|
704 | 28cbc3c2 | Stavros Sachtouris | key = unsaved[0]
|
705 | ca7f78c0 | Stavros Sachtouris | self._watch_thread_limit(flying.values())
|
706 | 28cbc3c2 | Stavros Sachtouris | self._thread2file(
|
707 | 28cbc3c2 | Stavros Sachtouris | flying, blockid_dict, local_file, offset, |
708 | ca7f78c0 | Stavros Sachtouris | **restargs) |
709 | 0fbc8a52 | Stavros Sachtouris | end = total_size - 1 if ( |
710 | 0fbc8a52 | Stavros Sachtouris | key + blocksize > total_size) else key + blocksize - 1 |
711 | 28cbc3c2 | Stavros Sachtouris | start, end = _range_up(key, end, filerange) |
712 | ca7f78c0 | Stavros Sachtouris | if start == end:
|
713 | ca7f78c0 | Stavros Sachtouris | self._cb_next()
|
714 | ca7f78c0 | Stavros Sachtouris | continue
|
715 | ca7f78c0 | Stavros Sachtouris | restargs['async_headers'] = {
|
716 | 6e50fed4 | Stavros Sachtouris | 'Range': 'bytes=%s-%s' % ( |
717 | 6e50fed4 | Stavros Sachtouris | (start, end) if end >= 0 else ('', - end))} |
718 | 28cbc3c2 | Stavros Sachtouris | flying[key] = self._get_block_async(obj, **restargs)
|
719 | 28cbc3c2 | Stavros Sachtouris | blockid_dict[key] = unsaved |
720 | fbfee225 | Stavros Sachtouris | |
721 | e02728f9 | Stavros Sachtouris | for thread in flying.values(): |
722 | e02728f9 | Stavros Sachtouris | thread.join() |
723 | 28cbc3c2 | Stavros Sachtouris | self._thread2file(flying, blockid_dict, local_file, offset, **restargs)
|
724 | fbfee225 | Stavros Sachtouris | |
725 | 24ff0a35 | Stavros Sachtouris | def download_object( |
726 | 24ff0a35 | Stavros Sachtouris | self, obj, dst,
|
727 | 24ff0a35 | Stavros Sachtouris | download_cb=None,
|
728 | 24ff0a35 | Stavros Sachtouris | version=None,
|
729 | 24ff0a35 | Stavros Sachtouris | resume=False,
|
730 | 24ff0a35 | Stavros Sachtouris | range_str=None,
|
731 | 24ff0a35 | Stavros Sachtouris | if_match=None,
|
732 | 24ff0a35 | Stavros Sachtouris | if_none_match=None,
|
733 | 24ff0a35 | Stavros Sachtouris | if_modified_since=None,
|
734 | 24ff0a35 | Stavros Sachtouris | if_unmodified_since=None):
|
735 | f5f2dc53 | Stavros Sachtouris | """Download an object (multiple connections, random blocks)
|
736 | 4375e020 | Stavros Sachtouris |
|
737 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
738 | 4375e020 | Stavros Sachtouris |
|
739 | 4375e020 | Stavros Sachtouris | :param dst: open file descriptor (wb+)
|
740 | 4375e020 | Stavros Sachtouris |
|
741 | 4375e020 | Stavros Sachtouris | :param download_cb: optional progress.bar object for downloading
|
742 | 4375e020 | Stavros Sachtouris |
|
743 | 4375e020 | Stavros Sachtouris | :param version: (str) file version
|
744 | 4375e020 | Stavros Sachtouris |
|
745 | 4375e020 | Stavros Sachtouris | :param resume: (bool) if set, preserve already downloaded file parts
|
746 | 4375e020 | Stavros Sachtouris |
|
747 | f5f2dc53 | Stavros Sachtouris | :param range_str: (str) from, to are file positions (int) in bytes
|
748 | 4375e020 | Stavros Sachtouris |
|
749 | 4375e020 | Stavros Sachtouris | :param if_match: (str)
|
750 | 4375e020 | Stavros Sachtouris |
|
751 | 4375e020 | Stavros Sachtouris | :param if_none_match: (str)
|
752 | 4375e020 | Stavros Sachtouris |
|
753 | 4375e020 | Stavros Sachtouris | :param if_modified_since: (str) formated date
|
754 | 4375e020 | Stavros Sachtouris |
|
755 | f5f2dc53 | Stavros Sachtouris | :param if_unmodified_since: (str) formated date"""
|
756 | 24ff0a35 | Stavros Sachtouris | restargs = dict(
|
757 | 24ff0a35 | Stavros Sachtouris | version=version, |
758 | 24ff0a35 | Stavros Sachtouris | data_range=None if range_str is None else 'bytes=%s' % range_str, |
759 | fbfee225 | Stavros Sachtouris | if_match=if_match, |
760 | fbfee225 | Stavros Sachtouris | if_none_match=if_none_match, |
761 | fbfee225 | Stavros Sachtouris | if_modified_since=if_modified_since, |
762 | fbfee225 | Stavros Sachtouris | if_unmodified_since=if_unmodified_since) |
763 | fbfee225 | Stavros Sachtouris | |
764 | 24ff0a35 | Stavros Sachtouris | ( |
765 | 24ff0a35 | Stavros Sachtouris | blocksize, |
766 | fbfee225 | Stavros Sachtouris | blockhash, |
767 | fbfee225 | Stavros Sachtouris | total_size, |
768 | 3dabe5d2 | Stavros Sachtouris | hash_list, |
769 | fbfee225 | Stavros Sachtouris | remote_hashes) = self._get_remote_blocks_info(obj, **restargs)
|
770 | fbfee225 | Stavros Sachtouris | assert total_size >= 0 |
771 | fbfee225 | Stavros Sachtouris | |
772 | fbfee225 | Stavros Sachtouris | if download_cb:
|
773 | ca7f78c0 | Stavros Sachtouris | self.progress_bar_gen = download_cb(len(hash_list)) |
774 | fbfee225 | Stavros Sachtouris | self._cb_next()
|
775 | fbfee225 | Stavros Sachtouris | |
776 | fbfee225 | Stavros Sachtouris | if dst.isatty():
|
777 | 24ff0a35 | Stavros Sachtouris | self._dump_blocks_sync(
|
778 | 24ff0a35 | Stavros Sachtouris | obj, |
779 | 3dabe5d2 | Stavros Sachtouris | hash_list, |
780 | 3dabe5d2 | Stavros Sachtouris | blocksize, |
781 | 3dabe5d2 | Stavros Sachtouris | total_size, |
782 | 3dabe5d2 | Stavros Sachtouris | dst, |
783 | 24ff0a35 | Stavros Sachtouris | range_str, |
784 | 3dabe5d2 | Stavros Sachtouris | **restargs) |
785 | 699d3bb1 | Stavros Sachtouris | else:
|
786 | 24ff0a35 | Stavros Sachtouris | self._dump_blocks_async(
|
787 | 24ff0a35 | Stavros Sachtouris | obj, |
788 | 3dabe5d2 | Stavros Sachtouris | remote_hashes, |
789 | 3dabe5d2 | Stavros Sachtouris | blocksize, |
790 | 3dabe5d2 | Stavros Sachtouris | total_size, |
791 | 3dabe5d2 | Stavros Sachtouris | dst, |
792 | 3dabe5d2 | Stavros Sachtouris | blockhash, |
793 | 3dabe5d2 | Stavros Sachtouris | resume, |
794 | 24ff0a35 | Stavros Sachtouris | range_str, |
795 | 3dabe5d2 | Stavros Sachtouris | **restargs) |
796 | 24ff0a35 | Stavros Sachtouris | if not range_str: |
797 | 22fc09fb | Stavros Sachtouris | dst.truncate(total_size) |
798 | 5b263ba2 | Stavros Sachtouris | |
799 | fbfee225 | Stavros Sachtouris | self._complete_cb()
|
800 | fbfee225 | Stavros Sachtouris | |
801 | 49cc29b2 | Stavros Sachtouris | def download_to_string( |
802 | 49cc29b2 | Stavros Sachtouris | self, obj,
|
803 | 49cc29b2 | Stavros Sachtouris | download_cb=None,
|
804 | 49cc29b2 | Stavros Sachtouris | version=None,
|
805 | 49cc29b2 | Stavros Sachtouris | range_str=None,
|
806 | 49cc29b2 | Stavros Sachtouris | if_match=None,
|
807 | 49cc29b2 | Stavros Sachtouris | if_none_match=None,
|
808 | 49cc29b2 | Stavros Sachtouris | if_modified_since=None,
|
809 | 49cc29b2 | Stavros Sachtouris | if_unmodified_since=None):
|
810 | 0fbc8a52 | Stavros Sachtouris | """Download an object to a string (multiple connections). This method
|
811 | 0fbc8a52 | Stavros Sachtouris | uses threads for http requests, but stores all content in memory.
|
812 | 49cc29b2 | Stavros Sachtouris |
|
813 | 49cc29b2 | Stavros Sachtouris | :param obj: (str) remote object path
|
814 | 49cc29b2 | Stavros Sachtouris |
|
815 | 49cc29b2 | Stavros Sachtouris | :param download_cb: optional progress.bar object for downloading
|
816 | 49cc29b2 | Stavros Sachtouris |
|
817 | 49cc29b2 | Stavros Sachtouris | :param version: (str) file version
|
818 | 49cc29b2 | Stavros Sachtouris |
|
819 | 49cc29b2 | Stavros Sachtouris | :param range_str: (str) from, to are file positions (int) in bytes
|
820 | 49cc29b2 | Stavros Sachtouris |
|
821 | 49cc29b2 | Stavros Sachtouris | :param if_match: (str)
|
822 | 49cc29b2 | Stavros Sachtouris |
|
823 | 49cc29b2 | Stavros Sachtouris | :param if_none_match: (str)
|
824 | 49cc29b2 | Stavros Sachtouris |
|
825 | 49cc29b2 | Stavros Sachtouris | :param if_modified_since: (str) formated date
|
826 | 49cc29b2 | Stavros Sachtouris |
|
827 | 49cc29b2 | Stavros Sachtouris | :param if_unmodified_since: (str) formated date
|
828 | 49cc29b2 | Stavros Sachtouris |
|
829 | 49cc29b2 | Stavros Sachtouris | :returns: (str) the whole object contents
|
830 | 49cc29b2 | Stavros Sachtouris | """
|
831 | 49cc29b2 | Stavros Sachtouris | restargs = dict(
|
832 | 49cc29b2 | Stavros Sachtouris | version=version, |
833 | 49cc29b2 | Stavros Sachtouris | data_range=None if range_str is None else 'bytes=%s' % range_str, |
834 | 49cc29b2 | Stavros Sachtouris | if_match=if_match, |
835 | 49cc29b2 | Stavros Sachtouris | if_none_match=if_none_match, |
836 | 49cc29b2 | Stavros Sachtouris | if_modified_since=if_modified_since, |
837 | 49cc29b2 | Stavros Sachtouris | if_unmodified_since=if_unmodified_since) |
838 | 49cc29b2 | Stavros Sachtouris | |
839 | 49cc29b2 | Stavros Sachtouris | ( |
840 | 49cc29b2 | Stavros Sachtouris | blocksize, |
841 | 49cc29b2 | Stavros Sachtouris | blockhash, |
842 | 49cc29b2 | Stavros Sachtouris | total_size, |
843 | 49cc29b2 | Stavros Sachtouris | hash_list, |
844 | 49cc29b2 | Stavros Sachtouris | remote_hashes) = self._get_remote_blocks_info(obj, **restargs)
|
845 | 49cc29b2 | Stavros Sachtouris | assert total_size >= 0 |
846 | 49cc29b2 | Stavros Sachtouris | |
847 | 49cc29b2 | Stavros Sachtouris | if download_cb:
|
848 | 49cc29b2 | Stavros Sachtouris | self.progress_bar_gen = download_cb(len(hash_list)) |
849 | 49cc29b2 | Stavros Sachtouris | self._cb_next()
|
850 | 49cc29b2 | Stavros Sachtouris | |
851 | 0fbc8a52 | Stavros Sachtouris | num_of_blocks = len(remote_hashes)
|
852 | 0fbc8a52 | Stavros Sachtouris | ret = [''] * num_of_blocks
|
853 | 0fbc8a52 | Stavros Sachtouris | self._init_thread_limit()
|
854 | 0fbc8a52 | Stavros Sachtouris | flying = dict()
|
855 | 5655d560 | Stavros Sachtouris | try:
|
856 | 5655d560 | Stavros Sachtouris | for blockid, blockhash in enumerate(remote_hashes): |
857 | 5655d560 | Stavros Sachtouris | start = blocksize * blockid |
858 | 5655d560 | Stavros Sachtouris | is_last = start + blocksize > total_size |
859 | 5655d560 | Stavros Sachtouris | end = (total_size - 1) if is_last else (start + blocksize - 1) |
860 | 5655d560 | Stavros Sachtouris | (start, end) = _range_up(start, end, range_str) |
861 | 6e50fed4 | Stavros Sachtouris | if start < end or end < 0: |
862 | 5655d560 | Stavros Sachtouris | self._watch_thread_limit(flying.values())
|
863 | 5655d560 | Stavros Sachtouris | flying[blockid] = self._get_block_async(obj, **restargs)
|
864 | 5655d560 | Stavros Sachtouris | for runid, thread in flying.items(): |
865 | 5655d560 | Stavros Sachtouris | if (blockid + 1) == num_of_blocks: |
866 | 5655d560 | Stavros Sachtouris | thread.join() |
867 | 5655d560 | Stavros Sachtouris | elif thread.isAlive():
|
868 | 5655d560 | Stavros Sachtouris | continue
|
869 | 5655d560 | Stavros Sachtouris | if thread.exception:
|
870 | 5655d560 | Stavros Sachtouris | raise thread.exception
|
871 | 5655d560 | Stavros Sachtouris | ret[runid] = thread.value.content |
872 | 5655d560 | Stavros Sachtouris | self._cb_next()
|
873 | 5655d560 | Stavros Sachtouris | flying.pop(runid) |
874 | 5655d560 | Stavros Sachtouris | return ''.join(ret) |
875 | 5655d560 | Stavros Sachtouris | except KeyboardInterrupt: |
876 | 5655d560 | Stavros Sachtouris | sendlog.info('- - - wait for threads to finish')
|
877 | 5655d560 | Stavros Sachtouris | for thread in activethreads(): |
878 | 5655d560 | Stavros Sachtouris | thread.join() |
879 | 49cc29b2 | Stavros Sachtouris | |
880 | fbfee225 | Stavros Sachtouris | #Command Progress Bar method
|
881 | 28cbc3c2 | Stavros Sachtouris | def _cb_next(self, step=1): |
882 | fbfee225 | Stavros Sachtouris | if hasattr(self, 'progress_bar_gen'): |
883 | fbfee225 | Stavros Sachtouris | try:
|
884 | e5c76b1a | Stavros Sachtouris | for i in xrange(step): |
885 | e5c76b1a | Stavros Sachtouris | self.progress_bar_gen.next()
|
886 | fbfee225 | Stavros Sachtouris | except:
|
887 | fbfee225 | Stavros Sachtouris | pass
|
888 | 3dabe5d2 | Stavros Sachtouris | |
889 | fbfee225 | Stavros Sachtouris | def _complete_cb(self): |
890 | fbfee225 | Stavros Sachtouris | while True: |
891 | fbfee225 | Stavros Sachtouris | try:
|
892 | e5c76b1a | Stavros Sachtouris | self.progress_bar_gen.next()
|
893 | fbfee225 | Stavros Sachtouris | except:
|
894 | fbfee225 | Stavros Sachtouris | break
|
895 | b1713259 | Stavros Sachtouris | |
896 | 24ff0a35 | Stavros Sachtouris | def get_object_hashmap( |
897 | 24ff0a35 | Stavros Sachtouris | self, obj,
|
898 | 24ff0a35 | Stavros Sachtouris | version=None,
|
899 | 24ff0a35 | Stavros Sachtouris | if_match=None,
|
900 | 24ff0a35 | Stavros Sachtouris | if_none_match=None,
|
901 | 24ff0a35 | Stavros Sachtouris | if_modified_since=None,
|
902 | 24ff0a35 | Stavros Sachtouris | if_unmodified_since=None,
|
903 | 24ff0a35 | Stavros Sachtouris | data_range=None):
|
904 | 4375e020 | Stavros Sachtouris | """
|
905 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
906 | 4375e020 | Stavros Sachtouris |
|
907 | 4375e020 | Stavros Sachtouris | :param if_match: (str)
|
908 | 4375e020 | Stavros Sachtouris |
|
909 | 4375e020 | Stavros Sachtouris | :param if_none_match: (str)
|
910 | 4375e020 | Stavros Sachtouris |
|
911 | 4375e020 | Stavros Sachtouris | :param if_modified_since: (str) formated date
|
912 | 4375e020 | Stavros Sachtouris |
|
913 | 4375e020 | Stavros Sachtouris | :param if_unmodified_since: (str) formated date
|
914 | 4375e020 | Stavros Sachtouris |
|
915 | 4375e020 | Stavros Sachtouris | :param data_range: (str) from-to where from and to are integers
|
916 | 4375e020 | Stavros Sachtouris | denoting file positions in bytes
|
917 | 4375e020 | Stavros Sachtouris |
|
918 | 4375e020 | Stavros Sachtouris | :returns: (list)
|
919 | 4375e020 | Stavros Sachtouris | """
|
920 | d804de82 | Stavros Sachtouris | try:
|
921 | 24ff0a35 | Stavros Sachtouris | r = self.object_get(
|
922 | 24ff0a35 | Stavros Sachtouris | obj, |
923 | 3dabe5d2 | Stavros Sachtouris | hashmap=True,
|
924 | 3dabe5d2 | Stavros Sachtouris | version=version, |
925 | 3dabe5d2 | Stavros Sachtouris | if_etag_match=if_match, |
926 | 3dabe5d2 | Stavros Sachtouris | if_etag_not_match=if_none_match, |
927 | 3dabe5d2 | Stavros Sachtouris | if_modified_since=if_modified_since, |
928 | 3dabe5d2 | Stavros Sachtouris | if_unmodified_since=if_unmodified_since, |
929 | 3dabe5d2 | Stavros Sachtouris | data_range=data_range) |
930 | d804de82 | Stavros Sachtouris | except ClientError as err: |
931 | d804de82 | Stavros Sachtouris | if err.status == 304 or err.status == 412: |
932 | d804de82 | Stavros Sachtouris | return {}
|
933 | d804de82 | Stavros Sachtouris | raise
|
934 | 64ab4c13 | Stavros Sachtouris | return r.json
|
935 | 56f0908a | Stavros Sachtouris | |
936 | 3a9e54b0 | Stavros Sachtouris | def set_account_group(self, group, usernames): |
937 | 4375e020 | Stavros Sachtouris | """
|
938 | 4375e020 | Stavros Sachtouris | :param group: (str)
|
939 | 4375e020 | Stavros Sachtouris |
|
940 | 4375e020 | Stavros Sachtouris | :param usernames: (list)
|
941 | 4375e020 | Stavros Sachtouris | """
|
942 | 915b99b5 | Stavros Sachtouris | r = self.account_post(update=True, groups={group: usernames}) |
943 | 915b99b5 | Stavros Sachtouris | return r
|
944 | eb903ba7 | Stavros Sachtouris | |
945 | c2867610 | Stavros Sachtouris | def del_account_group(self, group): |
946 | 4375e020 | Stavros Sachtouris | """
|
947 | 4375e020 | Stavros Sachtouris | :param group: (str)
|
948 | 4375e020 | Stavros Sachtouris | """
|
949 | c2b5da2f | Stavros Sachtouris | self.account_post(update=True, groups={group: []}) |
950 | c2867610 | Stavros Sachtouris | |
951 | 8af4cc0b | Stavros Sachtouris | def get_account_info(self, until=None): |
952 | 4375e020 | Stavros Sachtouris | """
|
953 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
954 | 4375e020 | Stavros Sachtouris |
|
955 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
956 | 4375e020 | Stavros Sachtouris | """
|
957 | 8af4cc0b | Stavros Sachtouris | r = self.account_head(until=until)
|
958 | 6657ec8c | Stavros Sachtouris | if r.status_code == 401: |
959 | 24851aa5 | Stavros Sachtouris | raise ClientError("No authorization", status=401) |
960 | 64ab4c13 | Stavros Sachtouris | return r.headers
|
961 | 6657ec8c | Stavros Sachtouris | |
962 | d1856abf | Stavros Sachtouris | def get_account_quota(self): |
963 | 4375e020 | Stavros Sachtouris | """
|
964 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
965 | 4375e020 | Stavros Sachtouris | """
|
966 | 24ff0a35 | Stavros Sachtouris | return filter_in(
|
967 | 24ff0a35 | Stavros Sachtouris | self.get_account_info(),
|
968 | 3dabe5d2 | Stavros Sachtouris | 'X-Account-Policy-Quota',
|
969 | 3dabe5d2 | Stavros Sachtouris | exactMatch=True)
|
970 | d1856abf | Stavros Sachtouris | |
971 | df0045d8 | Stavros Sachtouris | #def get_account_versioning(self):
|
972 | df0045d8 | Stavros Sachtouris | # """
|
973 | df0045d8 | Stavros Sachtouris | # :returns: (dict)
|
974 | df0045d8 | Stavros Sachtouris | # """
|
975 | df0045d8 | Stavros Sachtouris | # return filter_in(
|
976 | df0045d8 | Stavros Sachtouris | # self.get_account_info(),
|
977 | df0045d8 | Stavros Sachtouris | # 'X-Account-Policy-Versioning',
|
978 | df0045d8 | Stavros Sachtouris | # exactMatch=True)
|
979 | e6b39366 | Stavros Sachtouris | |
980 | 8af4cc0b | Stavros Sachtouris | def get_account_meta(self, until=None): |
981 | 4375e020 | Stavros Sachtouris | """
|
982 | 8f91e50c | Stavros Sachtouris | :param until: (str) formated date
|
983 | 4375e020 | Stavros Sachtouris |
|
984 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
985 | 4375e020 | Stavros Sachtouris | """
|
986 | 3dabe5d2 | Stavros Sachtouris | return filter_in(self.get_account_info(until=until), 'X-Account-Meta-') |
987 | af3b2b36 | Stavros Sachtouris | |
988 | c2867610 | Stavros Sachtouris | def get_account_group(self): |
989 | 4375e020 | Stavros Sachtouris | """
|
990 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
991 | 4375e020 | Stavros Sachtouris | """
|
992 | c2867610 | Stavros Sachtouris | return filter_in(self.get_account_info(), 'X-Account-Group-') |
993 | c2867610 | Stavros Sachtouris | |
994 | af3b2b36 | Stavros Sachtouris | def set_account_meta(self, metapairs): |
995 | 4375e020 | Stavros Sachtouris | """
|
996 | 4375e020 | Stavros Sachtouris | :param metapairs: (dict) {key1:val1, key2:val2, ...}
|
997 | 4375e020 | Stavros Sachtouris | """
|
998 | af3b2b36 | Stavros Sachtouris | assert(type(metapairs) is dict) |
999 | 915b99b5 | Stavros Sachtouris | r = self.account_post(update=True, metadata=metapairs) |
1000 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1001 | af3b2b36 | Stavros Sachtouris | |
1002 | 379cd4bb | Stavros Sachtouris | def del_account_meta(self, metakey): |
1003 | 4375e020 | Stavros Sachtouris | """
|
1004 | 4375e020 | Stavros Sachtouris | :param metakey: (str) metadatum key
|
1005 | 4375e020 | Stavros Sachtouris | """
|
1006 | 915b99b5 | Stavros Sachtouris | r = self.account_post(update=True, metadata={metakey: ''}) |
1007 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1008 | 379cd4bb | Stavros Sachtouris | |
1009 | df0045d8 | Stavros Sachtouris | #def set_account_quota(self, quota):
|
1010 | df0045d8 | Stavros Sachtouris | # """
|
1011 | df0045d8 | Stavros Sachtouris | # :param quota: (int)
|
1012 | df0045d8 | Stavros Sachtouris | # """
|
1013 | df0045d8 | Stavros Sachtouris | # self.account_post(update=True, quota=quota)
|
1014 | df0045d8 | Stavros Sachtouris | |
1015 | df0045d8 | Stavros Sachtouris | #def set_account_versioning(self, versioning):
|
1016 | df0045d8 | Stavros Sachtouris | # """
|
1017 | df0045d8 | Stavros Sachtouris | # :param versioning: (str)
|
1018 | df0045d8 | Stavros Sachtouris | # """
|
1019 | df0045d8 | Stavros Sachtouris | # r = self.account_post(update=True, versioning=versioning)
|
1020 | df0045d8 | Stavros Sachtouris | # return r.headers
|
1021 | d1856abf | Stavros Sachtouris | |
1022 | 4fd88feb | Stavros Sachtouris | def list_containers(self): |
1023 | 4375e020 | Stavros Sachtouris | """
|
1024 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1025 | 4375e020 | Stavros Sachtouris | """
|
1026 | 4fd88feb | Stavros Sachtouris | r = self.account_get()
|
1027 | 64ab4c13 | Stavros Sachtouris | return r.json
|
1028 | b758e547 | Stavros Sachtouris | |
1029 | a298f2ab | Stavros Sachtouris | def del_container(self, until=None, delimiter=None): |
1030 | 4375e020 | Stavros Sachtouris | """
|
1031 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
1032 | 4375e020 | Stavros Sachtouris |
|
1033 | 4c1882ab | Stavros Sachtouris | :param delimiter: (str) with / empty container
|
1034 | 4375e020 | Stavros Sachtouris |
|
1035 | 4375e020 | Stavros Sachtouris | :raises ClientError: 404 Container does not exist
|
1036 | 4375e020 | Stavros Sachtouris |
|
1037 | 4375e020 | Stavros Sachtouris | :raises ClientError: 409 Container is not empty
|
1038 | 4375e020 | Stavros Sachtouris | """
|
1039 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
1040 | 2005b18e | Stavros Sachtouris | r = self.container_delete(
|
1041 | 2005b18e | Stavros Sachtouris | until=until, |
1042 | 3dabe5d2 | Stavros Sachtouris | delimiter=delimiter, |
1043 | 3dabe5d2 | Stavros Sachtouris | success=(204, 404, 409)) |
1044 | a298f2ab | Stavros Sachtouris | if r.status_code == 404: |
1045 | 24ff0a35 | Stavros Sachtouris | raise ClientError(
|
1046 | 24ff0a35 | Stavros Sachtouris | 'Container "%s" does not exist' % self.container, |
1047 | 3dabe5d2 | Stavros Sachtouris | r.status_code) |
1048 | a298f2ab | Stavros Sachtouris | elif r.status_code == 409: |
1049 | 24ff0a35 | Stavros Sachtouris | raise ClientError(
|
1050 | 24ff0a35 | Stavros Sachtouris | 'Container "%s" is not empty' % self.container, |
1051 | 3dabe5d2 | Stavros Sachtouris | r.status_code) |
1052 | 5655d560 | Stavros Sachtouris | return r.headers
|
1053 | a298f2ab | Stavros Sachtouris | |
1054 | bae347d3 | Stavros Sachtouris | def get_container_versioning(self, container=None): |
1055 | 4375e020 | Stavros Sachtouris | """
|
1056 | 4375e020 | Stavros Sachtouris | :param container: (str)
|
1057 | 4375e020 | Stavros Sachtouris |
|
1058 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1059 | 4375e020 | Stavros Sachtouris | """
|
1060 | bae347d3 | Stavros Sachtouris | cnt_back_up = self.container
|
1061 | bae347d3 | Stavros Sachtouris | try:
|
1062 | bae347d3 | Stavros Sachtouris | self.container = container or cnt_back_up |
1063 | bae347d3 | Stavros Sachtouris | return filter_in(
|
1064 | bae347d3 | Stavros Sachtouris | self.get_container_info(),
|
1065 | bae347d3 | Stavros Sachtouris | 'X-Container-Policy-Versioning')
|
1066 | bae347d3 | Stavros Sachtouris | finally:
|
1067 | bae347d3 | Stavros Sachtouris | self.container = cnt_back_up
|
1068 | d1856abf | Stavros Sachtouris | |
1069 | 3ed6dbde | Stavros Sachtouris | def get_container_limit(self, container=None): |
1070 | 4375e020 | Stavros Sachtouris | """
|
1071 | 4375e020 | Stavros Sachtouris | :param container: (str)
|
1072 | 4375e020 | Stavros Sachtouris |
|
1073 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1074 | 4375e020 | Stavros Sachtouris | """
|
1075 | 1879e310 | Stavros Sachtouris | cnt_back_up = self.container
|
1076 | 1879e310 | Stavros Sachtouris | try:
|
1077 | 1879e310 | Stavros Sachtouris | self.container = container or cnt_back_up |
1078 | 1879e310 | Stavros Sachtouris | return filter_in(
|
1079 | 1879e310 | Stavros Sachtouris | self.get_container_info(),
|
1080 | 1879e310 | Stavros Sachtouris | 'X-Container-Policy-Quota')
|
1081 | 1879e310 | Stavros Sachtouris | finally:
|
1082 | 1879e310 | Stavros Sachtouris | self.container = cnt_back_up
|
1083 | e6b39366 | Stavros Sachtouris | |
1084 | 3dabe5d2 | Stavros Sachtouris | def get_container_info(self, until=None): |
1085 | 4375e020 | Stavros Sachtouris | """
|
1086 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
1087 | 4375e020 | Stavros Sachtouris |
|
1088 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1089 | f91bc6b1 | Stavros Sachtouris |
|
1090 | f91bc6b1 | Stavros Sachtouris | :raises ClientError: 404 Container not found
|
1091 | 4375e020 | Stavros Sachtouris | """
|
1092 | f91bc6b1 | Stavros Sachtouris | try:
|
1093 | f91bc6b1 | Stavros Sachtouris | r = self.container_head(until=until)
|
1094 | f91bc6b1 | Stavros Sachtouris | except ClientError as err: |
1095 | f91bc6b1 | Stavros Sachtouris | err.details.append('for container %s' % self.container) |
1096 | f91bc6b1 | Stavros Sachtouris | raise err
|
1097 | 8af4cc0b | Stavros Sachtouris | return r.headers
|
1098 | 8af4cc0b | Stavros Sachtouris | |
1099 | 3dabe5d2 | Stavros Sachtouris | def get_container_meta(self, until=None): |
1100 | 4375e020 | Stavros Sachtouris | """
|
1101 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
1102 | 4375e020 | Stavros Sachtouris |
|
1103 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1104 | 4375e020 | Stavros Sachtouris | """
|
1105 | 24ff0a35 | Stavros Sachtouris | return filter_in(
|
1106 | 24ff0a35 | Stavros Sachtouris | self.get_container_info(until=until),
|
1107 | 3dabe5d2 | Stavros Sachtouris | 'X-Container-Meta')
|
1108 | e6b39366 | Stavros Sachtouris | |
1109 | 3dabe5d2 | Stavros Sachtouris | def get_container_object_meta(self, until=None): |
1110 | 4375e020 | Stavros Sachtouris | """
|
1111 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
1112 | 4375e020 | Stavros Sachtouris |
|
1113 | 4375e020 | Stavros Sachtouris | :returns: (dict)
|
1114 | 4375e020 | Stavros Sachtouris | """
|
1115 | 24ff0a35 | Stavros Sachtouris | return filter_in(
|
1116 | 24ff0a35 | Stavros Sachtouris | self.get_container_info(until=until),
|
1117 | 3dabe5d2 | Stavros Sachtouris | 'X-Container-Object-Meta')
|
1118 | e6b39366 | Stavros Sachtouris | |
1119 | af3b2b36 | Stavros Sachtouris | def set_container_meta(self, metapairs): |
1120 | 4375e020 | Stavros Sachtouris | """
|
1121 | 4375e020 | Stavros Sachtouris | :param metapairs: (dict) {key1:val1, key2:val2, ...}
|
1122 | 4375e020 | Stavros Sachtouris | """
|
1123 | af3b2b36 | Stavros Sachtouris | assert(type(metapairs) is dict) |
1124 | 915b99b5 | Stavros Sachtouris | r = self.container_post(update=True, metadata=metapairs) |
1125 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1126 | 3dabe5d2 | Stavros Sachtouris | |
1127 | 3e544e5b | Stavros Sachtouris | def del_container_meta(self, metakey): |
1128 | 4375e020 | Stavros Sachtouris | """
|
1129 | 4375e020 | Stavros Sachtouris | :param metakey: (str) metadatum key
|
1130 | 545c6c29 | Stavros Sachtouris |
|
1131 | 545c6c29 | Stavros Sachtouris | :returns: (dict) response headers
|
1132 | 4375e020 | Stavros Sachtouris | """
|
1133 | 915b99b5 | Stavros Sachtouris | r = self.container_post(update=True, metadata={metakey: ''}) |
1134 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1135 | e6b39366 | Stavros Sachtouris | |
1136 | 326a79b9 | Stavros Sachtouris | def set_container_limit(self, limit): |
1137 | 4375e020 | Stavros Sachtouris | """
|
1138 | 326a79b9 | Stavros Sachtouris | :param limit: (int)
|
1139 | 4375e020 | Stavros Sachtouris | """
|
1140 | 915b99b5 | Stavros Sachtouris | r = self.container_post(update=True, quota=limit) |
1141 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1142 | d1856abf | Stavros Sachtouris | |
1143 | d1856abf | Stavros Sachtouris | def set_container_versioning(self, versioning): |
1144 | 4375e020 | Stavros Sachtouris | """
|
1145 | 4375e020 | Stavros Sachtouris | :param versioning: (str)
|
1146 | 4375e020 | Stavros Sachtouris | """
|
1147 | 915b99b5 | Stavros Sachtouris | r = self.container_post(update=True, versioning=versioning) |
1148 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1149 | d1856abf | Stavros Sachtouris | |
1150 | a298f2ab | Stavros Sachtouris | def del_object(self, obj, until=None, delimiter=None): |
1151 | 4375e020 | Stavros Sachtouris | """
|
1152 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
1153 | 4375e020 | Stavros Sachtouris |
|
1154 | 4375e020 | Stavros Sachtouris | :param until: (str) formated date
|
1155 | 4375e020 | Stavros Sachtouris |
|
1156 | 4375e020 | Stavros Sachtouris | :param delimiter: (str)
|
1157 | 4375e020 | Stavros Sachtouris | """
|
1158 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
1159 | 5655d560 | Stavros Sachtouris | r = self.object_delete(obj, until=until, delimiter=delimiter)
|
1160 | 5655d560 | Stavros Sachtouris | return r.headers
|
1161 | a298f2ab | Stavros Sachtouris | |
1162 | 4375e020 | Stavros Sachtouris | def set_object_meta(self, obj, metapairs): |
1163 | 4375e020 | Stavros Sachtouris | """
|
1164 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
1165 | 4375e020 | Stavros Sachtouris |
|
1166 | 4375e020 | Stavros Sachtouris | :param metapairs: (dict) {key1:val1, key2:val2, ...}
|
1167 | 4375e020 | Stavros Sachtouris | """
|
1168 | af3b2b36 | Stavros Sachtouris | assert(type(metapairs) is dict) |
1169 | 915b99b5 | Stavros Sachtouris | r = self.object_post(obj, update=True, metadata=metapairs) |
1170 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1171 | 87688514 | Stavros Sachtouris | |
1172 | bc223d91 | Stavros Sachtouris | def del_object_meta(self, obj, metakey): |
1173 | 4375e020 | Stavros Sachtouris | """
|
1174 | 4375e020 | Stavros Sachtouris | :param obj: (str) remote object path
|
1175 | bc223d91 | Stavros Sachtouris |
|
1176 | bc223d91 | Stavros Sachtouris | :param metakey: (str) metadatum key
|
1177 | 4375e020 | Stavros Sachtouris | """
|
1178 | 915b99b5 | Stavros Sachtouris | r = self.object_post(obj, update=True, metadata={metakey: ''}) |
1179 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1180 | 6de1f262 | Stavros Sachtouris | |
1181 | bc223d91 | Stavros Sachtouris | def publish_object(self, obj): |
1182 | bc223d91 | Stavros Sachtouris | """
|
1183 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1184 | 5260a313 | Stavros Sachtouris |
|
1185 | 5260a313 | Stavros Sachtouris | :returns: (str) access url
|
1186 | bc223d91 | Stavros Sachtouris | """
|
1187 | c2b5da2f | Stavros Sachtouris | self.object_post(obj, update=True, public=True) |
1188 | 5260a313 | Stavros Sachtouris | info = self.get_object_info(obj)
|
1189 | fa382f9e | Stavros Sachtouris | return info['x-object-public'] |
1190 | 93542587 | Stavros Sachtouris | pref, sep, rest = self.base_url.partition('//') |
1191 | 93542587 | Stavros Sachtouris | base = rest.split('/')[0] |
1192 | f847a0cc | Stavros Sachtouris | return '%s%s%s/%s' % (pref, sep, base, info['x-object-public']) |
1193 | 87688514 | Stavros Sachtouris | |
1194 | bc223d91 | Stavros Sachtouris | def unpublish_object(self, obj): |
1195 | bc223d91 | Stavros Sachtouris | """
|
1196 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1197 | bc223d91 | Stavros Sachtouris | """
|
1198 | 5655d560 | Stavros Sachtouris | r = self.object_post(obj, update=True, public=False) |
1199 | 5655d560 | Stavros Sachtouris | return r.headers
|
1200 | 28470086 | Stavros Sachtouris | |
1201 | 8af4cc0b | Stavros Sachtouris | def get_object_info(self, obj, version=None): |
1202 | bc223d91 | Stavros Sachtouris | """
|
1203 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1204 | bc223d91 | Stavros Sachtouris |
|
1205 | bc223d91 | Stavros Sachtouris | :param version: (str)
|
1206 | bc223d91 | Stavros Sachtouris |
|
1207 | bc223d91 | Stavros Sachtouris | :returns: (dict)
|
1208 | bc223d91 | Stavros Sachtouris | """
|
1209 | ca092af4 | Stavros Sachtouris | try:
|
1210 | ca092af4 | Stavros Sachtouris | r = self.object_head(obj, version=version)
|
1211 | ca092af4 | Stavros Sachtouris | return r.headers
|
1212 | ca092af4 | Stavros Sachtouris | except ClientError as ce: |
1213 | ca092af4 | Stavros Sachtouris | if ce.status == 404: |
1214 | 723e9d47 | Stavros Sachtouris | raise ClientError('Object %s not found' % obj, status=404) |
1215 | ca092af4 | Stavros Sachtouris | raise
|
1216 | 8af4cc0b | Stavros Sachtouris | |
1217 | 8af4cc0b | Stavros Sachtouris | def get_object_meta(self, obj, version=None): |
1218 | bc223d91 | Stavros Sachtouris | """
|
1219 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1220 | bc223d91 | Stavros Sachtouris |
|
1221 | bc223d91 | Stavros Sachtouris | :param version: (str)
|
1222 | bc223d91 | Stavros Sachtouris |
|
1223 | bc223d91 | Stavros Sachtouris | :returns: (dict)
|
1224 | bc223d91 | Stavros Sachtouris | """
|
1225 | 24ff0a35 | Stavros Sachtouris | return filter_in(
|
1226 | 24ff0a35 | Stavros Sachtouris | self.get_object_info(obj, version=version),
|
1227 | 3dabe5d2 | Stavros Sachtouris | 'X-Object-Meta')
|
1228 | 8af4cc0b | Stavros Sachtouris | |
1229 | bc223d91 | Stavros Sachtouris | def get_object_sharing(self, obj): |
1230 | bc223d91 | Stavros Sachtouris | """
|
1231 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1232 | bc223d91 | Stavros Sachtouris |
|
1233 | bc223d91 | Stavros Sachtouris | :returns: (dict)
|
1234 | bc223d91 | Stavros Sachtouris | """
|
1235 | 24ff0a35 | Stavros Sachtouris | r = filter_in( |
1236 | 24ff0a35 | Stavros Sachtouris | self.get_object_info(obj),
|
1237 | 3dabe5d2 | Stavros Sachtouris | 'X-Object-Sharing',
|
1238 | 3dabe5d2 | Stavros Sachtouris | exactMatch=True)
|
1239 | f70616fc | Stavros Sachtouris | reply = {} |
1240 | f70616fc | Stavros Sachtouris | if len(r) > 0: |
1241 | f70616fc | Stavros Sachtouris | perms = r['x-object-sharing'].split(';') |
1242 | f70616fc | Stavros Sachtouris | for perm in perms: |
1243 | f70616fc | Stavros Sachtouris | try:
|
1244 | f70616fc | Stavros Sachtouris | perm.index('=')
|
1245 | f70616fc | Stavros Sachtouris | except ValueError: |
1246 | f70616fc | Stavros Sachtouris | raise ClientError('Incorrect reply format') |
1247 | f70616fc | Stavros Sachtouris | (key, val) = perm.strip().split('=')
|
1248 | f70616fc | Stavros Sachtouris | reply[key] = val |
1249 | f70616fc | Stavros Sachtouris | return reply
|
1250 | f49084df | Stavros Sachtouris | |
1251 | 24ff0a35 | Stavros Sachtouris | def set_object_sharing( |
1252 | 2005b18e | Stavros Sachtouris | self, obj,
|
1253 | 00336c85 | Stavros Sachtouris | read_permission=False, write_permission=False): |
1254 | 28470086 | Stavros Sachtouris | """Give read/write permisions to an object.
|
1255 | bc223d91 | Stavros Sachtouris |
|
1256 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1257 | bc223d91 | Stavros Sachtouris |
|
1258 | 00336c85 | Stavros Sachtouris | :param read_permission: (list - bool) users and user groups that get
|
1259 | 00336c85 | Stavros Sachtouris | read permission for this object - False means all previous read
|
1260 | bc223d91 | Stavros Sachtouris | permissions will be removed
|
1261 | bc223d91 | Stavros Sachtouris |
|
1262 | 00336c85 | Stavros Sachtouris | :param write_permission: (list - bool) of users and user groups to get
|
1263 | 00336c85 | Stavros Sachtouris | write permission for this object - False means all previous write
|
1264 | 4067cdaf | Stavros Sachtouris | permissions will be removed
|
1265 | 915b99b5 | Stavros Sachtouris |
|
1266 | 915b99b5 | Stavros Sachtouris | :returns: (dict) response headers
|
1267 | 28470086 | Stavros Sachtouris | """
|
1268 | 4067cdaf | Stavros Sachtouris | |
1269 | 00336c85 | Stavros Sachtouris | perms = dict(read=read_permission or '', write=write_permission or '') |
1270 | 915b99b5 | Stavros Sachtouris | r = self.object_post(obj, update=True, permissions=perms) |
1271 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1272 | 28470086 | Stavros Sachtouris | |
1273 | bc223d91 | Stavros Sachtouris | def del_object_sharing(self, obj): |
1274 | bc223d91 | Stavros Sachtouris | """
|
1275 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1276 | bc223d91 | Stavros Sachtouris | """
|
1277 | 915b99b5 | Stavros Sachtouris | return self.set_object_sharing(obj) |
1278 | bc223d91 | Stavros Sachtouris | |
1279 | bc223d91 | Stavros Sachtouris | def append_object(self, obj, source_file, upload_cb=None): |
1280 | bc223d91 | Stavros Sachtouris | """
|
1281 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1282 | bc223d91 | Stavros Sachtouris |
|
1283 | bc223d91 | Stavros Sachtouris | :param source_file: open file descriptor
|
1284 | f49084df | Stavros Sachtouris |
|
1285 | bc223d91 | Stavros Sachtouris | :param upload_db: progress.bar for uploading
|
1286 | bcabbc35 | Stavros Sachtouris | """
|
1287 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
1288 | 2f749e6e | Stavros Sachtouris | meta = self.get_container_info()
|
1289 | ab474306 | Stavros Sachtouris | blocksize = int(meta['x-container-block-size']) |
1290 | 64ab4c13 | Stavros Sachtouris | filesize = fstat(source_file.fileno()).st_size |
1291 | 3dabe5d2 | Stavros Sachtouris | nblocks = 1 + (filesize - 1) // blocksize |
1292 | ab474306 | Stavros Sachtouris | offset = 0
|
1293 | 5655d560 | Stavros Sachtouris | headers = {} |
1294 | ca092af4 | Stavros Sachtouris | if upload_cb:
|
1295 | 5655d560 | Stavros Sachtouris | self.progress_bar_gen = upload_cb(nblocks)
|
1296 | 5655d560 | Stavros Sachtouris | self._cb_next()
|
1297 | 5655d560 | Stavros Sachtouris | flying = {} |
1298 | 5655d560 | Stavros Sachtouris | self._init_thread_limit()
|
1299 | 5655d560 | Stavros Sachtouris | try:
|
1300 | 5655d560 | Stavros Sachtouris | for i in range(nblocks): |
1301 | 5655d560 | Stavros Sachtouris | block = source_file.read(min(blocksize, filesize - offset))
|
1302 | 5655d560 | Stavros Sachtouris | offset += len(block)
|
1303 | 5655d560 | Stavros Sachtouris | |
1304 | 5655d560 | Stavros Sachtouris | self._watch_thread_limit(flying.values())
|
1305 | 5655d560 | Stavros Sachtouris | unfinished = {} |
1306 | 5655d560 | Stavros Sachtouris | flying[i] = SilentEvent( |
1307 | 5655d560 | Stavros Sachtouris | method=self.object_post,
|
1308 | 5655d560 | Stavros Sachtouris | obj=obj, |
1309 | 5655d560 | Stavros Sachtouris | update=True,
|
1310 | 5655d560 | Stavros Sachtouris | content_range='bytes */*',
|
1311 | 5655d560 | Stavros Sachtouris | content_type='application/octet-stream',
|
1312 | 5655d560 | Stavros Sachtouris | content_length=len(block),
|
1313 | 5655d560 | Stavros Sachtouris | data=block) |
1314 | 5655d560 | Stavros Sachtouris | flying[i].start() |
1315 | 5655d560 | Stavros Sachtouris | |
1316 | 5655d560 | Stavros Sachtouris | for key, thread in flying.items(): |
1317 | 5655d560 | Stavros Sachtouris | if thread.isAlive():
|
1318 | 5655d560 | Stavros Sachtouris | if i < nblocks:
|
1319 | 5655d560 | Stavros Sachtouris | unfinished[key] = thread |
1320 | 5655d560 | Stavros Sachtouris | continue
|
1321 | 5655d560 | Stavros Sachtouris | thread.join() |
1322 | 5655d560 | Stavros Sachtouris | if thread.exception:
|
1323 | 5655d560 | Stavros Sachtouris | raise thread.exception
|
1324 | 5655d560 | Stavros Sachtouris | headers[key] = thread.value.headers |
1325 | 5655d560 | Stavros Sachtouris | self._cb_next()
|
1326 | 5655d560 | Stavros Sachtouris | flying = unfinished |
1327 | 5655d560 | Stavros Sachtouris | except KeyboardInterrupt: |
1328 | 5655d560 | Stavros Sachtouris | sendlog.info('- - - wait for threads to finish')
|
1329 | 5655d560 | Stavros Sachtouris | for thread in activethreads(): |
1330 | 5655d560 | Stavros Sachtouris | thread.join() |
1331 | 3ec5c230 | Stavros Sachtouris | finally:
|
1332 | 3ec5c230 | Stavros Sachtouris | from time import sleep |
1333 | 4e424eaa | Stavros Sachtouris | sleep(2 * len(activethreads())) |
1334 | 5655d560 | Stavros Sachtouris | return headers.values()
|
1335 | 561116a6 | Stavros Sachtouris | |
1336 | bc223d91 | Stavros Sachtouris | def truncate_object(self, obj, upto_bytes): |
1337 | bc223d91 | Stavros Sachtouris | """
|
1338 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1339 | bc223d91 | Stavros Sachtouris |
|
1340 | bc223d91 | Stavros Sachtouris | :param upto_bytes: max number of bytes to leave on file
|
1341 | 915b99b5 | Stavros Sachtouris |
|
1342 | 915b99b5 | Stavros Sachtouris | :returns: (dict) response headers
|
1343 | bc223d91 | Stavros Sachtouris | """
|
1344 | 915b99b5 | Stavros Sachtouris | r = self.object_post(
|
1345 | 24ff0a35 | Stavros Sachtouris | obj, |
1346 | 3dabe5d2 | Stavros Sachtouris | update=True,
|
1347 | 3dabe5d2 | Stavros Sachtouris | content_range='bytes 0-%s/*' % upto_bytes,
|
1348 | 3dabe5d2 | Stavros Sachtouris | content_type='application/octet-stream',
|
1349 | 3dabe5d2 | Stavros Sachtouris | object_bytes=upto_bytes, |
1350 | bc223d91 | Stavros Sachtouris | source_object=path4url(self.container, obj))
|
1351 | 915b99b5 | Stavros Sachtouris | return r.headers
|
1352 | ee62607e | Stavros Sachtouris | |
1353 | 2005b18e | Stavros Sachtouris | def overwrite_object(self, obj, start, end, source_file, upload_cb=None): |
1354 | bc223d91 | Stavros Sachtouris | """Overwrite a part of an object from local source file
|
1355 | bc223d91 | Stavros Sachtouris |
|
1356 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1357 | bc223d91 | Stavros Sachtouris |
|
1358 | bc223d91 | Stavros Sachtouris | :param start: (int) position in bytes to start overwriting from
|
1359 | bc223d91 | Stavros Sachtouris |
|
1360 | bc223d91 | Stavros Sachtouris | :param end: (int) position in bytes to stop overwriting at
|
1361 | bc223d91 | Stavros Sachtouris |
|
1362 | bc223d91 | Stavros Sachtouris | :param source_file: open file descriptor
|
1363 | bc223d91 | Stavros Sachtouris |
|
1364 | bc223d91 | Stavros Sachtouris | :param upload_db: progress.bar for uploading
|
1365 | ee62607e | Stavros Sachtouris | """
|
1366 | 4067cdaf | Stavros Sachtouris | |
1367 | ca092af4 | Stavros Sachtouris | r = self.get_object_info(obj)
|
1368 | ca092af4 | Stavros Sachtouris | rf_size = int(r['content-length']) |
1369 | ca092af4 | Stavros Sachtouris | if rf_size < int(start): |
1370 | ca092af4 | Stavros Sachtouris | raise ClientError(
|
1371 | ca092af4 | Stavros Sachtouris | 'Range start exceeds file size',
|
1372 | ca092af4 | Stavros Sachtouris | status=416)
|
1373 | ca092af4 | Stavros Sachtouris | elif rf_size < int(end): |
1374 | ca092af4 | Stavros Sachtouris | raise ClientError(
|
1375 | ca092af4 | Stavros Sachtouris | 'Range end exceeds file size',
|
1376 | ca092af4 | Stavros Sachtouris | status=416)
|
1377 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
1378 | 2f749e6e | Stavros Sachtouris | meta = self.get_container_info()
|
1379 | ee62607e | Stavros Sachtouris | blocksize = int(meta['x-container-block-size']) |
1380 | 64ab4c13 | Stavros Sachtouris | filesize = fstat(source_file.fileno()).st_size |
1381 | ee62607e | Stavros Sachtouris | datasize = int(end) - int(start) + 1 |
1382 | 3dabe5d2 | Stavros Sachtouris | nblocks = 1 + (datasize - 1) // blocksize |
1383 | ee62607e | Stavros Sachtouris | offset = 0
|
1384 | ca092af4 | Stavros Sachtouris | if upload_cb:
|
1385 | 915b99b5 | Stavros Sachtouris | self.progress_bar_gen = upload_cb(nblocks)
|
1386 | 915b99b5 | Stavros Sachtouris | self._cb_next()
|
1387 | 915b99b5 | Stavros Sachtouris | headers = [] |
1388 | ee62607e | Stavros Sachtouris | for i in range(nblocks): |
1389 | 24ff0a35 | Stavros Sachtouris | read_size = min(blocksize, filesize - offset, datasize - offset)
|
1390 | 24ff0a35 | Stavros Sachtouris | block = source_file.read(read_size) |
1391 | 915b99b5 | Stavros Sachtouris | r = self.object_post(
|
1392 | 24ff0a35 | Stavros Sachtouris | obj, |
1393 | 3dabe5d2 | Stavros Sachtouris | update=True,
|
1394 | 3dabe5d2 | Stavros Sachtouris | content_type='application/octet-stream',
|
1395 | 3dabe5d2 | Stavros Sachtouris | content_length=len(block),
|
1396 | ca092af4 | Stavros Sachtouris | content_range='bytes %s-%s/*' % (
|
1397 | ca092af4 | Stavros Sachtouris | start + offset, |
1398 | ca092af4 | Stavros Sachtouris | start + offset + len(block) - 1), |
1399 | 3dabe5d2 | Stavros Sachtouris | data=block) |
1400 | 915b99b5 | Stavros Sachtouris | headers.append(dict(r.headers))
|
1401 | ca092af4 | Stavros Sachtouris | offset += len(block)
|
1402 | 3dabe5d2 | Stavros Sachtouris | |
1403 | 915b99b5 | Stavros Sachtouris | self._cb_next
|
1404 | 915b99b5 | Stavros Sachtouris | return headers
|
1405 | 7d420701 | Stavros Sachtouris | |
1406 | 24ff0a35 | Stavros Sachtouris | def copy_object( |
1407 | 2005b18e | Stavros Sachtouris | self, src_container, src_object, dst_container,
|
1408 | 33487500 | Stavros Sachtouris | dst_object=None,
|
1409 | 2005b18e | Stavros Sachtouris | source_version=None,
|
1410 | 3a066af4 | Stavros Sachtouris | source_account=None,
|
1411 | 2005b18e | Stavros Sachtouris | public=False,
|
1412 | 2005b18e | Stavros Sachtouris | content_type=None,
|
1413 | 2005b18e | Stavros Sachtouris | delimiter=None):
|
1414 | bc223d91 | Stavros Sachtouris | """
|
1415 | bc223d91 | Stavros Sachtouris | :param src_container: (str) source container
|
1416 | bc223d91 | Stavros Sachtouris |
|
1417 | bc223d91 | Stavros Sachtouris | :param src_object: (str) source object path
|
1418 | bc223d91 | Stavros Sachtouris |
|
1419 | bc223d91 | Stavros Sachtouris | :param dst_container: (str) destination container
|
1420 | bc223d91 | Stavros Sachtouris |
|
1421 | bc223d91 | Stavros Sachtouris | :param dst_object: (str) destination object path
|
1422 | bc223d91 | Stavros Sachtouris |
|
1423 | bc223d91 | Stavros Sachtouris | :param source_version: (str) source object version
|
1424 | bc223d91 | Stavros Sachtouris |
|
1425 | 3a066af4 | Stavros Sachtouris | :param source_account: (str) account to copy from
|
1426 | 3a066af4 | Stavros Sachtouris |
|
1427 | bc223d91 | Stavros Sachtouris | :param public: (bool)
|
1428 | bc223d91 | Stavros Sachtouris |
|
1429 | bc223d91 | Stavros Sachtouris | :param content_type: (str)
|
1430 | bc223d91 | Stavros Sachtouris |
|
1431 | bc223d91 | Stavros Sachtouris | :param delimiter: (str)
|
1432 | 55c75058 | Stavros Sachtouris |
|
1433 | 55c75058 | Stavros Sachtouris | :returns: (dict) response headers
|
1434 | bc223d91 | Stavros Sachtouris | """
|
1435 | 277ca4ed | Dionysis Zindros | self._assert_account()
|
1436 | 7d420701 | Stavros Sachtouris | self.container = dst_container
|
1437 | 7d420701 | Stavros Sachtouris | src_path = path4url(src_container, src_object) |
1438 | 55c75058 | Stavros Sachtouris | r = self.object_put(
|
1439 | 33487500 | Stavros Sachtouris | dst_object or src_object,
|
1440 | 3dabe5d2 | Stavros Sachtouris | success=201,
|
1441 | 3dabe5d2 | Stavros Sachtouris | copy_from=src_path, |
1442 | 3dabe5d2 | Stavros Sachtouris | content_length=0,
|
1443 | 3dabe5d2 | Stavros Sachtouris | source_version=source_version, |
1444 | 3a066af4 | Stavros Sachtouris | source_account=source_account, |
1445 | 3dabe5d2 | Stavros Sachtouris | public=public, |
1446 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
1447 | 7d420701 | Stavros Sachtouris | delimiter=delimiter) |
1448 | 55c75058 | Stavros Sachtouris | return r.headers
|
1449 | a5e0629d | Stavros Sachtouris | |
1450 | 24ff0a35 | Stavros Sachtouris | def move_object( |
1451 | 24ff0a35 | Stavros Sachtouris | self, src_container, src_object, dst_container,
|
1452 | 24ff0a35 | Stavros Sachtouris | dst_object=False,
|
1453 | 4f266635 | Stavros Sachtouris | source_account=None,
|
1454 | 24ff0a35 | Stavros Sachtouris | source_version=None,
|
1455 | 24ff0a35 | Stavros Sachtouris | public=False,
|
1456 | 24ff0a35 | Stavros Sachtouris | content_type=None,
|
1457 | 24ff0a35 | Stavros Sachtouris | delimiter=None):
|
1458 | bc223d91 | Stavros Sachtouris | """
|
1459 | bc223d91 | Stavros Sachtouris | :param src_container: (str) source container
|
1460 | bc223d91 | Stavros Sachtouris |
|
1461 | bc223d91 | Stavros Sachtouris | :param src_object: (str) source object path
|
1462 | bc223d91 | Stavros Sachtouris |
|
1463 | bc223d91 | Stavros Sachtouris | :param dst_container: (str) destination container
|
1464 | bc223d91 | Stavros Sachtouris |
|
1465 | bc223d91 | Stavros Sachtouris | :param dst_object: (str) destination object path
|
1466 | bc223d91 | Stavros Sachtouris |
|
1467 | 4f266635 | Stavros Sachtouris | :param source_account: (str) account to move from
|
1468 | 4f266635 | Stavros Sachtouris |
|
1469 | bc223d91 | Stavros Sachtouris | :param source_version: (str) source object version
|
1470 | bc223d91 | Stavros Sachtouris |
|
1471 | bc223d91 | Stavros Sachtouris | :param public: (bool)
|
1472 | bc223d91 | Stavros Sachtouris |
|
1473 | bc223d91 | Stavros Sachtouris | :param content_type: (str)
|
1474 | bc223d91 | Stavros Sachtouris |
|
1475 | bc223d91 | Stavros Sachtouris | :param delimiter: (str)
|
1476 | 55c75058 | Stavros Sachtouris |
|
1477 | 55c75058 | Stavros Sachtouris | :returns: (dict) response headers
|
1478 | bc223d91 | Stavros Sachtouris | """
|
1479 | 277ca4ed | Dionysis Zindros | self._assert_account()
|
1480 | a5e0629d | Stavros Sachtouris | self.container = dst_container
|
1481 | a5e0629d | Stavros Sachtouris | dst_object = dst_object or src_object
|
1482 | a5e0629d | Stavros Sachtouris | src_path = path4url(src_container, src_object) |
1483 | 55c75058 | Stavros Sachtouris | r = self.object_put(
|
1484 | 24ff0a35 | Stavros Sachtouris | dst_object, |
1485 | 3dabe5d2 | Stavros Sachtouris | success=201,
|
1486 | 3dabe5d2 | Stavros Sachtouris | move_from=src_path, |
1487 | 3dabe5d2 | Stavros Sachtouris | content_length=0,
|
1488 | 4f266635 | Stavros Sachtouris | source_account=source_account, |
1489 | 3dabe5d2 | Stavros Sachtouris | source_version=source_version, |
1490 | 3dabe5d2 | Stavros Sachtouris | public=public, |
1491 | 3dabe5d2 | Stavros Sachtouris | content_type=content_type, |
1492 | a23f6ffe | Stavros Sachtouris | delimiter=delimiter) |
1493 | 55c75058 | Stavros Sachtouris | return r.headers
|
1494 | a23f6ffe | Stavros Sachtouris | |
1495 | a23f6ffe | Stavros Sachtouris | def get_sharing_accounts(self, limit=None, marker=None, *args, **kwargs): |
1496 | bc223d91 | Stavros Sachtouris | """Get accounts that share with self.account
|
1497 | bc223d91 | Stavros Sachtouris |
|
1498 | bc223d91 | Stavros Sachtouris | :param limit: (str)
|
1499 | bc223d91 | Stavros Sachtouris |
|
1500 | bc223d91 | Stavros Sachtouris | :param marker: (str)
|
1501 | bc223d91 | Stavros Sachtouris |
|
1502 | bc223d91 | Stavros Sachtouris | :returns: (dict)
|
1503 | bc223d91 | Stavros Sachtouris | """
|
1504 | 277ca4ed | Dionysis Zindros | self._assert_account()
|
1505 | a23f6ffe | Stavros Sachtouris | |
1506 | 3dabe5d2 | Stavros Sachtouris | self.set_param('format', 'json') |
1507 | 3dabe5d2 | Stavros Sachtouris | self.set_param('limit', limit, iff=limit is not None) |
1508 | 3dabe5d2 | Stavros Sachtouris | self.set_param('marker', marker, iff=marker is not None) |
1509 | a23f6ffe | Stavros Sachtouris | |
1510 | a23f6ffe | Stavros Sachtouris | path = ''
|
1511 | a23f6ffe | Stavros Sachtouris | success = kwargs.pop('success', (200, 204)) |
1512 | 3dabe5d2 | Stavros Sachtouris | r = self.get(path, *args, success=success, **kwargs)
|
1513 | 38dc5d2f | Stavros Sachtouris | return r.json
|
1514 | 38dc5d2f | Stavros Sachtouris | |
1515 | bc223d91 | Stavros Sachtouris | def get_object_versionlist(self, obj): |
1516 | bc223d91 | Stavros Sachtouris | """
|
1517 | bc223d91 | Stavros Sachtouris | :param obj: (str) remote object path
|
1518 | bc223d91 | Stavros Sachtouris |
|
1519 | bc223d91 | Stavros Sachtouris | :returns: (list)
|
1520 | bc223d91 | Stavros Sachtouris | """
|
1521 | 277ca4ed | Dionysis Zindros | self._assert_container()
|
1522 | bc223d91 | Stavros Sachtouris | r = self.object_get(obj, format='json', version='list') |
1523 | 38dc5d2f | Stavros Sachtouris | return r.json['versions'] |