root / kamaki / clients / storage.py @ d88ba587
History | View | Annotate | Download (10.3 kB)
1 | 5cffe0b4 | Stavros Sachtouris | #a Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | a1c50326 | Giorgos Verigakis | #
|
3 | a1c50326 | Giorgos Verigakis | # Redistribution and use in source and binary forms, with or
|
4 | a1c50326 | Giorgos Verigakis | # without modification, are permitted provided that the following
|
5 | a1c50326 | Giorgos Verigakis | # conditions are met:
|
6 | a1c50326 | Giorgos Verigakis | #
|
7 | a1c50326 | Giorgos Verigakis | # 1. Redistributions of source code must retain the above
|
8 | a1c50326 | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
9 | a1c50326 | Giorgos Verigakis | # disclaimer.
|
10 | a1c50326 | Giorgos Verigakis | #
|
11 | a1c50326 | Giorgos Verigakis | # 2. Redistributions in binary form must reproduce the above
|
12 | a1c50326 | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
13 | a1c50326 | Giorgos Verigakis | # disclaimer in the documentation and/or other materials
|
14 | a1c50326 | Giorgos Verigakis | # provided with the distribution.
|
15 | a1c50326 | Giorgos Verigakis | #
|
16 | a1c50326 | Giorgos Verigakis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a1c50326 | Giorgos Verigakis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a1c50326 | Giorgos Verigakis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a1c50326 | Giorgos Verigakis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a1c50326 | Giorgos Verigakis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a1c50326 | Giorgos Verigakis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a1c50326 | Giorgos Verigakis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a1c50326 | Giorgos Verigakis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a1c50326 | Giorgos Verigakis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a1c50326 | Giorgos Verigakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a1c50326 | Giorgos Verigakis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a1c50326 | Giorgos Verigakis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | a1c50326 | Giorgos Verigakis | #
|
29 | a1c50326 | Giorgos Verigakis | # The views and conclusions contained in the software and
|
30 | a1c50326 | Giorgos Verigakis | # documentation are those of the authors and should not be
|
31 | a1c50326 | Giorgos Verigakis | # interpreted as representing official policies, either expressed
|
32 | a1c50326 | Giorgos Verigakis | # or implied, of GRNET S.A.
|
33 | a1c50326 | Giorgos Verigakis | |
34 | c270fe96 | Stavros Sachtouris | from kamaki.clients import Client, ClientError |
35 | 3dabe5d2 | Stavros Sachtouris | from kamaki.clients.utils import filter_in, filter_out, path4url |
36 | 3dabe5d2 | Stavros Sachtouris | |
37 | a1c50326 | Giorgos Verigakis | |
38 | 6a0b1658 | Giorgos Verigakis | class StorageClient(Client): |
39 | d2cea1e2 | Giorgos Verigakis | """OpenStack Object Storage API 1.0 client"""
|
40 | 44b8928d | Giorgos Verigakis | |
41 | 6a0b1658 | Giorgos Verigakis | def __init__(self, base_url, token, account=None, container=None): |
42 | 6ad245d5 | Stavros Sachtouris | super(StorageClient, self).__init__(base_url, token) |
43 | 6a0b1658 | Giorgos Verigakis | self.account = account
|
44 | 6a0b1658 | Giorgos Verigakis | self.container = container
|
45 | 44b8928d | Giorgos Verigakis | |
46 | d88ba587 | Stavros Sachtouris | def _assert_account(self): |
47 | 6a0b1658 | Giorgos Verigakis | if not self.account: |
48 | 2f749e6e | Stavros Sachtouris | raise ClientError("No account provided") |
49 | 44b8928d | Giorgos Verigakis | |
50 | d88ba587 | Stavros Sachtouris | def _assert_container(self): |
51 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
52 | 6a0b1658 | Giorgos Verigakis | if not self.container: |
53 | 2f749e6e | Stavros Sachtouris | raise ClientError("No container provided") |
54 | 44b8928d | Giorgos Verigakis | |
55 | d2dec8b1 | Stavros Sachtouris | def get_account_info(self): |
56 | d88ba587 | Stavros Sachtouris | """
|
57 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
58 | d88ba587 | Stavros Sachtouris | """
|
59 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
60 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account)
|
61 | d2dec8b1 | Stavros Sachtouris | r = self.head(path, success=(204, 401)) |
62 | d2dec8b1 | Stavros Sachtouris | if r.status_code == 401: |
63 | d2dec8b1 | Stavros Sachtouris | raise ClientError("No authorization") |
64 | 5b263ba2 | Stavros Sachtouris | reply = r.headers |
65 | 5b263ba2 | Stavros Sachtouris | return reply
|
66 | d2dec8b1 | Stavros Sachtouris | |
67 | af3b2b36 | Stavros Sachtouris | def replace_account_meta(self, metapairs): |
68 | d88ba587 | Stavros Sachtouris | """
|
69 | d88ba587 | Stavros Sachtouris | :param metapais: (dict) key:val metadata pairs
|
70 | d88ba587 | Stavros Sachtouris | """
|
71 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
72 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account)
|
73 | 3dabe5d2 | Stavros Sachtouris | for key, val in metapairs: |
74 | 3dabe5d2 | Stavros Sachtouris | self.set_header('X-Account-Meta-' + key, val) |
75 | 5b263ba2 | Stavros Sachtouris | r = self.post(path, success=202) |
76 | 3dabe5d2 | Stavros Sachtouris | r.release() |
77 | 0e4bec91 | Stavros Sachtouris | |
78 | 379cd4bb | Stavros Sachtouris | def del_account_meta(self, metakey): |
79 | d88ba587 | Stavros Sachtouris | """
|
80 | d88ba587 | Stavros Sachtouris | :param metakey: (str) metadatum key
|
81 | d88ba587 | Stavros Sachtouris | """
|
82 | e6b39366 | Stavros Sachtouris | headers = self.get_account_info()
|
83 | 3dabe5d2 | Stavros Sachtouris | self.headers = filter_out(headers,
|
84 | 3dabe5d2 | Stavros Sachtouris | 'X-Account-Meta-' + metakey,
|
85 | 3dabe5d2 | Stavros Sachtouris | exactMatch=True)
|
86 | e742badc | Stavros Sachtouris | if len(self.headers) == len(headers): |
87 | e6b39366 | Stavros Sachtouris | raise ClientError('X-Account-Meta-%s not found' % metakey, 404) |
88 | e6b39366 | Stavros Sachtouris | path = path4url(self.account)
|
89 | 3dabe5d2 | Stavros Sachtouris | r = self.post(path, success=202) |
90 | 3dabe5d2 | Stavros Sachtouris | r.release() |
91 | 0e4bec91 | Stavros Sachtouris | |
92 | 60560d7c | Giorgos Verigakis | def create_container(self, container): |
93 | d88ba587 | Stavros Sachtouris | """
|
94 | d88ba587 | Stavros Sachtouris | :param container: (str)
|
95 | d88ba587 | Stavros Sachtouris |
|
96 | d88ba587 | Stavros Sachtouris | :raises ClientError: 202 Container already exists
|
97 | d88ba587 | Stavros Sachtouris | """
|
98 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
99 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account, container)
|
100 | 6a0b1658 | Giorgos Verigakis | r = self.put(path, success=(201, 202)) |
101 | d88ba587 | Stavros Sachtouris | r.release() |
102 | 6a0b1658 | Giorgos Verigakis | if r.status_code == 202: |
103 | 16d445fe | Giorgos Verigakis | raise ClientError("Container already exists", r.status_code) |
104 | 44b8928d | Giorgos Verigakis | |
105 | 6c4778ae | Stavros Sachtouris | def get_container_info(self, container): |
106 | d88ba587 | Stavros Sachtouris | """
|
107 | d88ba587 | Stavros Sachtouris | :param container: (str)
|
108 | d88ba587 | Stavros Sachtouris |
|
109 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
110 | d88ba587 | Stavros Sachtouris |
|
111 | d88ba587 | Stavros Sachtouris | :raises ClientError: 404 Container does not exist
|
112 | d88ba587 | Stavros Sachtouris | """
|
113 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
114 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account, container)
|
115 | 6a0b1658 | Giorgos Verigakis | r = self.head(path, success=(204, 404)) |
116 | 6a0b1658 | Giorgos Verigakis | if r.status_code == 404: |
117 | 6a0b1658 | Giorgos Verigakis | raise ClientError("Container does not exist", r.status_code) |
118 | 5b263ba2 | Stavros Sachtouris | reply = r.headers |
119 | 5b263ba2 | Stavros Sachtouris | return reply
|
120 | 44b8928d | Giorgos Verigakis | |
121 | b66dfee7 | Stavros Sachtouris | def delete_container(self, container): |
122 | d88ba587 | Stavros Sachtouris | """
|
123 | d88ba587 | Stavros Sachtouris | :param container: (str)
|
124 | d88ba587 | Stavros Sachtouris |
|
125 | d88ba587 | Stavros Sachtouris | :raises ClientError: 404 Container does not exist
|
126 | d88ba587 | Stavros Sachtouris | :raises ClientError: 409 Container not empty
|
127 | d88ba587 | Stavros Sachtouris | """
|
128 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
129 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account, container)
|
130 | b66dfee7 | Stavros Sachtouris | r = self.delete(path, success=(204, 404, 409)) |
131 | b66dfee7 | Stavros Sachtouris | if r.status_code == 404: |
132 | b66dfee7 | Stavros Sachtouris | raise ClientError("Container does not exist", r.status_code) |
133 | b66dfee7 | Stavros Sachtouris | elif r.status_code == 409: |
134 | b66dfee7 | Stavros Sachtouris | raise ClientError("Container is not empty", r.status_code) |
135 | b66dfee7 | Stavros Sachtouris | |
136 | 11f8eed3 | Stavros Sachtouris | def list_containers(self): |
137 | d88ba587 | Stavros Sachtouris | """
|
138 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
139 | d88ba587 | Stavros Sachtouris | """
|
140 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
141 | 2f749e6e | Stavros Sachtouris | self.set_param('format', 'json') |
142 | 2f749e6e | Stavros Sachtouris | path = path4url(self.account)
|
143 | 3dabe5d2 | Stavros Sachtouris | r = self.get(path, success=(200, 204)) |
144 | 5b263ba2 | Stavros Sachtouris | reply = r.json |
145 | 5b263ba2 | Stavros Sachtouris | return reply
|
146 | 11f8eed3 | Stavros Sachtouris | |
147 | d88ba587 | Stavros Sachtouris | def upload_object(self, obj, f, size=None): |
148 | d88ba587 | Stavros Sachtouris | """ A simple (naive) implementation.
|
149 | d88ba587 | Stavros Sachtouris |
|
150 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
151 | d88ba587 | Stavros Sachtouris |
|
152 | d88ba587 | Stavros Sachtouris | :param f: an open for reading file descriptor
|
153 | d88ba587 | Stavros Sachtouris |
|
154 | d88ba587 | Stavros Sachtouris | :param size: (int) number of bytes to upload
|
155 | d88ba587 | Stavros Sachtouris | """
|
156 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
157 | d88ba587 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
158 | 188f23b9 | Giorgos Verigakis | data = f.read(size) if size is not None else f.read() |
159 | 5b263ba2 | Stavros Sachtouris | r = self.put(path, data=data, success=201) |
160 | 3dabe5d2 | Stavros Sachtouris | r.release() |
161 | 44b8928d | Giorgos Verigakis | |
162 | d88ba587 | Stavros Sachtouris | def create_directory(self, obj): |
163 | d88ba587 | Stavros Sachtouris | """
|
164 | d88ba587 | Stavros Sachtouris | :param obj: (str) directory-object name
|
165 | d88ba587 | Stavros Sachtouris | """
|
166 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
167 | d88ba587 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
168 | 4e68908f | Stavros Sachtouris | self.set_header('Content-Type', 'application/directory') |
169 | 4e68908f | Stavros Sachtouris | self.set_header('Content-length', '0') |
170 | 5b263ba2 | Stavros Sachtouris | r = self.put(path, success=201) |
171 | 3dabe5d2 | Stavros Sachtouris | r.release() |
172 | f3a722d4 | Stavros Sachtouris | |
173 | d88ba587 | Stavros Sachtouris | def get_object_info(self, obj): |
174 | d88ba587 | Stavros Sachtouris | """
|
175 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
176 | d88ba587 | Stavros Sachtouris |
|
177 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
178 | d88ba587 | Stavros Sachtouris | """
|
179 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
180 | d88ba587 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
181 | 6c4778ae | Stavros Sachtouris | r = self.head(path, success=200) |
182 | 5b263ba2 | Stavros Sachtouris | reply = r.headers |
183 | 5b263ba2 | Stavros Sachtouris | return reply
|
184 | 6c4778ae | Stavros Sachtouris | |
185 | d88ba587 | Stavros Sachtouris | def get_object_meta(self, obj): |
186 | d88ba587 | Stavros Sachtouris | """
|
187 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
188 | d88ba587 | Stavros Sachtouris |
|
189 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
190 | d88ba587 | Stavros Sachtouris | """
|
191 | d88ba587 | Stavros Sachtouris | r = filter_in(self.get_object_info(obj), 'X-Object-Meta-') |
192 | f70616fc | Stavros Sachtouris | reply = {} |
193 | f70616fc | Stavros Sachtouris | for (key, val) in r.items(): |
194 | f70616fc | Stavros Sachtouris | metakey = key.split('-')[-1] |
195 | f70616fc | Stavros Sachtouris | reply[metakey] = val |
196 | f70616fc | Stavros Sachtouris | return reply
|
197 | e6b39366 | Stavros Sachtouris | |
198 | 4375e020 | Stavros Sachtouris | def del_object_meta(self, obj, metakey): |
199 | d88ba587 | Stavros Sachtouris | """
|
200 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
201 | d88ba587 | Stavros Sachtouris |
|
202 | d88ba587 | Stavros Sachtouris | :param metakey: (str) the metadatum key
|
203 | d88ba587 | Stavros Sachtouris | """
|
204 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
205 | 3dabe5d2 | Stavros Sachtouris | self.set_header('X-Object-Meta-' + metakey, '') |
206 | 4375e020 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
207 | 3dabe5d2 | Stavros Sachtouris | r = self.post(path, success=202) |
208 | 3dabe5d2 | Stavros Sachtouris | r.release() |
209 | d0b42fb4 | Stavros Sachtouris | |
210 | e742badc | Stavros Sachtouris | def replace_object_meta(self, metapairs): |
211 | d88ba587 | Stavros Sachtouris | """
|
212 | d88ba587 | Stavros Sachtouris | :param metapairs: (dict) key:val metadata
|
213 | d88ba587 | Stavros Sachtouris | """
|
214 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
215 | 3dabe5d2 | Stavros Sachtouris | path = path4url(self.account, self.container) |
216 | e742badc | Stavros Sachtouris | for key, val in metapairs: |
217 | 3dabe5d2 | Stavros Sachtouris | self.set_header('X-Object-Meta-' + key, val) |
218 | 5b263ba2 | Stavros Sachtouris | r = self.post(path, success=202) |
219 | 3dabe5d2 | Stavros Sachtouris | r.release() |
220 | 0e4bec91 | Stavros Sachtouris | |
221 | d88ba587 | Stavros Sachtouris | def get_object(self, obj): |
222 | d88ba587 | Stavros Sachtouris | """
|
223 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
224 | d88ba587 | Stavros Sachtouris |
|
225 | d88ba587 | Stavros Sachtouris | :returns: (int, int) # of objects, size in bytes
|
226 | d88ba587 | Stavros Sachtouris | """
|
227 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
228 | d88ba587 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
229 | 2f749e6e | Stavros Sachtouris | r = self.get(path, success=200) |
230 | 6a0b1658 | Giorgos Verigakis | size = int(r.headers['content-length']) |
231 | 5b263ba2 | Stavros Sachtouris | cnt = r.content |
232 | 5b263ba2 | Stavros Sachtouris | return cnt, size
|
233 | 44b8928d | Giorgos Verigakis | |
234 | 3dabe5d2 | Stavros Sachtouris | def copy_object(self, src_container, src_object, dst_container, |
235 | 3dabe5d2 | Stavros Sachtouris | dst_object=False):
|
236 | d88ba587 | Stavros Sachtouris | """Copy an objects from src_contaier:src_object to
|
237 | d88ba587 | Stavros Sachtouris | dst_container[:dst_object]
|
238 | d88ba587 | Stavros Sachtouris |
|
239 | d88ba587 | Stavros Sachtouris | :param src_container: (str)
|
240 | d88ba587 | Stavros Sachtouris |
|
241 | d88ba587 | Stavros Sachtouris | :param src_object: (str)
|
242 | d88ba587 | Stavros Sachtouris |
|
243 | d88ba587 | Stavros Sachtouris | :param dst_container: (str)
|
244 | d88ba587 | Stavros Sachtouris |
|
245 | d88ba587 | Stavros Sachtouris | :param dst_object: (str)
|
246 | d88ba587 | Stavros Sachtouris | """
|
247 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
248 | c2867610 | Stavros Sachtouris | dst_object = dst_object or src_object
|
249 | c2867610 | Stavros Sachtouris | dst_path = path4url(self.account, dst_container, dst_object)
|
250 | c2867610 | Stavros Sachtouris | self.set_header('X-Copy-From', path4url(src_container, src_object)) |
251 | c2867610 | Stavros Sachtouris | self.set_header('Content-Length', 0) |
252 | 5b263ba2 | Stavros Sachtouris | r = self.put(dst_path, success=201) |
253 | 3dabe5d2 | Stavros Sachtouris | r.release() |
254 | c2867610 | Stavros Sachtouris | |
255 | 3dabe5d2 | Stavros Sachtouris | def move_object(self, src_container, src_object, dst_container, |
256 | 3dabe5d2 | Stavros Sachtouris | dst_object=False):
|
257 | d88ba587 | Stavros Sachtouris | """Move an objects from src_contaier:src_object to
|
258 | d88ba587 | Stavros Sachtouris | dst_container[:dst_object]
|
259 | d88ba587 | Stavros Sachtouris |
|
260 | d88ba587 | Stavros Sachtouris | :param src_container: (str)
|
261 | d88ba587 | Stavros Sachtouris |
|
262 | d88ba587 | Stavros Sachtouris | :param src_object: (str)
|
263 | d88ba587 | Stavros Sachtouris |
|
264 | d88ba587 | Stavros Sachtouris | :param dst_container: (str)
|
265 | d88ba587 | Stavros Sachtouris |
|
266 | d88ba587 | Stavros Sachtouris | :param dst_object: (str)
|
267 | d88ba587 | Stavros Sachtouris | """
|
268 | d88ba587 | Stavros Sachtouris | self._assert_account()
|
269 | eed330ab | Stavros Sachtouris | dst_object = dst_object or src_object
|
270 | eed330ab | Stavros Sachtouris | dst_path = path4url(self.account, dst_container, dst_object)
|
271 | eed330ab | Stavros Sachtouris | self.set_header('X-Move-From', path4url(src_container, src_object)) |
272 | eed330ab | Stavros Sachtouris | self.set_header('Content-Length', 0) |
273 | 5b263ba2 | Stavros Sachtouris | r = self.put(dst_path, success=201) |
274 | 3dabe5d2 | Stavros Sachtouris | r.release() |
275 | eed330ab | Stavros Sachtouris | |
276 | d88ba587 | Stavros Sachtouris | def delete_object(self, obj): |
277 | d88ba587 | Stavros Sachtouris | """
|
278 | d88ba587 | Stavros Sachtouris | :param obj: (str)
|
279 | d88ba587 | Stavros Sachtouris |
|
280 | d88ba587 | Stavros Sachtouris | :raises ClientError: 404 Object not found
|
281 | d88ba587 | Stavros Sachtouris | """
|
282 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
283 | d88ba587 | Stavros Sachtouris | path = path4url(self.account, self.container, obj) |
284 | bebdd0d6 | Stavros Sachtouris | r = self.delete(path, success=(204, 404)) |
285 | bebdd0d6 | Stavros Sachtouris | if r.status_code == 404: |
286 | d88ba587 | Stavros Sachtouris | raise ClientError("Object %s not found" % obj, r.status_code) |
287 | 3dabe5d2 | Stavros Sachtouris | |
288 | e2bd16d5 | Stavros Sachtouris | def list_objects(self): |
289 | d88ba587 | Stavros Sachtouris | """
|
290 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
291 | d88ba587 | Stavros Sachtouris |
|
292 | d88ba587 | Stavros Sachtouris | :raises ClientError: 404 Invalid account
|
293 | d88ba587 | Stavros Sachtouris | """
|
294 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
295 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account, self.container) |
296 | 2f749e6e | Stavros Sachtouris | self.set_param('format', 'json') |
297 | 2f749e6e | Stavros Sachtouris | r = self.get(path, success=(200, 204, 304, 404), ) |
298 | 175f40ab | Stavros Sachtouris | if r.status_code == 404: |
299 | 3dabe5d2 | Stavros Sachtouris | raise ClientError(\
|
300 | d88ba587 | Stavros Sachtouris | "Invalid account (%s) for that container" % self.account, |
301 | 3dabe5d2 | Stavros Sachtouris | r.status_code) |
302 | 16ce7b91 | Stavros Sachtouris | elif r.status_code == 304: |
303 | 16ce7b91 | Stavros Sachtouris | return []
|
304 | 5b263ba2 | Stavros Sachtouris | reply = r.json |
305 | 5b263ba2 | Stavros Sachtouris | return reply
|
306 | e2bd16d5 | Stavros Sachtouris | |
307 | e2bd16d5 | Stavros Sachtouris | def list_objects_in_path(self, path_prefix): |
308 | d88ba587 | Stavros Sachtouris | """
|
309 | d88ba587 | Stavros Sachtouris | :param path_prefix: (str)
|
310 | d88ba587 | Stavros Sachtouris |
|
311 | d88ba587 | Stavros Sachtouris | :raises ClientError: 404 Invalid account
|
312 | d88ba587 | Stavros Sachtouris |
|
313 | d88ba587 | Stavros Sachtouris | :returns: (dict)
|
314 | d88ba587 | Stavros Sachtouris | """
|
315 | d88ba587 | Stavros Sachtouris | self._assert_container()
|
316 | af3b2b36 | Stavros Sachtouris | path = path4url(self.account, self.container) |
317 | 2f749e6e | Stavros Sachtouris | self.set_param('format', 'json') |
318 | 2f749e6e | Stavros Sachtouris | self.set_param('path', 'path_prefix') |
319 | 2f749e6e | Stavros Sachtouris | r = self.get(path, success=(200, 204, 404)) |
320 | a79f6d30 | Stavros Sachtouris | if r.status_code == 404: |
321 | 3dabe5d2 | Stavros Sachtouris | raise ClientError(\
|
322 | d88ba587 | Stavros Sachtouris | "Invalid account (%s) for that container" % self.account, |
323 | 3dabe5d2 | Stavros Sachtouris | r.status_code) |
324 | 5b263ba2 | Stavros Sachtouris | reply = r.json |
325 | 5b263ba2 | Stavros Sachtouris | return reply |