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

def _copy_image_data_to_volume(self, context, volume, image_service, image_id, encrypted=False):

    LOG.debug('copy_image_to_volume    %s.', volume['name'])
    use_multipath = self.configuration.use_multipath_for_image_xfer
    enforce_multipath = self.configuration.enforce_multipath_for_image_xfer
    properties = utils.brick_get_connector_properties(use_multipath, enforce_multipath)
    (attach_info, volume) = self._attach_volume(context, volume, properties)
    try:
        if encrypted:
            encryption = self.db.volume_encryption_metadata_get(context, volume.id)
            utils.brick_attach_volume_encryptor(context, attach_info, encryption)
        try:
            image_utils.fetch_to_raw(context, image_service, image_id, attach_info['device']['path'], self.configuration.volume_dd_blocksize, size=volume['size'])
        except exception.ImageTooBig:
            with excutils.save_and_reraise_exception():
                LOG.exception('Copying    image    %(image_id)s    to    volume    failed    due    to    insufficient    available    space.', {'image_id': image_id})
        finally:
            if encrypted:
                utils.brick_detach_volume_encryptor(attach_info, encryption)
    finally:
        self._detach_volume(context, attach_info, volume, properties, force=True)
