From 43d85930ed3c27fded562aacc17a910d5d72e472 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Mar 2013 10:51:07 -0700 Subject: [PATCH] Improve network interface detection to avoid crash [GH-1480] --- CHANGELOG.md | 2 ++ lib/vagrant/errors.rb | 4 ++++ plugins/providers/virtualbox/action/forward_ports.rb | 8 ++++++++ templates/locales/en.yml | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 776c3e9ff..197018a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ BUG FIXES: auto-corrected ports. [GH-1472] - Fix obscure error when temp directory is world writable when adding boxes. + - Improved error handling around network interface detection for + VirtualBox [GH-1480] ## 1.1.2 (March 18, 2013) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index fa286fb09..361a6d80d 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -203,6 +203,10 @@ module Vagrant error_key(:home_dir_not_accessible) end + class ForwardPortAdapterNotFound < VagrantError + error_key(:forward_port_adapter_not_found) + end + class ForwardPortAutolistEmpty < VagrantError error_key(:auto_empty, "vagrant.actions.vm.forward_ports") end diff --git a/plugins/providers/virtualbox/action/forward_ports.rb b/plugins/providers/virtualbox/action/forward_ports.rb index 55f30dd31..ee64d7988 100644 --- a/plugins/providers/virtualbox/action/forward_ports.rb +++ b/plugins/providers/virtualbox/action/forward_ports.rb @@ -50,6 +50,14 @@ module VagrantPlugins @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes)) + # Verify we have the network interface to attach to + if !interfaces[fp.adapter] + raise Vagrant::Errors::ForwardPortAdapterNotFound, + :adapter => fp.adapter.to_s, + :guest => fp.guest_port.to_s, + :host => fp.host_port.to_s + end + # Port forwarding requires the network interface to be a NAT interface, # so verify that that is the case. if interfaces[fp.adapter][:type] != :nat diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 1d8f69b05..a450702d2 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -130,6 +130,14 @@ en: may run at any given time to avoid problems with VirtualBox inconsistencies occurring. Please wait for the other instance of Vagrant to end and then try again. + forward_port_adapter_not_found: |- + The adapter to attach a forwarded port to was not found. Please + verify that the given adapter is setup on the machine as a NAT + interface. + + Host port: %{host} + Guest port: %{guest} + Adapter: %{adapter} gem_command_in_bundler: |- You cannot run the `vagrant plugin` command while in a bundler environment. This should generally never happen unless Vagrant is installed outside