Switch the actions over to using the new UI objects.

This commit is contained in:
Mitchell Hashimoto 2010-08-25 22:13:55 -07:00
parent e74bce8b10
commit 9ab5a7c2b1
31 changed files with 75 additions and 68 deletions

View File

@ -7,7 +7,7 @@ env = Vagrant::Environment.load!
begin
Vagrant::CLI.start(ARGV, :env => env)
rescue Vagrant::VagrantError => e
env.ui.error e.message
env.ui.error e.backtrace.join("\n") if ENV["VAGRANT_DEBUG"]
env.ui.error e.message, false
env.ui.error e.backtrace.join("\n"), false if ENV["VAGRANT_DEBUG"]
exit e.status_code
end

View File

@ -10,7 +10,7 @@ module Vagrant
end
def call(env)
env.logger.info "Deleting box directory..."
env.ui.info "Deleting box directory..."
FileUtils.rm_rf(env["box"].directory)
@app.call(env)

View File

@ -29,7 +29,7 @@ module Vagrant
def instantiate_downloader
@env["download.classes"].each do |klass|
if klass.match?(@env["box"].uri)
@env.logger.info "Downloading with #{klass}..."
@env.ui.info "Downloading with #{klass}..."
@downloader = klass.new(@env)
end
end
@ -52,13 +52,13 @@ module Vagrant
def recover(env)
if temp_path && File.exist?(temp_path)
env.logger.info "Cleaning up downloaded box..."
env.ui.info "Cleaning up downloaded box..."
File.unlink(temp_path)
end
end
def with_tempfile
@env.logger.info "Creating tempfile for storing box file..."
@env.ui.info "Creating tempfile for storing box file..."
File.open(box_temp_path, Platform.tar_file_options) do |tempfile|
yield tempfile
end
@ -69,7 +69,7 @@ module Vagrant
end
def download_to(f)
@env.logger.info "Copying box to temporary location..."
@env.ui.info "Copying box to temporary location..."
@downloader.download!(@env["box"].uri, f)
end
end

View File

@ -49,7 +49,7 @@ module Vagrant
def decompress
Dir.chdir(@env["box"].directory) do
@env.logger.info "Extracting box to #{@env["box"].directory}..."
@env.ui.info "Extracting box to #{@env["box"].directory}..."
Archive::Tar::Minitar.unpack(@env["download.temp_path"], @env["box"].directory)
end
end

View File

@ -9,7 +9,7 @@ module Vagrant
def call(env)
begin
env.logger.info "Verifying box..."
env.ui.info "Verifying box..."
VirtualBox::Appliance.new(env["box"].ovf_file)
rescue Exception
return env.error!(:box_verification_failed)

View File

@ -34,6 +34,11 @@ module Vagrant
env.logger
end
# Returns a UI object from the environment
def ui
env.ui
end
# Flags the environment as erroneous. Stores the given key
# and options until the end of the action sequence.
#

View File

@ -60,7 +60,7 @@ module Vagrant
FileUtils.mkdir_p(include_dir)
@env["package.include"].each do |f|
@env.logger.info "Packaging additional file: #{f}"
@env.ui.info "Packaging additional file: #{f}"
FileUtils.cp(f, include_dir)
end
end
@ -68,7 +68,7 @@ module Vagrant
# Compress the exported file into a package
def compress
@env.logger.info "Compressing package to #{tar_path}..."
@env.ui.info "Compressing package to #{tar_path}..."
File.open(tar_path, Platform.tar_file_options) do |tar|
Archive::Tar::Minitar::Output.open(tar) do |output|
begin

View File

@ -22,18 +22,18 @@ module Vagrant
end
def boot
@env.logger.info "Booting VM..."
@env.ui.info "Booting VM..."
@env["vm"].vm.start(@env.env.config.vm.boot_mode)
end
def wait_for_boot
@env.logger.info "Waiting for VM to boot..."
@env.ui.info "Waiting for VM to boot..."
@env.env.config.ssh.max_tries.to_i.times do |i|
@env.logger.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..."
@env.ui.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..."
if @env["vm"].ssh.up?
@env.logger.info "VM booted and ready for use!"
@env.ui.info "VM booted and ready for use!"
return true
end
@ -44,7 +44,7 @@ module Vagrant
sleep 5 if !@env["vagrant.test"]
end
@env.logger.info "Failed to connect to VM! Failed to boot?"
@env.ui.error "Failed to connect to VM! Failed to boot?"
false
end
end

View File

@ -14,7 +14,7 @@ module Vagrant
box_url = env["config"].vm.box_url
return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url
env.logger.info "Box #{box_name} not found. Fetching box since URL specified..."
env.ui.info "Box #{box_name} not found. Fetching box since URL specified..."
Vagrant::Box.add(env.env, box_name, box_url)
env.env.load_box!
end

View File

@ -16,9 +16,9 @@ module Vagrant
# doesn't support guest properties (due to cross platform issues)
version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
if version.empty?
env.logger.error Translator.t(:vm_additions_not_detected)
env.ui.warn Translator.t(:vm_additions_not_detected)
elsif version != VirtualBox.version
env.logger.error Translator.t(:vm_additions_version_mismatch,
env.ui.warn Translator.t(:vm_additions_version_mismatch,
:guest_additions_version => version,
:virtualbox_version => VirtualBox.version)
end

View File

@ -19,7 +19,7 @@ module Vagrant
def clear
if used_ports.length > 0
@env.logger.info "Deleting any previously set forwarded ports..."
@env.ui.info "Deleting any previously set forwarded ports..."
clear_ports
@env["vm"].reload!
end

View File

@ -16,7 +16,7 @@ module Vagrant
def clear_shared_folders
if @env["vm"].vm.shared_folders.length > 0
@env.logger.info "Clearing previously set shared folders..."
@env.ui.info "Clearing previously set shared folders..."
folders = @env["vm"].vm.shared_folders.dup
folders.each do |shared_folder|

View File

@ -8,7 +8,7 @@ module Vagrant
def call(env)
if !env.env.config.vm.proc_stack.empty?
env.logger.info "Running any VM customizations..."
env.ui.info "Running any VM customizations..."
env.env.config.vm.run_procs!(env["vm"].vm)
env["vm"].vm.save
end

View File

@ -7,7 +7,7 @@ module Vagrant
end
def call(env)
env.logger.info "Destroying VM and associated drives..."
env.ui.info "Destroying VM and associated drives..."
env["vm"].vm.destroy(:destroy_medium => :delete)
env["vm"].vm = nil
env.env.update_dotfile

View File

@ -21,7 +21,7 @@ module Vagrant
# Destroy the network interface if there is only one
# attached VM (which must be this VM)
if interface.attached_vms.length == 1
env.logger.info "Destroying unused network interface..."
env.ui.info "Destroying unused network interface..."
interface.destroy
end
end

View File

@ -16,7 +16,7 @@ module Vagrant
next if adapter.attachment_type != :host_only
if !logged
env.logger.info "Disabling host only networks..."
env.ui.info "Disabling host only networks..."
logged = true
end

View File

@ -10,7 +10,7 @@ module Vagrant
def call(env)
if env["vm"].vm.saved?
env.logger.info "Discarding saved state of VM..."
env.ui.info "Discarding saved state of VM..."
env["vm"].vm.discard_state
end

View File

@ -31,13 +31,13 @@ module Vagrant
end
def setup_temp_dir
@env.logger.info "Creating temporary directory for export..."
@env.ui.info "Creating temporary directory for export..."
@temp_dir = @env["export.temp_dir"] = File.join(@env.env.tmp_path, Time.now.to_i.to_s)
FileUtils.mkpath(@env["export.temp_dir"])
end
def export
@env.logger.info "Exporting VM to #{ovf_path}..."
@env.ui.info "Exporting VM to #{ovf_path}..."
@env["vm"].vm.export(ovf_path) do |progress|
@env.logger.report_progress(progress.percent, 100, false)
end

View File

@ -67,7 +67,7 @@ module Vagrant
existing_ports << options[:hostport]
# Notify the user
@env.logger.info "Fixed port collision: #{name} now on port #{options[:hostport]}"
@env.ui.info "Fixed port collision: #{name} now on port #{options[:hostport]}"
end
#--------------------------------------------------------------
@ -82,7 +82,7 @@ module Vagrant
end
def forward_ports
@env.logger.info "Forwarding ports..."
@env.ui.info "Forwarding ports..."
@env.env.config.vm.forwarded_ports.each do |name, options|
adapter = options[:adapter]
@ -91,11 +91,11 @@ module Vagrant
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
# attachment types has uncertain behaviour.
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
@env.logger.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}"
@env.ui.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}"
forward_port(name, options)
else
@env.logger.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"."
@env.logger.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}"
@env.ui.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"."
@env.ui.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}"
end
end

View File

@ -17,7 +17,7 @@ module Vagrant
end
if env["vm"].vm.state(true) != :powered_off
env.logger.info "Forcing shutdown of VM..."
env.ui.info "Forcing shutdown of VM..."
env["vm"].vm.stop
end

View File

@ -7,7 +7,7 @@ module Vagrant
end
def call(env)
env.logger.info "Importing base VM (#{env.env.box.ovf_file})"
env.ui.info "Importing base VM (#{env.env.box.ovf_file})"
begin
# Import the virtual machine

View File

@ -7,7 +7,7 @@ module Vagrant
end
def call(env)
env.logger.info "Matching MAC addresses..."
env.ui.info "Matching MAC addresses..."
env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac
env["vm"].vm.save

View File

@ -26,7 +26,7 @@ module Vagrant
if !env.error? && enable_network?
catch_action_exception(env) do
@env.logger.info "Enabling host only network..."
@env.ui.info "Enabling host only network..."
@env["vm"].system.prepare_host_only_network
@env.env.config.vm.network_options.compact.each do |network_options|
@env["vm"].system.enable_host_only_network(network_options)
@ -61,7 +61,7 @@ module Vagrant
# Enables and assigns the host only network to the proper
# adapter on the VM, and saves the adapter.
def assign_network
@env.logger.info "Preparing host only network..."
@env.ui.info "Preparing host only network..."
@env.env.config.vm.network_options.compact.each do |network_options|
adapter = @env["vm"].vm.network_adapters[network_options[:adapter]]
@ -93,7 +93,7 @@ module Vagrant
return @env.error!(:network_not_found, :name => net_options[:name]) if net_options[:name]
# One doesn't exist, create it.
@env.logger.info "Creating new host only network for environment..."
@env.ui.info "Creating new host only network for environment..."
ni = interfaces.create
ni.enable_static(network_ip(net_options[:ip], net_options[:netmask]),

View File

@ -104,7 +104,7 @@ module Vagrant
# involves adding a line to `/etc/exports` for this VM, but it is
# up to the host class to define the specific behavior.
def export_folders
@env.logger.info "Exporting NFS shared folders..."
@env.ui.info "Exporting NFS shared folders..."
catch_action_exception(@env) do
@env["host"].nfs_export(guest_ip, folders)
@ -113,7 +113,7 @@ module Vagrant
# Uses the system class to mount the NFS folders.
def mount_folders
@env.logger.info "Mounting NFS shared folders..."
@env.ui.info "Mounting NFS shared folders..."
catch_action_exception(@env) do
@env["vm"].system.mount_nfs(host_ip, folders)

View File

@ -11,7 +11,7 @@ module Vagrant
end
def call(env)
env.logger.info "Persisting the VM UUID (#{env["vm"].uuid})"
env.ui.info "Persisting the VM UUID (#{env["vm"].uuid})"
env.env.update_dotfile
@app.call(env)

View File

@ -13,7 +13,7 @@ module Vagrant
@app.call(env)
if !env.error? && provisioning_enabled?
@env.logger.info "Beginning provisioning process..."
@env.ui.info "Beginning provisioning process..."
@provisioner.provision!
end
end
@ -40,7 +40,7 @@ module Vagrant
@provisioner = provisioner_klass.new(@env)
end
@env.logger.info "Provisioning enabled with #{@provisioner.class}"
@env.ui.info "Provisioning enabled with #{@provisioner.class}"
@provisioner.prepare
@provisioner
end

View File

@ -8,7 +8,7 @@ module Vagrant
def call(env)
if env["vm"].vm.saved?
env.logger.info "Resuming suspended VM..."
env.ui.info "Resuming suspended VM..."
env["actions"].run(Boot)
end

View File

@ -60,7 +60,7 @@ module Vagrant
end
def create_metadata
@env.logger.info "Creating shared folders metadata..."
@env.ui.info "Creating shared folders metadata..."
shared_folders.each do |name, data|
folder = VirtualBox::SharedFolder.new
@ -73,11 +73,11 @@ module Vagrant
end
def mount_shared_folders
@env.logger.info "Mounting shared folders..."
@env.ui.info "Mounting shared folders..."
@env["vm"].ssh.execute do |ssh|
shared_folders.each do |name, data|
@env.logger.info "-- #{name}: #{data[:guestpath]}"
@env.ui.info "-- #{name}: #{data[:guestpath]}"
@env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath])
end
end
@ -89,7 +89,7 @@ module Vagrant
@env["vm"].ssh.execute do |ssh|
@env["vm"].system.prepare_unison(ssh)
@env.logger.info "Creating unison crontab entries..."
@env.ui.info "Creating unison crontab entries..."
unison_folders.each do |name, data|
@env["vm"].system.create_unison(ssh, data)
end

View File

@ -8,7 +8,7 @@ module Vagrant
def call(env)
if env["vm"].vm.running?
env.logger.info "Saving VM state and suspending execution..."
env.ui.info "Saving VM state and suspending execution..."
env["vm"].vm.save_state
end

View File

@ -9,9 +9,9 @@ module Vagrant
@env = env
end
[:warn, :error, :info, :confirm].each do |method|
[:warn, :error, :info, :confirm, :say_with_vm].each do |method|
# By default these methods don't do anything. A silent UI.
define_method(method) { |message| }
define_method(method) { |*args| }
end
# A shell UI, which uses a `Thor::Shell` object to talk with
@ -23,20 +23,18 @@ module Vagrant
@shell = shell
end
def warn(message)
@shell.say(message, :yellow)
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
define_method(method) do |message, prepend_vm_name=true|
message = format_message(message) if prepend_vm_name
@shell.say(message, color)
end
end
def error(message)
@shell.say(message, :red)
end
protected
def info(message)
@shell.say(message)
end
def confirm(message)
@shell.say(message, :green)
def format_message(message)
name = env.vm_name || "vagrant"
"[#{name}] #{message}"
end
end
end

View File

@ -15,6 +15,10 @@ class ActionEnvironmentTest < Test::Unit::TestCase
assert_equal @instance.env.logger, @instance.logger
end
should "setup the UI" do
assert_equal @instance.env.ui, @instance.ui
end
should "not be erroneous initially" do
assert !@instance.error?
end