def upload_image(image_file, pool_name, volume_name, env)
image_size = File.size(image_file)
begin
pool = env[:machine].provider.driver.connection.client.lookup_storage_pool_by_name(
pool_name
)
volume = pool.lookup_volume_by_name(volume_name)
stream = env[:machine].provider.driver.connection.client.stream
volume.upload(stream, offset = 0, length = image_size)
buf_size = 1024 * 250
progress = 0
open(image_file, 'rb') do |io|
while (buff = io.read(buf_size))
sent = stream.send buff
progress += sent
yield progress
end
end
rescue => e
raise Errors::ImageUploadError,
error_message: e.message
end
progress == image_size
end