diff --git a/Gemfile.lock b/Gemfile.lock index a672bdfdf..f1c307c81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT remote: git://github.com/mitchellh/virtualbox.git - revision: 041996145591d20acf3e04fef3d4709f826d878a + revision: c79de55b05dd5703fa157e9900efecaaf1da5861 specs: - virtualbox (0.7.6.dev) + virtualbox (0.7.8.dev) ffi (~> 0.6.3) PATH @@ -25,28 +25,28 @@ GEM abstract (1.0.0) archive-tar-minitar (0.5.2) bluecloth (2.0.9) - columnize (0.3.1) + columnize (0.3.2) contest (0.1.2) erubis (2.6.6) abstract (>= 1.0.0) ffi (0.6.3) rake (>= 0.8.7) - i18n (0.4.1) + i18n (0.4.2) json (1.4.6) linecache (0.43) linecache19 (0.5.11) ruby_core_source (>= 0.1.4) mario (0.0.6) - mocha (0.9.8) + mocha (0.9.10) rake net-scp (1.0.4) net-ssh (>= 1.99.1) net-ssh (2.0.23) rake (0.8.7) - ruby-debug (0.10.3) + ruby-debug (0.10.4) columnize (>= 0.1) - ruby-debug-base (~> 0.10.3.0) - ruby-debug-base (0.10.3) + ruby-debug-base (~> 0.10.4.0) + ruby-debug-base (0.10.4) linecache (>= 0.3) ruby-debug-base19 (0.11.24) columnize (>= 0.3.1) @@ -58,8 +58,8 @@ GEM ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.4) archive-tar-minitar (>= 0.5.2) - thor (0.14.3) - yard (0.6.1) + thor (0.14.6) + yard (0.6.3) PLATFORMS ruby diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index 0236b8535..c49a1a7f3 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -21,8 +21,8 @@ module Vagrant if enable_network? @env.ui.info I18n.t("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.prepare_host_only_network(network_options) @env["vm"].system.enable_host_only_network(network_options) end end diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 021a687b7..c0aee84b7 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -62,27 +62,39 @@ module Vagrant end end - def prepare_host_only_network + def prepare_host_only_network(net_options) # Remove any previous host only network additions to the # interface file. vm.ssh.execute do |ssh| - # Verify debian/ubuntu - ssh.exec!("cat /etc/debian_version", :error_class => LinuxError, :_key => :network_not_debian) - - # Clear out any previous entries - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") + case distribution(ssh) + when :debian + # Clear out any previous entries + ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") + when :redhat + ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]} > /tmp/vagrant-ifcfg-eth#{net_options[:adapter]}") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{net_options[:adapter]} > /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}'") + end end end def enable_host_only_network(net_options) - entry = TemplateRenderer.render('network_entry', :net_options => net_options) - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + vm.ssh.execute do |ssh| + case distribution(ssh) + when :debian + entry = TemplateRenderer.render('debian_network_entry', :net_options => net_options) + vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'") + ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") - vm.ssh.execute do |ssh| - ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'") - ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") + when :redhat + entry = TemplateRenderer.render('redhat_network_entry', :net_options => net_options) + vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}'") + ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") + end end end @@ -110,6 +122,30 @@ module Vagrant sleep sleeptime end end + + def debian?(ssh) + ssh.exec!("test -e /etc/debian_version") do |ch, type, data| + return true if type == :exit_status && data == 0 + end + false + end + + def redhat?(ssh) + ssh.exec!("test -e /etc/redhat-release ") do |ch, type, data| + return true if type == :exit_status && data == 0 + end + false + end + + def distribution(ssh) + if debian?(ssh) + :debian + elsif redhat?(ssh) + :redhat + else + raise LinuxError.new(:distribution_not_supported) + end + end end class Linux < Base diff --git a/templates/.DS_Store b/templates/.DS_Store new file mode 100644 index 000000000..459fa59b9 Binary files /dev/null and b/templates/.DS_Store differ diff --git a/templates/network_entry.erb b/templates/debian_network_entry.erb similarity index 100% rename from templates/network_entry.erb rename to templates/debian_network_entry.erb diff --git a/templates/locales/en.yml b/templates/locales/en.yml index ff3286e77..9f9749bf5 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -432,16 +432,17 @@ en: systems: linux: attempting_halt: "Attempting graceful shutdown of linux..." - mount_fail: "Failed to mount shared folders. `vboxsf` was not available." - network_not_debian: |- - Host only networking is only supported for Debian/Ubuntu by the built-in - "Linux" system. If you're using some other distro and want to implement - host only networking, please subclass the `Vagrant::Systems::Linux` class - and implement the `prepare_host_only_network` and `enable_host_only_network` - methods. + mount_fail: "Failed to mount shared folders. `vboxsf` was not available." + distribution_not_supported: |- + Host only networking is only supported for Debian/Ubuntu and Redhat Distributions by the built-in + "Linux" system. If you're using some other distro and want to implement + host only networking, please subclass the `Vagrant::Systems::Linux` class + and implement the `prepare_host_only_network` and `enable_host_only_network` + methods. - Otherwise, please report your distro and how to modify network interfaces - to the Vagrant mailing list or IRC and we'll probably be glad to add it - to the internal systems. + Otherwise, please report your distro and how to modify network interfaces + to the Vagrant mailing list or IRC and we'll probably be glad to add it + to the internal systems. + solaris: attempting_halt: "Attempting graceful shutdown of solaris..." diff --git a/templates/redhat_network_entry.erb b/templates/redhat_network_entry.erb new file mode 100644 index 000000000..d3f39d695 --- /dev/null +++ b/templates/redhat_network_entry.erb @@ -0,0 +1,8 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. +# Please do not modify any of these contents. +BOOTPROTO=static +DHCPCLASS= +IPADDR=<%= net_options[:ip] %> +NETMASK=<%= net_options[:netmask] %> +#VAGRANT-END \ No newline at end of file