From d143fa965e9879bb96a47647e0bb19a2c130e10f Mon Sep 17 00:00:00 2001 From: Michael Bearne Date: Thu, 16 Dec 2010 13:30:44 +0000 Subject: [PATCH] redhat distribution implemention for host only network --- Gemfile.lock | 20 +++--- lib/vagrant/action/vm/network.rb | 2 +- lib/vagrant/systems/linux.rb | 62 ++++++++++++++---- templates/.DS_Store | Bin 0 -> 6148 bytes ...ork_entry.erb => debian_network_entry.erb} | 0 templates/locales/en.yml | 21 +++--- templates/redhat_network_entry.erb | 8 +++ 7 files changed, 79 insertions(+), 34 deletions(-) create mode 100644 templates/.DS_Store rename templates/{network_entry.erb => debian_network_entry.erb} (100%) create mode 100644 templates/redhat_network_entry.erb 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 0000000000000000000000000000000000000000..459fa59b9acc2ca2a8e8e8e03ddd9ccccd2245ce GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8ZvBB=6pxGNDlMY4;30$x9)%Qou%Zc38YoR^QVPaMUdVUwDSRGh zcE@6|hn_@q26n%1cV?2!2ie^bLP&2GwS;hl5DFTiM6$wgdZnvE!4eRfBhpDYN+9?`3@3hYvy3;x@ih5nu zoj0|AbaHXk3!d`l;>Btxaj9r~78ZTEU`$v6R)7^?1z3SK6rck|?W_^YA*=u^@V^wm z{Xs)RbO}p~X6t~?lmLJ=m^KC+YYEKJgf3xe5jlDG&*DXzx5M+b2^Z3}$UQ5-3M?y7wL=Hb|4aB~Ru=ioDLi5YSb;yLfUI@>t_L4Q zXY04m!?RXHyN8B`aU~Kk;7gYP7~no~Xq?uskwctISX#uV;Jir( +NETMASK=<%= net_options[:netmask] %> +#VAGRANT-END \ No newline at end of file