Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / storage / __init__.py @ 4f0576d8

History | View | Annotate | Download (11.5 kB)

1 4f0576d8 Stavros Sachtouris
# Copyright 2011-2013 GRNET S.A. All rights reserved.
2 3e6f33ca Stavros Sachtouris
#
3 3e6f33ca Stavros Sachtouris
# Redistribution and use in source and binary forms, with or
4 3e6f33ca Stavros Sachtouris
# without modification, are permitted provided that the following
5 3e6f33ca Stavros Sachtouris
# conditions are met:
6 3e6f33ca Stavros Sachtouris
#
7 3e6f33ca Stavros Sachtouris
#   1. Redistributions of source code must retain the above
8 3e6f33ca Stavros Sachtouris
#      copyright notice, this list of conditions and the following
9 3e6f33ca Stavros Sachtouris
#      disclaimer.
10 3e6f33ca Stavros Sachtouris
#
11 3e6f33ca Stavros Sachtouris
#   2. Redistributions in binary form must reproduce the above
12 3e6f33ca Stavros Sachtouris
#      copyright notice, this list of conditions and the following
13 3e6f33ca Stavros Sachtouris
#      disclaimer in the documentation and/or other materials
14 3e6f33ca Stavros Sachtouris
#      provided with the distribution.
15 3e6f33ca Stavros Sachtouris
#
16 3e6f33ca Stavros Sachtouris
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 3e6f33ca Stavros Sachtouris
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 3e6f33ca Stavros Sachtouris
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 3e6f33ca Stavros Sachtouris
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 3e6f33ca Stavros Sachtouris
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 3e6f33ca Stavros Sachtouris
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 3e6f33ca Stavros Sachtouris
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 3e6f33ca Stavros Sachtouris
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 3e6f33ca Stavros Sachtouris
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 3e6f33ca Stavros Sachtouris
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 3e6f33ca Stavros Sachtouris
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 3e6f33ca Stavros Sachtouris
# POSSIBILITY OF SUCH DAMAGE.
28 3e6f33ca Stavros Sachtouris
#
29 3e6f33ca Stavros Sachtouris
# The views and conclusions contained in the software and
30 3e6f33ca Stavros Sachtouris
# documentation are those of the authors and should not be
31 3e6f33ca Stavros Sachtouris
# interpreted as representing official policies, either expressed
32 3e6f33ca Stavros Sachtouris
# or implied, of GRNET S.A.
33 3e6f33ca Stavros Sachtouris
34 3e6f33ca Stavros Sachtouris
from kamaki.clients import Client, ClientError
35 3e6f33ca Stavros Sachtouris
from kamaki.clients.utils import filter_in, filter_out, path4url
36 3e6f33ca Stavros Sachtouris
37 3e6f33ca Stavros Sachtouris
38 3e6f33ca Stavros Sachtouris
class StorageClient(Client):
39 3e6f33ca Stavros Sachtouris
    """OpenStack Object Storage API 1.0 client"""
40 3e6f33ca Stavros Sachtouris
41 3e6f33ca Stavros Sachtouris
    def __init__(self, base_url, token, account=None, container=None):
42 3e6f33ca Stavros Sachtouris
        super(StorageClient, self).__init__(base_url, token)
43 3e6f33ca Stavros Sachtouris
        self.account = account
44 3e6f33ca Stavros Sachtouris
        self.container = container
45 3e6f33ca Stavros Sachtouris
46 3e6f33ca Stavros Sachtouris
    def _assert_account(self):
47 3e6f33ca Stavros Sachtouris
        if not self.account:
48 3e6f33ca Stavros Sachtouris
            raise ClientError("No account provided")
49 3e6f33ca Stavros Sachtouris
50 3e6f33ca Stavros Sachtouris
    def _assert_container(self):
51 3e6f33ca Stavros Sachtouris
        self._assert_account()
52 3e6f33ca Stavros Sachtouris
        if not self.container:
53 3e6f33ca Stavros Sachtouris
            raise ClientError("No container provided")
54 3e6f33ca Stavros Sachtouris
55 3e6f33ca Stavros Sachtouris
    def get_account_info(self):
56 3e6f33ca Stavros Sachtouris
        """
57 3e6f33ca Stavros Sachtouris
        :returns: (dict)
58 3e6f33ca Stavros Sachtouris
        """
59 3e6f33ca Stavros Sachtouris
        self._assert_account()
60 3e6f33ca Stavros Sachtouris
        path = path4url(self.account)
61 3e6f33ca Stavros Sachtouris
        r = self.head(path, success=(204, 401))
62 3e6f33ca Stavros Sachtouris
        if r.status_code == 401:
63 3e6f33ca Stavros Sachtouris
            raise ClientError("No authorization", status=401)
64 3e6f33ca Stavros Sachtouris
        reply = r.headers
65 3e6f33ca Stavros Sachtouris
        return reply
66 3e6f33ca Stavros Sachtouris
67 3e6f33ca Stavros Sachtouris
    def replace_account_meta(self, metapairs):
68 3e6f33ca Stavros Sachtouris
        """
69 3e6f33ca Stavros Sachtouris
        :param metapais: (dict) key:val metadata pairs
70 3e6f33ca Stavros Sachtouris
        """
71 3e6f33ca Stavros Sachtouris
        self._assert_account()
72 3e6f33ca Stavros Sachtouris
        path = path4url(self.account)
73 3e6f33ca Stavros Sachtouris
        for key, val in metapairs.items():
74 3e6f33ca Stavros Sachtouris
            self.set_header('X-Account-Meta-' + key, val)
75 c2b5da2f Stavros Sachtouris
        self.post(path, success=202)
76 3e6f33ca Stavros Sachtouris
77 3e6f33ca Stavros Sachtouris
    def del_account_meta(self, metakey):
78 3e6f33ca Stavros Sachtouris
        """
79 3e6f33ca Stavros Sachtouris
        :param metakey: (str) metadatum key
80 3e6f33ca Stavros Sachtouris
        """
81 3e6f33ca Stavros Sachtouris
        headers = self.get_account_info()
82 3e6f33ca Stavros Sachtouris
        self.headers = filter_out(
83 3e6f33ca Stavros Sachtouris
            headers,
84 3e6f33ca Stavros Sachtouris
            'X-Account-Meta-' + metakey,
85 3e6f33ca Stavros Sachtouris
            exactMatch=True)
86 3e6f33ca Stavros Sachtouris
        if len(self.headers) == len(headers):
87 3e6f33ca Stavros Sachtouris
            raise ClientError('X-Account-Meta-%s not found' % metakey, 404)
88 3e6f33ca Stavros Sachtouris
        path = path4url(self.account)
89 c2b5da2f Stavros Sachtouris
        self.post(path, success=202)
90 3e6f33ca Stavros Sachtouris
91 3e6f33ca Stavros Sachtouris
    def create_container(self, container):
92 3e6f33ca Stavros Sachtouris
        """
93 3e6f33ca Stavros Sachtouris
        :param container: (str)
94 3e6f33ca Stavros Sachtouris

95 3e6f33ca Stavros Sachtouris
        :raises ClientError: 202 Container already exists
96 3e6f33ca Stavros Sachtouris
        """
97 3e6f33ca Stavros Sachtouris
        self._assert_account()
98 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, container)
99 3e6f33ca Stavros Sachtouris
        r = self.put(path, success=(201, 202))
100 3e6f33ca Stavros Sachtouris
        if r.status_code == 202:
101 3e6f33ca Stavros Sachtouris
            raise ClientError("Container already exists", r.status_code)
102 3e6f33ca Stavros Sachtouris
103 3e6f33ca Stavros Sachtouris
    def get_container_info(self, container):
104 3e6f33ca Stavros Sachtouris
        """
105 3e6f33ca Stavros Sachtouris
        :param container: (str)
106 3e6f33ca Stavros Sachtouris

107 3e6f33ca Stavros Sachtouris
        :returns: (dict)
108 3e6f33ca Stavros Sachtouris

109 3e6f33ca Stavros Sachtouris
        :raises ClientError: 404 Container does not exist
110 3e6f33ca Stavros Sachtouris
        """
111 3e6f33ca Stavros Sachtouris
        self._assert_account()
112 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, container)
113 3e6f33ca Stavros Sachtouris
        r = self.head(path, success=(204, 404))
114 3e6f33ca Stavros Sachtouris
        if r.status_code == 404:
115 3e6f33ca Stavros Sachtouris
            raise ClientError("Container does not exist", r.status_code)
116 3e6f33ca Stavros Sachtouris
        reply = r.headers
117 3e6f33ca Stavros Sachtouris
        return reply
118 3e6f33ca Stavros Sachtouris
119 3e6f33ca Stavros Sachtouris
    def delete_container(self, container):
120 3e6f33ca Stavros Sachtouris
        """
121 3e6f33ca Stavros Sachtouris
        :param container: (str)
122 3e6f33ca Stavros Sachtouris

123 3e6f33ca Stavros Sachtouris
        :raises ClientError: 404 Container does not exist
124 3e6f33ca Stavros Sachtouris
        :raises ClientError: 409 Container not empty
125 3e6f33ca Stavros Sachtouris
        """
126 3e6f33ca Stavros Sachtouris
        self._assert_account()
127 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, container)
128 3e6f33ca Stavros Sachtouris
        r = self.delete(path, success=(204, 404, 409))
129 3e6f33ca Stavros Sachtouris
        if r.status_code == 404:
130 3e6f33ca Stavros Sachtouris
            raise ClientError("Container does not exist", r.status_code)
131 3e6f33ca Stavros Sachtouris
        elif r.status_code == 409:
132 3e6f33ca Stavros Sachtouris
            raise ClientError("Container is not empty", r.status_code)
133 3e6f33ca Stavros Sachtouris
134 3e6f33ca Stavros Sachtouris
    def list_containers(self):
135 3e6f33ca Stavros Sachtouris
        """
136 3e6f33ca Stavros Sachtouris
        :returns: (dict)
137 3e6f33ca Stavros Sachtouris
        """
138 3e6f33ca Stavros Sachtouris
        self._assert_account()
139 3e6f33ca Stavros Sachtouris
        self.set_param('format', 'json')
140 3e6f33ca Stavros Sachtouris
        path = path4url(self.account)
141 3e6f33ca Stavros Sachtouris
        r = self.get(path, success=(200, 204))
142 3e6f33ca Stavros Sachtouris
        reply = r.json
143 3e6f33ca Stavros Sachtouris
        return reply
144 3e6f33ca Stavros Sachtouris
145 3e6f33ca Stavros Sachtouris
    def upload_object(self, obj, f, size=None):
146 3e6f33ca Stavros Sachtouris
        """ A simple (naive) implementation.
147 3e6f33ca Stavros Sachtouris

148 3e6f33ca Stavros Sachtouris
        :param obj: (str)
149 3e6f33ca Stavros Sachtouris

150 3e6f33ca Stavros Sachtouris
        :param f: an open for reading file descriptor
151 3e6f33ca Stavros Sachtouris

152 3e6f33ca Stavros Sachtouris
        :param size: (int) number of bytes to upload
153 3e6f33ca Stavros Sachtouris
        """
154 3e6f33ca Stavros Sachtouris
        self._assert_container()
155 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
156 c2bf1c19 Stavros Sachtouris
        data = f.read(size) if size else f.read()
157 c2b5da2f Stavros Sachtouris
        self.put(path, data=data, success=201)
158 3e6f33ca Stavros Sachtouris
159 3e6f33ca Stavros Sachtouris
    def create_object(
160 3e6f33ca Stavros Sachtouris
            self, obj,
161 3e6f33ca Stavros Sachtouris
            content_type='application/octet-stream', content_length=0):
162 3e6f33ca Stavros Sachtouris
        """
163 3e6f33ca Stavros Sachtouris
        :param obj: (str) directory-object name
164 94bedc5b Stavros Sachtouris

165 3e6f33ca Stavros Sachtouris
        :param content_type: (str) explicitly set content_type
166 94bedc5b Stavros Sachtouris

167 3e6f33ca Stavros Sachtouris
        :param content_length: (int) explicitly set content length
168 94bedc5b Stavros Sachtouris

169 94bedc5b Stavros Sachtouris
        :returns: (dict) object creation headers
170 3e6f33ca Stavros Sachtouris
        """
171 3e6f33ca Stavros Sachtouris
        self._assert_container()
172 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
173 3e6f33ca Stavros Sachtouris
        self.set_header('Content-Type', content_type)
174 3e6f33ca Stavros Sachtouris
        self.set_header('Content-length', str(content_length))
175 94bedc5b Stavros Sachtouris
        r = self.put(path, success=201)
176 94bedc5b Stavros Sachtouris
        return r.headers
177 3e6f33ca Stavros Sachtouris
178 3e6f33ca Stavros Sachtouris
    def create_directory(self, obj):
179 3e6f33ca Stavros Sachtouris
        """
180 3e6f33ca Stavros Sachtouris
        :param obj: (str) directory-object name
181 94bedc5b Stavros Sachtouris

182 94bedc5b Stavros Sachtouris
        :returns: (dict) request headers
183 3e6f33ca Stavros Sachtouris
        """
184 3e6f33ca Stavros Sachtouris
        self._assert_container()
185 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
186 3e6f33ca Stavros Sachtouris
        self.set_header('Content-Type', 'application/directory')
187 3e6f33ca Stavros Sachtouris
        self.set_header('Content-length', '0')
188 94bedc5b Stavros Sachtouris
        r = self.put(path, success=201)
189 94bedc5b Stavros Sachtouris
        return r.headers
190 3e6f33ca Stavros Sachtouris
191 3e6f33ca Stavros Sachtouris
    def get_object_info(self, obj):
192 3e6f33ca Stavros Sachtouris
        """
193 3e6f33ca Stavros Sachtouris
        :param obj: (str)
194 3e6f33ca Stavros Sachtouris

195 3e6f33ca Stavros Sachtouris
        :returns: (dict)
196 3e6f33ca Stavros Sachtouris
        """
197 3e6f33ca Stavros Sachtouris
        self._assert_container()
198 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
199 3e6f33ca Stavros Sachtouris
        r = self.head(path, success=200)
200 3e6f33ca Stavros Sachtouris
        reply = r.headers
201 3e6f33ca Stavros Sachtouris
        return reply
202 3e6f33ca Stavros Sachtouris
203 3e6f33ca Stavros Sachtouris
    def get_object_meta(self, obj):
204 3e6f33ca Stavros Sachtouris
        """
205 3e6f33ca Stavros Sachtouris
        :param obj: (str)
206 3e6f33ca Stavros Sachtouris

207 3e6f33ca Stavros Sachtouris
        :returns: (dict)
208 3e6f33ca Stavros Sachtouris
        """
209 3e6f33ca Stavros Sachtouris
        r = filter_in(self.get_object_info(obj), 'X-Object-Meta-')
210 3e6f33ca Stavros Sachtouris
        reply = {}
211 3e6f33ca Stavros Sachtouris
        for (key, val) in r.items():
212 3e6f33ca Stavros Sachtouris
            metakey = key.split('-')[-1]
213 3e6f33ca Stavros Sachtouris
            reply[metakey] = val
214 3e6f33ca Stavros Sachtouris
        return reply
215 3e6f33ca Stavros Sachtouris
216 3e6f33ca Stavros Sachtouris
    def del_object_meta(self, obj, metakey):
217 3e6f33ca Stavros Sachtouris
        """
218 3e6f33ca Stavros Sachtouris
        :param obj: (str)
219 3e6f33ca Stavros Sachtouris

220 3e6f33ca Stavros Sachtouris
        :param metakey: (str) the metadatum key
221 3e6f33ca Stavros Sachtouris
        """
222 3e6f33ca Stavros Sachtouris
        self._assert_container()
223 3e6f33ca Stavros Sachtouris
        self.set_header('X-Object-Meta-' + metakey, '')
224 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
225 c2b5da2f Stavros Sachtouris
        self.post(path, success=202)
226 3e6f33ca Stavros Sachtouris
227 3e6f33ca Stavros Sachtouris
    def replace_object_meta(self, metapairs):
228 3e6f33ca Stavros Sachtouris
        """
229 3e6f33ca Stavros Sachtouris
        :param metapairs: (dict) key:val metadata
230 3e6f33ca Stavros Sachtouris
        """
231 3e6f33ca Stavros Sachtouris
        self._assert_container()
232 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container)
233 3e6f33ca Stavros Sachtouris
        for key, val in metapairs.items():
234 3e6f33ca Stavros Sachtouris
            self.set_header('X-Object-Meta-' + key, val)
235 c2b5da2f Stavros Sachtouris
        self.post(path, success=202)
236 3e6f33ca Stavros Sachtouris
237 3e6f33ca Stavros Sachtouris
    def copy_object(
238 3e6f33ca Stavros Sachtouris
            self, src_container, src_object, dst_container,
239 3e6f33ca Stavros Sachtouris
            dst_object=False):
240 3e6f33ca Stavros Sachtouris
        """Copy an objects from src_contaier:src_object to
241 3e6f33ca Stavros Sachtouris
            dst_container[:dst_object]
242 3e6f33ca Stavros Sachtouris

243 3e6f33ca Stavros Sachtouris
        :param src_container: (str)
244 3e6f33ca Stavros Sachtouris

245 3e6f33ca Stavros Sachtouris
        :param src_object: (str)
246 3e6f33ca Stavros Sachtouris

247 3e6f33ca Stavros Sachtouris
        :param dst_container: (str)
248 3e6f33ca Stavros Sachtouris

249 3e6f33ca Stavros Sachtouris
        :param dst_object: (str)
250 3e6f33ca Stavros Sachtouris
        """
251 3e6f33ca Stavros Sachtouris
        self._assert_account()
252 3e6f33ca Stavros Sachtouris
        dst_object = dst_object or src_object
253 3e6f33ca Stavros Sachtouris
        dst_path = path4url(self.account, dst_container, dst_object)
254 3e6f33ca Stavros Sachtouris
        self.set_header('X-Copy-From', path4url(src_container, src_object))
255 3e6f33ca Stavros Sachtouris
        self.set_header('Content-Length', 0)
256 c2b5da2f Stavros Sachtouris
        self.put(dst_path, success=201)
257 3e6f33ca Stavros Sachtouris
258 3e6f33ca Stavros Sachtouris
    def move_object(
259 3e6f33ca Stavros Sachtouris
            self, src_container, src_object, dst_container,
260 3e6f33ca Stavros Sachtouris
            dst_object=False):
261 3e6f33ca Stavros Sachtouris
        """Move an objects from src_contaier:src_object to
262 3e6f33ca Stavros Sachtouris
            dst_container[:dst_object]
263 3e6f33ca Stavros Sachtouris

264 3e6f33ca Stavros Sachtouris
        :param src_container: (str)
265 3e6f33ca Stavros Sachtouris

266 3e6f33ca Stavros Sachtouris
        :param src_object: (str)
267 3e6f33ca Stavros Sachtouris

268 3e6f33ca Stavros Sachtouris
        :param dst_container: (str)
269 3e6f33ca Stavros Sachtouris

270 3e6f33ca Stavros Sachtouris
        :param dst_object: (str)
271 3e6f33ca Stavros Sachtouris
        """
272 3e6f33ca Stavros Sachtouris
        self._assert_account()
273 3e6f33ca Stavros Sachtouris
        dst_object = dst_object or src_object
274 3e6f33ca Stavros Sachtouris
        dst_path = path4url(self.account, dst_container, dst_object)
275 3e6f33ca Stavros Sachtouris
        self.set_header('X-Move-From', path4url(src_container, src_object))
276 3e6f33ca Stavros Sachtouris
        self.set_header('Content-Length', 0)
277 c2b5da2f Stavros Sachtouris
        self.put(dst_path, success=201)
278 3e6f33ca Stavros Sachtouris
279 3e6f33ca Stavros Sachtouris
    def delete_object(self, obj):
280 3e6f33ca Stavros Sachtouris
        """
281 3e6f33ca Stavros Sachtouris
        :param obj: (str)
282 3e6f33ca Stavros Sachtouris

283 3e6f33ca Stavros Sachtouris
        :raises ClientError: 404 Object not found
284 3e6f33ca Stavros Sachtouris
        """
285 3e6f33ca Stavros Sachtouris
        self._assert_container()
286 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container, obj)
287 3e6f33ca Stavros Sachtouris
        r = self.delete(path, success=(204, 404))
288 3e6f33ca Stavros Sachtouris
        if r.status_code == 404:
289 3e6f33ca Stavros Sachtouris
            raise ClientError("Object %s not found" % obj, r.status_code)
290 3e6f33ca Stavros Sachtouris
291 3f7e4e14 Stavros Sachtouris
    def list_objects(
292 3f7e4e14 Stavros Sachtouris
            self,
293 3f7e4e14 Stavros Sachtouris
            limit=None,
294 3f7e4e14 Stavros Sachtouris
            marker=None,
295 3f7e4e14 Stavros Sachtouris
            prefix=None,
296 3f7e4e14 Stavros Sachtouris
            format=None,
297 3f7e4e14 Stavros Sachtouris
            delimiter=None,
298 3f7e4e14 Stavros Sachtouris
            path=None):
299 3e6f33ca Stavros Sachtouris
        """
300 3f7e4e14 Stavros Sachtouris
        :param limit: (integer) The amount of results requested
301 3f7e4e14 Stavros Sachtouris

302 3f7e4e14 Stavros Sachtouris
        :param marker: (string) Return containers with name lexicographically
303 3f7e4e14 Stavros Sachtouris
            after marker
304 3f7e4e14 Stavros Sachtouris

305 3f7e4e14 Stavros Sachtouris
        :param prefix: (string) Return objects starting with prefix
306 3f7e4e14 Stavros Sachtouris

307 3f7e4e14 Stavros Sachtouris
        :param format: (string) reply format can be json or xml (default:json)
308 3f7e4e14 Stavros Sachtouris

309 3f7e4e14 Stavros Sachtouris
        :param delimiter: (string) Return objects up to the delimiter
310 3f7e4e14 Stavros Sachtouris

311 3f7e4e14 Stavros Sachtouris
        :param path: (string) assume prefix = path and delimiter = /
312 3f7e4e14 Stavros Sachtouris
            (overwrites prefix and delimiter)
313 3f7e4e14 Stavros Sachtouris

314 3e6f33ca Stavros Sachtouris
        :returns: (dict)
315 3e6f33ca Stavros Sachtouris

316 3e6f33ca Stavros Sachtouris
        :raises ClientError: 404 Invalid account
317 3e6f33ca Stavros Sachtouris
        """
318 3e6f33ca Stavros Sachtouris
        self._assert_container()
319 3f7e4e14 Stavros Sachtouris
        restpath = path4url(self.account, self.container)
320 3f7e4e14 Stavros Sachtouris
321 3f7e4e14 Stavros Sachtouris
        self.set_param('format', format or 'json')
322 3f7e4e14 Stavros Sachtouris
323 3f7e4e14 Stavros Sachtouris
        self.set_param('limit', limit, iff=limit)
324 3f7e4e14 Stavros Sachtouris
        self.set_param('marker', marker, iff=marker)
325 3f7e4e14 Stavros Sachtouris
        if path:
326 3f7e4e14 Stavros Sachtouris
            self.set_param('path', path)
327 3f7e4e14 Stavros Sachtouris
        else:
328 3f7e4e14 Stavros Sachtouris
            self.set_param('prefix', prefix, iff=prefix)
329 3f7e4e14 Stavros Sachtouris
            self.set_param('delimiter', delimiter, iff=delimiter)
330 3f7e4e14 Stavros Sachtouris
331 3f7e4e14 Stavros Sachtouris
        r = self.get(restpath, success=(200, 204, 304, 404), )
332 3e6f33ca Stavros Sachtouris
        if r.status_code == 404:
333 3e6f33ca Stavros Sachtouris
            raise ClientError(
334 3e6f33ca Stavros Sachtouris
                "Invalid account (%s) for that container" % self.account,
335 3e6f33ca Stavros Sachtouris
                r.status_code)
336 3e6f33ca Stavros Sachtouris
        elif r.status_code == 304:
337 3e6f33ca Stavros Sachtouris
            return []
338 3e6f33ca Stavros Sachtouris
        return r.json
339 3e6f33ca Stavros Sachtouris
340 3e6f33ca Stavros Sachtouris
    def list_objects_in_path(self, path_prefix):
341 3e6f33ca Stavros Sachtouris
        """
342 3e6f33ca Stavros Sachtouris
        :param path_prefix: (str)
343 3e6f33ca Stavros Sachtouris

344 3e6f33ca Stavros Sachtouris
        :raises ClientError: 404 Invalid account
345 3e6f33ca Stavros Sachtouris

346 3e6f33ca Stavros Sachtouris
        :returns: (dict)
347 3e6f33ca Stavros Sachtouris
        """
348 3e6f33ca Stavros Sachtouris
        self._assert_container()
349 3e6f33ca Stavros Sachtouris
        path = path4url(self.account, self.container)
350 3e6f33ca Stavros Sachtouris
        self.set_param('format', 'json')
351 3e6f33ca Stavros Sachtouris
        self.set_param('path', path_prefix)
352 3e6f33ca Stavros Sachtouris
        r = self.get(path, success=(200, 204, 404))
353 3e6f33ca Stavros Sachtouris
        if r.status_code == 404:
354 3e6f33ca Stavros Sachtouris
            raise ClientError(
355 3e6f33ca Stavros Sachtouris
                "Invalid account (%s) for that container" % self.account,
356 3e6f33ca Stavros Sachtouris
                r.status_code)
357 3e6f33ca Stavros Sachtouris
        reply = r.json
358 3e6f33ca Stavros Sachtouris
        return reply