Пример #1
0
    def test_create_mashup_dict_with_same_core_custom_properties(self):
        image_meta = {
            'id': 'test-123',
            'name': 'fake_image',
            'status': 'active',
            'created_at': '',
            'min_disk': '10G',
            'min_ram': '1024M',
            'protected': False,
            'locations': '',
            'checksum': 'c1234',
            'owner': '',
            'disk_format': 'raw',
            'container_format': 'bare',
            'size': '123456789',
            'virtual_size': '123456789',
            'is_public': 'public',
            'deleted': True,
            'updated_at': '',
            'properties': {'min_ram': '2048M'},
        }

        mashup_dict = utils.create_mashup_dict(image_meta)
        self.assertFalse('properties' in mashup_dict)
        self.assertNotEqual(image_meta['properties']['min_ram'],
                            mashup_dict['min_ram'])
        self.assertEqual(image_meta['min_ram'], mashup_dict['min_ram'])
Пример #2
0
    def show(self, req, id):
        """
        Returns an iterator that can be used to retrieve an image's
        data along with the image metadata.

        :param req: The WSGI/Webob Request object
        :param id: The opaque image identifier

        :raises HTTPNotFound if image is not available to user
        """

        self._enforce(req, "get_image")

        try:
            image_meta = self.get_active_image_meta_or_404(req, id)
        except HTTPNotFound:
            # provision for backward-compatibility breaking issue
            # catch the 404 exception and raise it after enforcing
            # the policy
            with excutils.save_and_reraise_exception():
                self._enforce(req, "download_image")
        else:
            target = utils.create_mashup_dict(image_meta)
            self._enforce(req, "download_image", target=target)

        self._enforce_read_protected_props(image_meta, req)

        if image_meta.get("size") == 0:
            image_iterator = iter([])
        else:
            image_iterator, size = self._get_from_store(req.context, image_meta["location"])
            image_iterator = utils.cooperative_iter(image_iterator)
            image_meta["size"] = size or image_meta["size"]
        image_meta = redact_loc(image_meta)
        return {"image_iterator": image_iterator, "image_meta": image_meta}
Пример #3
0
 def _get_v1_image_metadata(self, request, image_id):
     """
     Retrieves image metadata using registry for v1 api and creates
     dictionary-like mash-up of image core and custom properties.
     """
     try:
         image_metadata = registry.get_image_metadata(request.context, image_id)
         return utils.create_mashup_dict(image_metadata)
     except exception.NotFound as e:
         LOG.debug("No metadata found for image '%s'" % image_id)
         raise webob.exc.HTTPNotFound(explanation=e.msg, request=request)
Пример #4
0
 def _get_v1_image_metadata(self, request, image_id):
     """
     Retrieves image metadata using registry for v1 api and creates
     dictionary-like mash-up of image core and custom properties.
     """
     try:
         image_metadata = registry.get_image_metadata(
             request.context, image_id)
         return utils.create_mashup_dict(image_metadata)
     except exception.NotFound as e:
         LOG.debug("No metadata found for image '%s'", image_id)
         raise webob.exc.HTTPNotFound(explanation=e.msg, request=request)