'Fetch the image from image_service and write it to the volume.'

@utils.trace_method
def copy_image_to_volume(self, context, volume, image_service, image_id):

    LOG.debug('copy_image_to_volume    volume:    %(vol)s    image    service:    %(service)s    image    id:    %(id)s.', {'vol': volume, 'service': six.text_type(image_service), 'id': six.text_type(image_id)})
    path = util.get_image_path(image_id)
    try:
        if (not os.path.isfile(path)):
            image_utils.fetch_to_raw(context, image_service, image_id, path, BLOCK_SIZE, size=volume['size'])
        metadata = self._get_volume_metadata(volume)
        hs_img_id = self._get_volume_metadata_value(metadata, 'hs_image_id')
        util.update_image(path, volume['id'], hs_img_id)
    except (exception.UnableToExecuteHyperScaleCmd, exception.UnableToProcessHyperScaleCmdOutput):
        with excutils.save_and_reraise_exception():
            LOG.exception('Failed    to    copy_image_to_volume')
