From 7982f01f2e9e8120f2849194fad95d3f59976e12 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 3 Jan 2012 09:34:32 -0800 Subject: [PATCH] Check for adapter collisions --- lib/vagrant/action/vm/network.rb | 14 ++++++++++++++ lib/vagrant/errors.rb | 5 +++++ templates/locales/en.yml | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index d27fd549e..795b8e4e6 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -46,6 +46,9 @@ module Vagrant @logger.debug("Assigning adapter locations...") assign_adapter_locations(adapters) + # Verify that our adapters are good just prior to enabling them. + verify_adapters(adapters) + # Create all the network interfaces @logger.info("Enabling adapters...") env[:ui].info I18n.t("vagrant.actions.vm.network.preparing") @@ -100,6 +103,17 @@ module Vagrant end end + # Verifies that the adapter configurations look good. This will + # raise an exception in the case that any errors occur. + def verify_adapters(adapters) + # Verify that there are no collisions in the adapters being used. + used = Set.new + adapters.each do |adapter| + raise Errors::NetworkAdapterCollision if used.include?(adapter[:adapter]) + used.add(adapter[:adapter]) + end + end + # Assigns the actual interface number of a network based on the # enabled NICs on the virtual machine. # diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index e4f5b0c38..429b9c7d5 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -203,6 +203,11 @@ module Vagrant error_key(:multi_vm_target_required) end + class NetworkAdapterCollision < VagrantError + status_code(65) + error_key(:adapter_collision, "vagrant.actions.vm.network") + end + class NetworkCollision < VagrantError status_code(29) error_key(:collides, "vagrant.actions.vm.host_only_network") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 311c69a37..4b523b9ef 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -395,6 +395,10 @@ en: MAC address is typically up to the box and box maintiner. Please contact the relevant person to solve this issue. network: + adapter_collision: |- + More than one network have been assigned to the same adapter. At + this point this error is actually indicative of an internal error + within Vagrant. Please report this as a bug. configuring: |- Configuring and enabling network interfaces... no_adapters: |-