Beispiel #1
0
    def _copy_image_to_volume(self, context, volume_ref, image_id,
                              image_location, image_service):
        """Downloads Glance image to the specified volume."""
        copy_image_to_volume = self.driver.copy_image_to_volume
        volume_id = volume_ref['id']
        LOG.debug(
            "Attempting download of %(image_id)s (%(image_location)s)"
            " to volume %(volume_id)s." % {
                'image_id':
                image_id,
                'volume_id':
                volume_id,
                'image_location':
                flow_utils.safe_print_image_location(image_location)
            })
        try:
            copy_image_to_volume(context, volume_ref, image_service, image_id)
        except processutils.ProcessExecutionError as ex:
            LOG.error(
                _("Failed to copy image %(image_id)s to volume: "
                  "%(volume_id)s, error: %(error)s") % {
                      'volume_id': volume_id,
                      'error': ex.stderr,
                      'image_id': image_id
                  })
            raise exception.ImageCopyFailure(reason=ex.stderr)
        except exception.ImageUnacceptable as ex:
            LOG.error(
                _("Failed to copy image to volume: %(volume_id)s, "
                  "error: %(error)s") % {
                      'volume_id': volume_id,
                      'error': ex
                  })
            raise exception.ImageUnacceptable(ex)
        except Exception as ex:
            LOG.error(
                _("Failed to copy image %(image_id)s to "
                  "volume: %(volume_id)s, error: %(error)s") % {
                      'volume_id': volume_id,
                      'error': ex,
                      'image_id': image_id
                  })
            if not isinstance(ex, exception.ImageCopyFailure):
                raise exception.ImageCopyFailure(reason=ex)
            else:
                raise

        LOG.debug(
            "Downloaded image %(image_id)s (%(image_location)s)"
            " to volume %(volume_id)s successfully." % {
                'image_id':
                image_id,
                'volume_id':
                volume_id,
                'image_location':
                flow_utils.safe_print_image_location(image_location)
            })
Beispiel #2
0
    def _create_from_image(self, context, volume_ref, image_location, image_id,
                           image_meta, image_service, **kwargs):
        LOG.debug(
            "Cloning %(volume_id)s from image %(image_id)s "
            " at location %(image_location)s." % {
                'volume_id':
                volume_ref['id'],
                'image_location':
                flow_utils.safe_print_image_location(image_location),
                'image_id':
                image_id
            })
        # Create the volume from an image.
        #
        # NOTE (singn): two params need to be returned
        # dict containing provider_location for cloned volume
        # and clone status.
        model_update, cloned = self.driver.clone_image(volume_ref,
                                                       image_location,
                                                       image_id, image_meta)
        if not cloned:
            # TODO(harlowja): what needs to be rolled back in the clone if this
            # volume create fails?? Likely this should be a subflow or broken
            # out task in the future. That will bring up the question of how
            # do we make said subflow/task which is only triggered in the
            # clone image 'path' resumable and revertable in the correct
            # manner.
            #
            # Create the volume and then download the image onto the volume.
            volume_ref['image_id'] = image_id
            model_update = self.driver.create_volume(volume_ref)
            updates = dict(model_update or dict(), status='downloading')
            try:
                volume_ref = self.db.volume_update(context, volume_ref['id'],
                                                   updates)
            except exception.CinderException:
                LOG.exception(
                    _("Failed updating volume %(volume_id)s with "
                      "%(updates)s") % {
                          'volume_id': volume_ref['id'],
                          'updates': updates
                      })
            self._copy_image_to_volume(context, volume_ref, image_id,
                                       image_location, image_service)

        self._handle_bootable_volume_glance_meta(context,
                                                 volume_ref['id'],
                                                 image_id=image_id,
                                                 image_meta=image_meta)
        return model_update
Beispiel #3
0
    def _copy_image_to_volume(self, context, volume_ref,
                              image_id, image_location, image_service):
        """Downloads Glance image to the specified volume."""
        copy_image_to_volume = self.driver.copy_image_to_volume
        volume_id = volume_ref['id']
        LOG.debug("Attempting download of %(image_id)s (%(image_location)s)"
                  " to volume %(volume_id)s." %
                  {'image_id': image_id, 'volume_id': volume_id,
                   'image_location': flow_utils.safe_print_image_location(image_location)})
        try:
            copy_image_to_volume(context, volume_ref, image_service, image_id)
        except processutils.ProcessExecutionError as ex:
            LOG.error(_("Failed to copy image %(image_id)s to volume: "
                        "%(volume_id)s, error: %(error)s") %
                      {'volume_id': volume_id,
                       'error': ex.stderr, 'image_id': image_id})
            raise exception.ImageCopyFailure(reason=ex.stderr)
        except exception.ImageUnacceptable as ex:
            LOG.error(_("Failed to copy image to volume: %(volume_id)s, "
                        "error: %(error)s") % {'volume_id': volume_id,
                                               'error': ex})
            raise exception.ImageUnacceptable(ex)
        except Exception as ex:
            LOG.error(_("Failed to copy image %(image_id)s to "
                        "volume: %(volume_id)s, error: %(error)s") %
                      {'volume_id': volume_id, 'error': ex,
                       'image_id': image_id})
            if not isinstance(ex, exception.ImageCopyFailure):
                raise exception.ImageCopyFailure(reason=ex)
            else:
                raise

        LOG.debug("Downloaded image %(image_id)s (%(image_location)s)"
                  " to volume %(volume_id)s successfully." %
                  {'image_id': image_id, 'volume_id': volume_id,
                   'image_location': flow_utils.safe_print_image_location(image_location)})
Beispiel #4
0
    def _create_from_image(self, context, volume_ref,
                           image_location, image_id, image_meta,
                           image_service, **kwargs):
        LOG.debug("Cloning %(volume_id)s from image %(image_id)s "
                  " at location %(image_location)s." %
                  {'volume_id': volume_ref['id'],
                   'image_location': flow_utils.safe_print_image_location(image_location),
                   'image_id': image_id})
        # Create the volume from an image.
        #
        # NOTE (singn): two params need to be returned
        # dict containing provider_location for cloned volume
        # and clone status.
        model_update, cloned = self.driver.clone_image(
            volume_ref, image_location, image_id, image_meta)
        if not cloned:
            # TODO(harlowja): what needs to be rolled back in the clone if this
            # volume create fails?? Likely this should be a subflow or broken
            # out task in the future. That will bring up the question of how
            # do we make said subflow/task which is only triggered in the
            # clone image 'path' resumable and revertable in the correct
            # manner.
            #
            # Create the volume and then download the image onto the volume.
            volume_ref['image_id'] = image_id
            model_update = self.driver.create_volume(volume_ref)
            updates = dict(model_update or dict(), status='downloading')
            try:
                volume_ref = self.db.volume_update(context,
                                                   volume_ref['id'], updates)
            except exception.CinderException:
                LOG.exception(_("Failed updating volume %(volume_id)s with "
                                "%(updates)s") %
                              {'volume_id': volume_ref['id'],
                               'updates': updates})
            self._copy_image_to_volume(context, volume_ref,
                                       image_id, image_location, image_service)

        self._handle_bootable_volume_glance_meta(context, volume_ref['id'],
                                                 image_id=image_id,
                                                 image_meta=image_meta)
        return model_update