예제 #1
0
    def _show(self, image_href, method='get'):
        """Returns a dict with image data for the given opaque image id.

        :param image_href: The opaque image identifier.
        :returns: A dict containing image metadata.

        :raises: ImageNotFound
        :raises: ImageUnacceptable if the image status is not active
        """
        LOG.debug("Getting image metadata from glance. Image: %s",
                  image_href)
        image_id = service_utils.parse_image_id(image_href)

        image = self.call(method, image_id)

        if not service_utils.is_image_active(image):
            raise exception.ImageUnacceptable(
                image_id=image_id,
                reason=_("The image is required to be in an active state."))

        if not service_utils.is_image_available(self.context, image):
            raise exception.ImageNotFound(image_id=image_id)

        base_image_meta = service_utils.translate_from_glance(image)
        return base_image_meta
예제 #2
0
def _translate_image_exception(image_id, exc_value):
    if isinstance(exc_value, (glance_exc.Forbidden, glance_exc.Unauthorized)):
        return exception.ImageNotAuthorized(image_id=image_id)
    if isinstance(exc_value, glance_exc.NotFound):
        return exception.ImageNotFound(image_id=image_id)
    if isinstance(exc_value, glance_exc.BadRequest):
        return exception.Invalid(exc_value)
    return exc_value
예제 #3
0
 def test_validate_image_properties_glance_image_not_found(self,
         image_service_mock):
     d_info = {'image_source': 'uuid'}
     show_mock = image_service_mock.return_value.show
     show_mock.side_effect = exception.ImageNotFound(image_id='uuid')
     self.assertRaises(exception.InvalidParameterValue,
                       iscsi_deploy.validate_image_properties, self.context,
                       d_info, [])
예제 #4
0
    def _get_location(self, image_id):
        """Returns the direct url representing the backend storage location,
        or None if this attribute is not shown by Glance.
        """
        image_meta = self.call('get', image_id)

        if not service_utils.is_image_available(self.context, image_meta):
            raise exc.ImageNotFound(image_id=image_id)

        return getattr(image_meta, 'direct_url', None)
예제 #5
0
    def _show(self, image_href, method='get'):
        """Returns a dict with image data for the given opaque image id.

        :param image_id: The opaque image identifier.
        :returns: A dict containing image metadata.

        :raises: ImageNotFound
        """
        LOG.debug("Getting image metadata from glance. Image: %s" % image_href)
        (image_id, self.glance_host, self.glance_port,
         use_ssl) = service_utils.parse_image_ref(image_href)

        image = self.call(method, image_id)

        if not service_utils.is_image_available(self.context, image):
            raise exception.ImageNotFound(image_id=image_id)

        base_image_meta = service_utils.translate_from_glance(image)
        return base_image_meta
예제 #6
0
 def test_validate_fail_glance_image_doesnt_exists(self, mock_glance):
     mock_glance.side_effect = exception.ImageNotFound('not found')
     with task_manager.acquire(self.context, self.node.uuid,
                               shared=True) as task:
         self.assertRaises(exception.InvalidParameterValue,
                           task.driver.deploy.validate, task)
예제 #7
0
 def get(self, image_id):
     for image in self._images:
         if image.id == str(image_id):
             return image
     raise exception.ImageNotFound(image_id)