Revision 23808592 snf-cyclades-app/synnefo/plankton/views.py

b/snf-cyclades-app/synnefo/plankton/views.py
43 43
from snf_django.lib import api
44 44
from snf_django.lib.api import faults
45 45
from synnefo.util.text import uenc
46
from synnefo.plankton.utils import image_backend
47
from synnefo.plankton.backend import split_url, InvalidLocation
46
from synnefo.plankton.backend import PlanktonBackend
47
from synnefo.plankton.backend import split_url
48 48

  
49 49

  
50 50
FILTERS = ('name', 'container_format', 'disk_format', 'status', 'size_min',
......
109 109
    for key, val in request.META.items():
110 110
        if key.startswith(META_PROPERTY_PREFIX):
111 111
            name = normalize(key[META_PROPERTY_PREFIX_LEN:])
112
            headers['properties'][unquote(name)] = unquote(val)
112
            headers['properties'][unquote(name)] = unquote(uenc(val))
113 113
        elif key.startswith(META_PREFIX):
114 114
            name = normalize(key[META_PREFIX_LEN:])
115
            headers[unquote(name)] = unquote(val)
115
            headers[unquote(name)] = unquote(uenc(val))
116 116

  
117 117
    is_public = headers.get('is_public', None)
118 118
    if is_public is not None:
......
149 149
    if not set(params.keys()).issubset(set(ADD_FIELDS)):
150 150
        raise faults.BadRequest("Invalid parameters")
151 151

  
152
    name = params.pop('name')
152
    name = params.pop('name', None)
153 153
    if name is None:
154 154
        raise faults.BadRequest("Image 'name' parameter is required")
155 155
    elif len(uenc(name)) == 0:
......
160 160

  
161 161
    try:
162 162
        split_url(location)
163
    except InvalidLocation:
163
    except AssertionError:
164 164
        raise faults.BadRequest("Invalid location '%s'" % location)
165 165

  
166 166
    validate_fields(params)
167 167

  
168 168
    if location:
169
        with image_backend(request.user_uniq) as backend:
169
        with PlanktonBackend(request.user_uniq) as backend:
170 170
            image = backend.register(name, location, params)
171 171
    else:
172 172
        #f = StringIO(request.body)
......
193 193
    """
194 194
    log.info("delete_image '%s'" % image_id)
195 195
    userid = request.user_uniq
196
    with image_backend(userid) as backend:
196
    with PlanktonBackend(userid) as backend:
197 197
        backend.unregister(image_id)
198 198
    log.info("User '%s' deleted image '%s'" % (userid, image_id))
199 199
    return HttpResponse(status=204)
......
211 211
    """
212 212

  
213 213
    log.debug('add_image_member %s %s', image_id, member)
214
    with image_backend(request.user_uniq) as backend:
214
    with PlanktonBackend(request.user_uniq) as backend:
215 215
        backend.add_user(image_id, member)
216 216
    return HttpResponse(status=204)
217 217

  
......
250 250
    3.4. Requesting Detailed Metadata on a Specific Image
251 251
    """
252 252

  
253
    with image_backend(request.user_uniq) as backend:
253
    with PlanktonBackend(request.user_uniq) as backend:
254 254
        image = backend.get_image(image_id)
255 255
    return _create_image_response(image)
256 256

  
......
263 263
    3.7. Requesting Image Memberships
264 264
    """
265 265

  
266
    with image_backend(request.user_uniq) as backend:
266
    with PlanktonBackend(request.user_uniq) as backend:
267 267
        users = backend.list_users(image_id)
268 268

  
269 269
    members = [{'member_id': u, 'can_share': False} for u in users]
......
313 313
        except ValueError:
314 314
            raise faults.BadRequest("Malformed request.")
315 315

  
316
    with image_backend(request.user_uniq) as backend:
316
    with PlanktonBackend(request.user_uniq) as backend:
317 317
        images = backend.list_images(filters, params)
318 318

  
319 319
    # Remove keys that should not be returned
......
342 342
    log.debug('list_shared_images %s', member)
343 343

  
344 344
    images = []
345
    with image_backend(request.user_uniq) as backend:
345
    with PlanktonBackend(request.user_uniq) as backend:
346 346
        for image in backend.list_shared_images(member=member):
347
            image_id = image['id']
348
            images.append({'image_id': image_id, 'can_share': False})
347
            images.append({'image_id': image["id"], 'can_share': False})
349 348

  
350 349
    data = json.dumps({'shared_images': images}, indent=settings.DEBUG)
351 350
    return HttpResponse(data)
......
360 359
    """
361 360

  
362 361
    log.debug('remove_image_member %s %s', image_id, member)
363
    with image_backend(request.user_uniq) as backend:
362
    with PlanktonBackend(request.user_uniq) as backend:
364 363
        backend.remove_user(image_id, member)
365 364
    return HttpResponse(status=204)
366 365

  
......
386 385

  
387 386
    validate_fields(meta)
388 387

  
389
    with image_backend(request.user_uniq) as backend:
388
    with PlanktonBackend(request.user_uniq) as backend:
390 389
        image = backend.update_metadata(image_id, meta)
391 390
    return _create_image_response(image)
392 391

  
......
411 410
    except (ValueError, KeyError, TypeError):
412 411
        return HttpResponse(status=400)
413 412

  
414
    with image_backend(request.user_uniq) as backend:
413
    with PlanktonBackend(request.user_uniq) as backend:
415 414
        backend.replace_users(image_id, members)
416 415
    return HttpResponse(status=204)
417 416

  

Also available in: Unified diff