From 2358130c0e086528cc25a92188d234e105773fe2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Dec 2010 19:52:41 -0800 Subject: [PATCH] Show error if host only networking on Windows --- CHANGELOG.md | 2 ++ lib/vagrant/action/vm/network.rb | 4 ++++ lib/vagrant/errors.rb | 7 +++++++ templates/locales/en.yml | 11 ++++++++--- test/vagrant/action/vm/network_test.rb | 18 ++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c19ace27..cedb9617a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Enumerate VMs in a multi-VM environment in order they were defined. [GH-244] - Check for VM boot changed to use `timeout` library, which works better with Windows. - Show special error if VirtualBox not detected on 64-bit Windows. + - Show error to Windows users attempting to use host only networking since + it doesn't work yet. ## 0.6.8 (November 30, 2010) diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index 0236b8535..c12bb5f15 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -8,6 +8,10 @@ module Vagrant @app = app @env = env + if enable_network? && Util::Platform.windows? + raise Errors::NetworkNotImplemented + end + env["config"].vm.network_options.compact.each do |network_options| raise Errors::NetworkCollision.new if !verify_no_bridge_collision(network_options) end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index cf1447ef0..08f537495 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -183,6 +183,13 @@ module Vagrant error_key(:not_found, "vagrant.actions.vm.network") end + # Note: This is a temporary error for Windows users while host-only + # networking doesn't quite work. + class NetworkNotImplemented < VagrantError + status_code(49) + error_key(:windows_not_implemented, "vagrant.actions.vm.network") + end + class NFSHostRequired < VagrantError status_code(31) error_key(:host_required, "vagrant.actions.vm.nfs") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 21280996a..485d450a9 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -304,14 +304,19 @@ en: This will cause your specified IP to be inaccessible. Please change the IP or name of your host only network to not match that of a bridged or non-hostonly network. - creating: Creating new host only network for environment... - enabling: Enabling host only network... + creating: "Creating new host only network for environment..." + enabling: "Enabling host only network..." not_found: |- The specified host network could not be found: '%{name}.' If the name specification is removed, Vagrant will create a new host only network for you. Alternatively, please create the specified network manually. - preparing: Preparing host only network... + preparing: "Preparing host only network..." + windows_not_implemented: |- + Host only networking is currently broken on Windows due to a bug + in jruby-win32ole. When the bug is fixed, a patch release for Vagrant + will be released to remove this error. Until then, please just use + forwarded ports. nfs: host_required: |- A host class is required for NFS shared folders. By default, these diff --git a/test/vagrant/action/vm/network_test.rb b/test/vagrant/action/vm/network_test.rb index 924d50b02..33626d3ab 100644 --- a/test/vagrant/action/vm/network_test.rb +++ b/test/vagrant/action/vm/network_test.rb @@ -16,6 +16,24 @@ class NetworkVMActionTest < Test::Unit::TestCase end context "initializing" do + should "raise an error if on windows and networking is enabled" do + Vagrant::Util::Platform.stubs(:windows?).returns(true) + @env.env.config.vm.network("foo") + + assert_raises(Vagrant::Errors::NetworkNotImplemented) { + @klass.new(@app, @env) + } + end + + should "not raise an error if not on windows and networking is enabled" do + Vagrant::Util::Platform.stubs(:windows?).returns(false) + @env.env.config.vm.network("foo") + + assert_nothing_raised { + @klass.new(@app, @env) + } + end + should "verify no bridge collisions for each network enabled" do @env.env.config.vm.network("foo") @klass.any_instance.expects(:verify_no_bridge_collision).returns(true).once.with() do |options|