Esempio n. 1
0
    def _get_marker(self, req):
        """Parse a marker query param into something usable."""
        marker = req.str_params.get('marker', None)

        if marker and not utils.is_uuid_like(marker):
            msg = _('Invalid marker format')
            raise exc.HTTPBadRequest(explanation=msg)

        return marker
Esempio n. 2
0
    def create(self, req, body):
        """
        Registers a new image with the registry.

        :param req: wsgi Request object
        :param body: Dictionary of information about the image

        :retval Returns the newly-created image information as a mapping,
                which will include the newly-created image's internal id
                in the 'id' field
        """
        if req.context.read_only:
            raise exc.HTTPForbidden()

        image_data = body['image']

        # Ensure the image has a status set
        image_data.setdefault('status', 'active')

        # Set up the image owner
        if not req.context.is_admin or 'owner' not in image_data:
            image_data['owner'] = req.context.owner

        image_id = image_data.get('id')
        if image_id and not utils.is_uuid_like(image_id):
            msg = _("Invalid image id format")
            return exc.HTTPBadRequest(explanation=msg)

        try:
            image_data = db_api.image_create(req.context, image_data)
            return dict(image=make_image_dict(image_data))
        except exception.Duplicate:
            msg = (_("Image with identifier %s already exists!") % id)
            logger.error(msg)
            return exc.HTTPConflict(msg)
        except exception.Invalid, e:
            msg = (_("Failed to add image metadata. "
                     "Got error: %(e)s") % locals())
            logger.error(msg)
            return exc.HTTPBadRequest(msg)
Esempio n. 3
0
 def test_is_uuid_like_fails(self):
     fixture = 'pants'
     self.assertFalse(utils.is_uuid_like(fixture))
Esempio n. 4
0
 def test_is_uuid_like_success(self):
     fixture = 'b694bf02-6b01-4905-a50e-fcf7bce7e4d2'
     self.assertTrue(utils.is_uuid_like(fixture))