mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Support the newly-introduced --no-tty Vagrant's option (#1120)
hashicorp/vagrant#11465 introduced a new option --no-tty which silences progress bars so they don't spam logs when Vagrant is used non-interactively. First Vagrant version with this change is v2.2.8. However, existing code needs to be slightly updated to cooperate with the new option correctly, otherwise the progress bars spam the logs with empty lines/warnings instead of remaining silent. Fixes: #1106
This commit is contained in:
parent
027910d236
commit
308ead403e
@ -5,6 +5,7 @@ module VagrantPlugins
|
||||
module Action
|
||||
class HandleBoxImage
|
||||
include VagrantPlugins::ProviderLibvirt::Util::StorageUtil
|
||||
include VagrantPlugins::ProviderLibvirt::Util::Ui
|
||||
|
||||
|
||||
@@lock = Mutex.new
|
||||
@ -102,13 +103,15 @@ module VagrantPlugins
|
||||
# Upload box image to storage pool
|
||||
ret = upload_image(box_image_file, config.storage_pool_name,
|
||||
env[:box_volume_name], env) do |progress|
|
||||
env[:ui].clear_line
|
||||
env[:ui].report_progress(progress, box_image_size, false)
|
||||
rewriting(env[:ui]) do |ui|
|
||||
ui.clear_line
|
||||
ui.report_progress(progress, box_image_size, false)
|
||||
end
|
||||
end
|
||||
|
||||
# Clear the line one last time since the progress meter doesn't
|
||||
# disappear immediately.
|
||||
env[:ui].clear_line
|
||||
rewriting(env[:ui]) {|ui| ui.clear_line}
|
||||
|
||||
# If upload failed or was interrupted, remove created volume from
|
||||
# storage pool.
|
||||
|
@ -6,6 +6,9 @@ module VagrantPlugins
|
||||
module Action
|
||||
# Action for create new box for Libvirt provider
|
||||
class PackageDomain
|
||||
include VagrantPlugins::ProviderLibvirt::Util::Ui
|
||||
|
||||
|
||||
def initialize(app, env)
|
||||
@logger = Log4r::Logger.new('vagrant_libvirt::action::package_domain')
|
||||
@app = app
|
||||
@ -31,12 +34,14 @@ module VagrantPlugins
|
||||
env[:ui].info("Downloading #{root_disk.name} to #{@tmp_img}")
|
||||
ret = download_image(@tmp_img, env[:machine].provider_config.storage_pool_name,
|
||||
root_disk.name, env) do |progress,image_size|
|
||||
env[:ui].clear_line
|
||||
env[:ui].report_progress(progress, image_size, false)
|
||||
rewriting(env[:ui]) do |ui|
|
||||
ui.clear_line
|
||||
ui.report_progress(progress, image_size, false)
|
||||
end
|
||||
end
|
||||
# Clear the line one last time since the progress meter doesn't
|
||||
# disappear immediately.
|
||||
env[:ui].clear_line
|
||||
rewriting(env[:ui]) {|ui| ui.clear_line}
|
||||
backing = `qemu-img info "#{@tmp_img}" | grep 'backing file:' | cut -d ':' -f2`.chomp
|
||||
if backing
|
||||
env[:ui].info('Image has backing image, copying image and rebasing ...')
|
||||
|
@ -7,6 +7,7 @@ module VagrantPlugins
|
||||
autoload :NetworkUtil, 'vagrant-libvirt/util/network_util'
|
||||
autoload :StorageUtil, 'vagrant-libvirt/util/storage_util'
|
||||
autoload :ErrorCodes, 'vagrant-libvirt/util/error_codes'
|
||||
autoload :Ui, 'vagrant-libvirt/util/ui'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
23
lib/vagrant-libvirt/util/ui.rb
Normal file
23
lib/vagrant-libvirt/util/ui.rb
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Util
|
||||
module Ui
|
||||
# Since v2.2.8 Vagrant support --no-tty option, which silences
|
||||
# progress bars and other interactive elements for cleaner logs
|
||||
# in scripts, but requires a slight change in UI object handling.
|
||||
# This helper allows the vagrant-libvirt plugin to stay compatible
|
||||
# with the older Vagrant versions.
|
||||
# See: https://github.com/hashicorp/vagrant/pull/11465/
|
||||
def rewriting(ui)
|
||||
if ui.respond_to?(:rewriting)
|
||||
ui.rewriting {|rw| yield rw}
|
||||
else
|
||||
yield ui
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user