From 1d29ba31fa2c9d8d08fbbb86a99499684eb725f4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 27 Aug 2010 19:26:33 -0700 Subject: [PATCH] I18nified all the VM actions --- bin/.gitignore | 0 lib/vagrant/action/vm/boot.rb | 10 +-- lib/vagrant/action/vm/check_box.rb | 2 +- .../action/vm/check_guest_additions.rb | 8 +- .../action/vm/clear_forwarded_ports.rb | 2 +- lib/vagrant/action/vm/clear_shared_folders.rb | 2 +- lib/vagrant/action/vm/customize.rb | 2 +- lib/vagrant/action/vm/destroy.rb | 2 +- .../vm/destroy_unused_network_interfaces.rb | 2 +- lib/vagrant/action/vm/disable_networks.rb | 2 +- lib/vagrant/action/vm/discard_state.rb | 2 +- lib/vagrant/action/vm/export.rb | 4 +- lib/vagrant/action/vm/forward_ports.rb | 17 ++-- lib/vagrant/action/vm/halt.rb | 2 +- lib/vagrant/action/vm/import.rb | 2 +- lib/vagrant/action/vm/match_mac_address.rb | 2 +- lib/vagrant/action/vm/network.rb | 6 +- lib/vagrant/action/vm/nfs.rb | 6 +- lib/vagrant/action/vm/persist.rb | 2 +- lib/vagrant/action/vm/provision.rb | 4 +- lib/vagrant/action/vm/resume.rb | 2 +- lib/vagrant/action/vm/share_folders.rb | 10 ++- lib/vagrant/action/vm/suspend.rb | 2 +- templates/locales/en.yml | 82 +++++++++++++++++++ templates/strings.yml | 20 ----- test/vagrant/action/vm/import_test.rb | 1 + 26 files changed, 133 insertions(+), 63 deletions(-) delete mode 100755 bin/.gitignore diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100755 index e69de29bb..000000000 diff --git a/lib/vagrant/action/vm/boot.rb b/lib/vagrant/action/vm/boot.rb index 657e2d736..ae71702dc 100644 --- a/lib/vagrant/action/vm/boot.rb +++ b/lib/vagrant/action/vm/boot.rb @@ -22,18 +22,16 @@ module Vagrant end def boot - @env.ui.info "Booting VM..." + @env.ui.info "vagrant.actions.vm.boot.booting" @env["vm"].vm.start(@env.env.config.vm.boot_mode) end def wait_for_boot - @env.ui.info "Waiting for VM to boot..." + @env.ui.info "vagrant.actions.vm.boot.waiting" @env.env.config.ssh.max_tries.to_i.times do |i| - @env.ui.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..." - if @env["vm"].ssh.up? - @env.ui.info "VM booted and ready for use!" + @env.ui.info "vagrant.actions.vm.boot.ready" return true end @@ -44,7 +42,7 @@ module Vagrant sleep 5 if !@env["vagrant.test"] end - @env.ui.error "Failed to connect to VM! Failed to boot?" + @env.ui.error "vagrant.actions.vm.boot.failed" false end end diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index cbf71d2b7..90526c6de 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -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.ui.info "Box #{box_name} not found. Fetching box since URL specified..." + env.ui.info "vagrant.actions.vm.check_box.not_found", :name => box_name Vagrant::Box.add(env.env, box_name, box_url) env.env.load_box! end diff --git a/lib/vagrant/action/vm/check_guest_additions.rb b/lib/vagrant/action/vm/check_guest_additions.rb index 118723580..a9f151e9b 100644 --- a/lib/vagrant/action/vm/check_guest_additions.rb +++ b/lib/vagrant/action/vm/check_guest_additions.rb @@ -16,11 +16,11 @@ 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.ui.warn Translator.t(:vm_additions_not_detected) + env.ui.warn "vagrant.actions.vm.check_guest_additions.not_detected" elsif version != VirtualBox.version - env.ui.warn Translator.t(:vm_additions_version_mismatch, - :guest_additions_version => version, - :virtualbox_version => VirtualBox.version) + env.ui.warn("vagrant.actions.vm.check_guest_additions.version_mismatch", + :guest_version => version, + :virtualbox_version => VirtualBox.version) end # Continue diff --git a/lib/vagrant/action/vm/clear_forwarded_ports.rb b/lib/vagrant/action/vm/clear_forwarded_ports.rb index 81c76bb80..6e16a00cf 100644 --- a/lib/vagrant/action/vm/clear_forwarded_ports.rb +++ b/lib/vagrant/action/vm/clear_forwarded_ports.rb @@ -19,7 +19,7 @@ module Vagrant def clear if used_ports.length > 0 - @env.ui.info "Deleting any previously set forwarded ports..." + @env.ui.info "vagrant.actions.vm.clear_forward_ports.deleting" clear_ports @env["vm"].reload! end diff --git a/lib/vagrant/action/vm/clear_shared_folders.rb b/lib/vagrant/action/vm/clear_shared_folders.rb index e429a93b4..f088ebdde 100644 --- a/lib/vagrant/action/vm/clear_shared_folders.rb +++ b/lib/vagrant/action/vm/clear_shared_folders.rb @@ -16,7 +16,7 @@ module Vagrant def clear_shared_folders if @env["vm"].vm.shared_folders.length > 0 - @env.ui.info "Clearing previously set shared folders..." + @env.ui.info "vagrant.actions.vm.clear_shared_folders.deleting" folders = @env["vm"].vm.shared_folders.dup folders.each do |shared_folder| diff --git a/lib/vagrant/action/vm/customize.rb b/lib/vagrant/action/vm/customize.rb index 442b0fe94..4cfd4d1f6 100644 --- a/lib/vagrant/action/vm/customize.rb +++ b/lib/vagrant/action/vm/customize.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if !env.env.config.vm.proc_stack.empty? - env.ui.info "Running any VM customizations..." + env.ui.info "vagrant.actions.vm.customize.running" env.env.config.vm.run_procs!(env["vm"].vm) env["vm"].vm.save end diff --git a/lib/vagrant/action/vm/destroy.rb b/lib/vagrant/action/vm/destroy.rb index 53b24f2eb..6d89fe268 100644 --- a/lib/vagrant/action/vm/destroy.rb +++ b/lib/vagrant/action/vm/destroy.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.ui.info "Destroying VM and associated drives..." + env.ui.info "vagrant.actions.vm.destroy.destroying" env["vm"].vm.destroy(:destroy_medium => :delete) env["vm"].vm = nil env.env.update_dotfile diff --git a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb index 3176a8fe6..4af66a947 100644 --- a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +++ b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb @@ -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.ui.info "Destroying unused network interface..." + env.ui.info "vagrant.actions.vm.destroy_network.destroying" interface.destroy end end diff --git a/lib/vagrant/action/vm/disable_networks.rb b/lib/vagrant/action/vm/disable_networks.rb index 6b5a3eb6f..2ba272e62 100644 --- a/lib/vagrant/action/vm/disable_networks.rb +++ b/lib/vagrant/action/vm/disable_networks.rb @@ -16,7 +16,7 @@ module Vagrant next if adapter.attachment_type != :host_only if !logged - env.ui.info "Disabling host only networks..." + env.ui.info "vagrant.actions.vm.disable_networks.disabling" logged = true end diff --git a/lib/vagrant/action/vm/discard_state.rb b/lib/vagrant/action/vm/discard_state.rb index 6350b2702..dee46a41d 100644 --- a/lib/vagrant/action/vm/discard_state.rb +++ b/lib/vagrant/action/vm/discard_state.rb @@ -10,7 +10,7 @@ module Vagrant def call(env) if env["vm"].vm.saved? - env.ui.info "Discarding saved state of VM..." + env.ui.info "vagrant.actions.vm.discard_state.discarding" env["vm"].vm.discard_state end diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index 741b31621..c1bd70080 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -31,13 +31,13 @@ module Vagrant end def setup_temp_dir - @env.ui.info "Creating temporary directory for export..." + @env.ui.info "vagrant.actions.vm.export.create_dir" @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.ui.info "Exporting VM to #{ovf_path}..." + @env.ui.info "vagrant.actions.vm.export.exporting" @env["vm"].vm.export(ovf_path) do |progress| @env.ui.report_progress(progress.percent, 100, false) end diff --git a/lib/vagrant/action/vm/forward_ports.rb b/lib/vagrant/action/vm/forward_ports.rb index 123ac9fc8..27dc8246e 100644 --- a/lib/vagrant/action/vm/forward_ports.rb +++ b/lib/vagrant/action/vm/forward_ports.rb @@ -67,7 +67,9 @@ module Vagrant existing_ports << options[:hostport] # Notify the user - @env.ui.info "Fixed port collision: #{name} now on port #{options[:hostport]}" + @env.ui.info("vagrant.actions.vm.forward_ports.fixed_collision", + :name => name, + :new_port => options[:hostport]) end #-------------------------------------------------------------- @@ -82,20 +84,25 @@ module Vagrant end def forward_ports - @env.ui.info "Forwarding ports..." + @env.ui.info "vagrant.actions.vm.forward_ports.forwarding" @env.env.config.vm.forwarded_ports.each do |name, options| adapter = options[:adapter] + message_attributes = { + :name => name, + :guest_port => options[:guestport], + :host_port => options[:hostport], + :adapter => adapter + 1 + } # Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking. # 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.ui.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}" + @env.ui.info("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes) forward_port(name, options) else - @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]}" + @env.ui.info("vagrant.actions.vm.forward_ports.non_nat", message_attributes) end end diff --git a/lib/vagrant/action/vm/halt.rb b/lib/vagrant/action/vm/halt.rb index b9a2c4746..a2f0bd801 100644 --- a/lib/vagrant/action/vm/halt.rb +++ b/lib/vagrant/action/vm/halt.rb @@ -17,7 +17,7 @@ module Vagrant end if env["vm"].vm.state(true) != :powered_off - env.ui.info "Forcing shutdown of VM..." + env.ui.info "vagrant.actions.vm.halt.force" env["vm"].vm.stop end diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index b205f86ad..98172c5a7 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.ui.info "Importing base VM (#{env.env.box.ovf_file})" + env.ui.info "vagrant.actions.vm.import.importing", :name => env.env.box.name # Import the virtual machine env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress| diff --git a/lib/vagrant/action/vm/match_mac_address.rb b/lib/vagrant/action/vm/match_mac_address.rb index 7b8351701..44332cab0 100644 --- a/lib/vagrant/action/vm/match_mac_address.rb +++ b/lib/vagrant/action/vm/match_mac_address.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.ui.info "Matching MAC addresses..." + env.ui.info "vagrant.actions.vm.match_mac.matching" env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac env["vm"].vm.save diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index 26acdc231..3187cdd96 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -26,7 +26,7 @@ module Vagrant if !env.error? && enable_network? catch_action_exception(env) do - @env.ui.info "Enabling host only network..." + @env.ui.info "vagrant.actions.vm.network.enabling" @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.ui.info "Preparing host only network..." + @env.ui.info "vagrant.actions.vm.network.preparing" @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.ui.info "Creating new host only network for environment..." + @env.ui.info "vagrant.actions.vm.network.creating" ni = interfaces.create ni.enable_static(network_ip(net_options[:ip], net_options[:netmask]), diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index 62fa68d61..4bb9f4d63 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'nfs_helpers') +require File.expand_path("../nfs_helpers", __FILE__) module Vagrant class Action @@ -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.ui.info "Exporting NFS shared folders..." + @env.ui.info "vagrant.actions.vm.nfs.exporting" 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.ui.info "Mounting NFS shared folders..." + @env.ui.info "vagrant.actions.vm.nfs.mounting" catch_action_exception(@env) do @env["vm"].system.mount_nfs(host_ip, folders) diff --git a/lib/vagrant/action/vm/persist.rb b/lib/vagrant/action/vm/persist.rb index 8a763ff03..29a3e3929 100644 --- a/lib/vagrant/action/vm/persist.rb +++ b/lib/vagrant/action/vm/persist.rb @@ -11,7 +11,7 @@ module Vagrant end def call(env) - env.ui.info "Persisting the VM UUID (#{env["vm"].uuid})" + env.ui.info "vagrant.actions.vm.persist.persisting", :uuid => env["vm"].uuid env.env.update_dotfile @app.call(env) diff --git a/lib/vagrant/action/vm/provision.rb b/lib/vagrant/action/vm/provision.rb index fb3403b1e..9fe3d76a3 100644 --- a/lib/vagrant/action/vm/provision.rb +++ b/lib/vagrant/action/vm/provision.rb @@ -13,7 +13,7 @@ module Vagrant @app.call(env) if !env.error? && provisioning_enabled? - @env.ui.info "Beginning provisioning process..." + @env.ui.info "vagrant.actions.vm.provision.beginning" @provisioner.provision! end end @@ -40,7 +40,7 @@ module Vagrant @provisioner = provisioner_klass.new(@env) end - @env.ui.info "Provisioning enabled with #{@provisioner.class}" + @env.ui.info "vagrant.actions.vm.provision.enabled", :provisioner => provisioner.class.to_s @provisioner.prepare @provisioner end diff --git a/lib/vagrant/action/vm/resume.rb b/lib/vagrant/action/vm/resume.rb index cf5c5348c..7177f1d10 100644 --- a/lib/vagrant/action/vm/resume.rb +++ b/lib/vagrant/action/vm/resume.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if env["vm"].vm.saved? - env.ui.info "Resuming suspended VM..." + env.ui.info "vagrant.actions.vm.resume.resuming" env["actions"].run(Boot) end diff --git a/lib/vagrant/action/vm/share_folders.rb b/lib/vagrant/action/vm/share_folders.rb index 9ba9828d4..3a6d4a61c 100644 --- a/lib/vagrant/action/vm/share_folders.rb +++ b/lib/vagrant/action/vm/share_folders.rb @@ -60,7 +60,7 @@ module Vagrant end def create_metadata - @env.ui.info "Creating shared folders metadata..." + @env.ui.info "vagrant.actions.vm.share_folders.creating" shared_folders.each do |name, data| folder = VirtualBox::SharedFolder.new @@ -73,11 +73,13 @@ module Vagrant end def mount_shared_folders - @env.ui.info "Mounting shared folders..." + @env.ui.info "vagrant.actions.vm.share_folders.mounting" @env["vm"].ssh.execute do |ssh| shared_folders.each do |name, data| - @env.ui.info "-- #{name}: #{data[:guestpath]}" + @env.ui.info("vagrant.actions.vm.share_folders.mounting_entry", + :name => name, + :guest_path => data[:guestpath]) @env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath]) end end @@ -89,7 +91,7 @@ module Vagrant @env["vm"].ssh.execute do |ssh| @env["vm"].system.prepare_unison(ssh) - @env.ui.info "Creating unison crontab entries..." + @env.ui.info "vagrant.actions.vm.share_folders.setup_unison" unison_folders.each do |name, data| @env["vm"].system.create_unison(ssh, data) end diff --git a/lib/vagrant/action/vm/suspend.rb b/lib/vagrant/action/vm/suspend.rb index 8a6823141..47cf32d53 100644 --- a/lib/vagrant/action/vm/suspend.rb +++ b/lib/vagrant/action/vm/suspend.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if env["vm"].vm.running? - env.ui.info "Saving VM state and suspending execution..." + env.ui.info "vagrant.actions.vm.suspend.suspending" env["vm"].vm.save_state end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 313729feb..da5e506c4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -81,3 +81,85 @@ en: This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`. + +#------------------------------------------------------------------------------- +# Translations for Vagrant middleware acions +#------------------------------------------------------------------------------- + actions: + vm: + boot: + booting: Booting VM... + waiting: Waiting for VM to boot. This can take a few minutes. + ready: VM booted and ready for use! + failed: Failed to connect to VM! + check_box: + not_found: Box %{name} was not found. Fetching box from specified URL... + check_guest_additions: + not_detected: |- + No guest additions were detected on the base box for this VM! Guest + additions are required for forwarded ports, shared folders, host only + networking, and more. If SSH fails on this machine, please install + the guest additions and repackage the box to continue. + + This is not an error message; everything may continue to work properly, + in which case you may ignore this message. + version_mismatch: |- + The guest additions on this VM do not match the install version of + VirtualBox! This may cause things such as forwared ports, shared + folders, and more to not work properly. If any of those things fail on + this machine, please update the guest additions and repackage the + box. + + Guest Additions Version: %{guest_version} + VirtualBox Version: %{virtualbox_version} + clear_forward_ports: + deleting: Clearing any previously set forwarded ports... + clear_shared_folders: + deleting: Cleaing previously set shared folders... + customize: + running: Running any VM customizations... + destroy: + destroying: Destroying VM and associated drives... + destroy_network: + destroying: Destroying unused networking interface... + disable_networks: + disabling: Disabling host only networks... + discard_state: + discarding: Discarding saved state of VM... + export: + create_dir: Creating temporary directory for export... + exporting: Exporting VM... + forward_ports: + fixed_collision: Fixed port collision '%{name}'. Now on port %{new_port}. + forwarding: Forwarding ports... + forwarding_entry: "-- %{name}: %{guest_port} => %{host_port} (adapter %{adapter})" + non_nat: |- + VirtualBox adapter #%{adapter} not configured as "NAT" + Skipping port forwarding '%{name}'. + halt: + force: Forcing shutdown of VM... + import: + importing: Importing base box '%{name}'... + match_mac: + matching: Matching MAC address for NAT networking... + network: + enabling: Enabling host only network... + preparing: Preparing host only network... + creating: Creating new host only network for environment... + nfs: + exporting: Exporting NFS shared folders... + mounting: Mounting NFS shared folders... + persist: + persisting: Persisting the VM UUID (%{uuid})... + provision: + beginning: Beginning provisioning process... + enabled: Provisioning enabled with %{provisioner}... + resume: + resuming: Resuming suspended VM... + share_folders: + creating: Creating shared folders metadata... + mounting: Mounting shared folders... + mounting_entry: "-- %{name}: %{guest_path}" + setup_unison: Creating unison crontab entries... + suspend: + suspending: Saving VM state and suspending execution... diff --git a/templates/strings.yml b/templates/strings.yml index 3cc1c74f7..91b32c73a 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -4,26 +4,6 @@ # In short, | means keep new lines, trim whitespace left and right # The |- does the above, but trims the new line at the end of all text -#--------------------------------------------------------------------- -# CATEGORY: Warning Messages -#--------------------------------------------------------------------- -:vm_additions_not_detected: |- - WARNING! - No guest additions were detected on the base box for this VM! Guest - additions are required for forwarded ports, shared folders, host only - networking, and more. If SSH fails on this machine, please install - the guest additions and repackage the box to continue. -:vm_additions_version_mismatch: |- - WARNING! - The guest additions on this VM do not match the install version of - VirtualBox! This often causes things such as forwared ports, shared - folders, and more to not work properly. If any of those things fail on - this machine, please update the guest additions and repackage the - box. - - Guest Additions Version: <%= guest_additions_version %> - VirtualBox Version: <%= virtualbox_version %> - #--------------------------------------------------------------------- # CATEGORY: Error Messages #--------------------------------------------------------------------- diff --git a/test/vagrant/action/vm/import_test.rb b/test/vagrant/action/vm/import_test.rb index 02f326755..0388aef22 100644 --- a/test/vagrant/action/vm/import_test.rb +++ b/test/vagrant/action/vm/import_test.rb @@ -8,6 +8,7 @@ class ImportVMActionTest < Test::Unit::TestCase ovf_file = "foo" @box = mock("box") + @box.stubs(:name).returns("foo") @box.stubs(:ovf_file).returns(ovf_file) @env.env.stubs(:box).returns(@box)