From ad834feccc932ee299a23d5ea48b21627190b7ff Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Mon, 16 May 2011 15:10:25 -0700 Subject: [PATCH] (368) Added local network config code for Suse. Networking in SUSE works almost exactly like redhat. The only difference is the location of the networking scripts. This has been verified as working on SLES11sp1, but requires a previously configured eth1 interface (as with redhat) I have also verified that I can still bring up a localnet on rhel 4,5 --- lib/vagrant/systems.rb | 1 + lib/vagrant/systems/linux.rb | 1 + lib/vagrant/systems/redhat.rb | 16 ++++++++++++---- lib/vagrant/systems/suse.rb | 9 +++++++++ lib/vagrant/vm.rb | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 lib/vagrant/systems/suse.rb diff --git a/lib/vagrant/systems.rb b/lib/vagrant/systems.rb index 89a2f86ce..7c815ffcf 100644 --- a/lib/vagrant/systems.rb +++ b/lib/vagrant/systems.rb @@ -8,4 +8,5 @@ require 'vagrant/systems/solaris' require 'vagrant/systems/debian' require 'vagrant/systems/gentoo' require 'vagrant/systems/redhat' +require 'vagrant/systems/suse' require 'vagrant/systems/ubuntu' diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index fd747576c..592cc5bfa 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -13,6 +13,7 @@ module Vagrant return :gentoo if ssh.test?("cat /etc/gentoo-release") return :redhat if ssh.test?("cat /etc/redhat-release") + return :suse if ssh.test?("cat /etc/SuSE-release") end # Can't detect the distro, assume vanilla linux diff --git a/lib/vagrant/systems/redhat.rb b/lib/vagrant/systems/redhat.rb index 3805dcbca..68bd3678e 100644 --- a/lib/vagrant/systems/redhat.rb +++ b/lib/vagrant/systems/redhat.rb @@ -6,9 +6,9 @@ module Vagrant # interface file. vm.ssh.execute do |ssh| # Clear out any previous entries - ssh.exec!("sudo touch /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}") - 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]}'") + ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}") + ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/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]} > #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}'") end end @@ -20,11 +20,19 @@ module Vagrant vm.ssh.execute do |ssh| interface_up = ssh.test?("/sbin/ifconfig eth#{net_options[:adapter]} | grep 'inet addr:'") ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") if interface_up - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/sysconfig/network-scripts/ifcfg-eth#{net_options[:adapter]}'") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}'") ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") end end + # The path to the directory with the network configuration scripts. + # This is pulled out into its own directory since there are other + # operationg systems (SuSE) which behave similarly but with a different + # path to the network scripts. + def network_scripts_dir + '/etc/sysconfig/network-scripts/' + end + def change_host_name(name) vm.ssh.execute do |ssh| # Only do this if the hostname is not already set diff --git a/lib/vagrant/systems/suse.rb b/lib/vagrant/systems/suse.rb new file mode 100644 index 000000000..411338e81 --- /dev/null +++ b/lib/vagrant/systems/suse.rb @@ -0,0 +1,9 @@ +module Vagrant + module Systems + class Suse < Redhat + def network_scripts_dir + '/etc/sysconfig/network/' + end + end + end +end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 239922d7c..5002ede19 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -63,6 +63,7 @@ module Vagrant :freebsd => Systems::FreeBSD, :gentoo => Systems::Gentoo, :redhat => Systems::Redhat, + :suse => Systems::Suse, :linux => Systems::Linux, :solaris => Systems::Solaris }