~ubuntu-branches/ubuntu/raring/glance/raring-proposed

« back to all changes in this revision

Viewing changes to glance/api/v1/images.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-03-20 07:42:22 UTC
  • mfrom: (1.1.50)
  • Revision ID: package-import@ubuntu.com-20130320074222-d8oochgvhjooh1a5
Tags: 1:2013.1~rc1-0ubuntu1
[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org.

[ Chuck Short ]
* New upstrem release
* debian/control: Clean up build-dependencies:
  - Drop python-argparse referenced in pydist-overrides
  - Drop python-swift no longer needed.
  - Drop python-dateutils no longer needed.
  - Drop python-glacneclient no longer needed.
  - Added python-anyjson to build-depends.
  - Use python-keystoneclient instead of python-keystone.
  - Added python-lxml to build-depends.
  - Added python-swiftclientto build-depends.
  - Added python-passlib to build-depends.
* debian/rules: Set the PYTHONPATH for the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
/images endpoint for Glance v1 API
20
20
"""
21
21
 
22
 
import traceback
 
22
import copy
23
23
 
24
24
import eventlet
25
25
from oslo.config import cfg
97
97
    return values
98
98
 
99
99
 
 
100
def redact_loc(image_meta):
 
101
    """
 
102
    Create a shallow copy of image meta with 'location' removed
 
103
    for security (as it can contain credentials).
 
104
    """
 
105
    if 'location' in image_meta:
 
106
        tmp_image_meta = copy.copy(image_meta)
 
107
        del tmp_image_meta['location']
 
108
        return tmp_image_meta
 
109
 
 
110
    return image_meta
 
111
 
 
112
 
100
113
class Controller(controller.BaseController):
101
114
    """
102
115
    WSGI controller for images resource in Glance v1 API
212
225
        for PARAM in SUPPORTED_PARAMS:
213
226
            if PARAM in req.params:
214
227
                params[PARAM] = req.params.get(PARAM)
 
228
 
 
229
        # Fix for LP Bug #1132294
 
230
        # Ensure all shared images are returned in v1
 
231
        params['member_status'] = 'all'
215
232
        return params
216
233
 
217
234
    def _get_filters(self, req):
348
365
 
349
366
        try:
350
367
            image_meta = registry.add_image_metadata(req.context, image_meta)
351
 
            self.notifier.info("image.create", image_meta)
 
368
            self.notifier.info("image.create", redact_loc(image_meta))
352
369
            return image_meta
353
370
        except exception.Duplicate:
354
371
            msg = (_("An image with identifier %s already exists") %
420
437
                    "to %(scheme)s store"), locals())
421
438
 
422
439
        try:
423
 
            self.notifier.info("image.prepare", image_meta)
 
440
            self.notifier.info("image.prepare", redact_loc(image_meta))
424
441
            location, size, checksum = store.add(
425
442
                image_meta['id'],
426
443
                utils.CooperativeReader(image_data),
455
472
            image_meta = registry.update_image_metadata(req.context,
456
473
                                                        image_id,
457
474
                                                        update_data)
458
 
            self.notifier.info('image.upload', image_meta)
 
475
            self.notifier.info('image.upload', redact_loc(image_meta))
459
476
 
460
477
            return location
461
478
 
490
507
                                         content_type='text/plain')
491
508
 
492
509
        except exception.ImageSizeLimitExceeded, e:
493
 
            msg = _("Denying attempt to upload image larger than %d bytes.")
 
510
            msg = _("Denying attempt to upload image larger than %d bytes."
 
511
                    % CONF.image_size_cap)
 
512
            LOG.info(msg)
494
513
            self._safe_kill(req, image_id)
495
 
            raise HTTPBadRequest(explanation=msg % CONF.image_size_cap,
496
 
                                 request=req, content_type='text/plain')
 
514
            raise HTTPBadRequest(explanation=msg, request=req,
 
515
                                 content_type='text/plain')
497
516
 
498
517
        except HTTPError, e:
499
518
            self._safe_kill(req, image_id)
525
544
            image_meta_data = registry.update_image_metadata(req.context,
526
545
                                                             image_id,
527
546
                                                             image_meta)
528
 
            self.notifier.info("image.activate", image_meta_data)
529
 
            self.notifier.info("image.update", image_meta_data)
 
547
            self.notifier.info("image.activate", redact_loc(image_meta_data))
 
548
            self.notifier.info("image.update", redact_loc(image_meta_data))
530
549
            return image_meta_data
531
550
        except exception.Invalid, e:
532
551
            msg = (_("Failed to activate image. Got error: %(e)s")
778
797
                                request=req,
779
798
                                content_type="text/plain")
780
799
        else:
781
 
            self.notifier.info('image.update', image_meta)
 
800
            self.notifier.info('image.update', redact_loc(image_meta))
782
801
 
783
802
        # Prevent client from learning the location, as it
784
803
        # could contain security credentials
855
874
                                request=req,
856
875
                                content_type="text/plain")
857
876
        else:
858
 
            self.notifier.info('image.delete', image)
 
877
            self.notifier.info('image.delete', redact_loc(image))
859
878
            return Response(body='', status=200)
860
879
 
861
880
    def get_store_or_400(self, request, scheme):