From 0915186b26dc53adbc93b3426ba12802d0e2962c Mon Sep 17 00:00:00 2001 From: Elad Rosenheim Date: Mon, 31 Dec 2012 10:38:36 +0200 Subject: [PATCH] Fix guest plugin for RH & SUSE --- plugins/guests/redhat/guest.rb | 30 ++++++++++++++++-------------- plugins/guests/suse/guest.rb | 11 +++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/guests/redhat/guest.rb b/plugins/guests/redhat/guest.rb index 269900182..39c508856 100644 --- a/plugins/guests/redhat/guest.rb +++ b/plugins/guests/redhat/guest.rb @@ -22,10 +22,10 @@ module VagrantPlugins # Remove any previous vagrant configuration in this network interface's # configuration files. - vm.channel.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") - vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}") - vm.channel.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") - vm.channel.sudo("rm /tmp/vagrant-ifcfg-eth#{network[:interface]}") + vm.communicate.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") + vm.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}") + vm.communicate.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}") + vm.communicate.sudo("rm /tmp/vagrant-ifcfg-eth#{network[:interface]}") # Render and upload the network entry file to a deterministic # temporary location. @@ -37,17 +37,17 @@ module VagrantPlugins temp.write(entry) temp.close - vm.channel.upload(temp.path, "/tmp/vagrant-network-entry_#{network[:interface]}") + vm.communicate.upload(temp.path, "/tmp/vagrant-network-entry_#{network[:interface]}") end # Bring down all the interfaces we're reconfiguring. By bringing down # each specifically, we avoid reconfiguring eth0 (the NAT interface) so # SSH never dies. interfaces.each do |interface| - vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null", :error_check => false) - vm.channel.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}") - vm.channel.sudo("rm /tmp/vagrant-network-entry_#{interface}") - vm.channel.sudo("/sbin/ifup eth#{interface} 2> /dev/null") + vm.communicate.sudo("/sbin/ifdown eth#{interface} 2> /dev/null", :error_check => false) + vm.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}") + vm.communicate.sudo("rm /tmp/vagrant-network-entry_#{interface}") + vm.communicate.sudo("/sbin/ifup eth#{interface} 2> /dev/null") end end @@ -60,11 +60,13 @@ module VagrantPlugins end def change_host_name(name) - # Only do this if the hostname is not already set - if !vm.channel.test("sudo hostname | grep '#{name}'") - vm.channel.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") - vm.channel.sudo("hostname #{name}") - vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + vm.communicate.tap do |comm| + # Only do this if the hostname is not already set + if !comm.test("sudo hostname | grep '#{name}'") + comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") + comm.sudo("hostname #{name}") + comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + end end end end diff --git a/plugins/guests/suse/guest.rb b/plugins/guests/suse/guest.rb index cc8045c6c..17da59f29 100644 --- a/plugins/guests/suse/guest.rb +++ b/plugins/guests/suse/guest.rb @@ -8,6 +8,17 @@ module VagrantPlugins def network_scripts_dir '/etc/sysconfig/network/' end + + def change_host_name(name) + vm.communicate.tap do |comm| + # Only do this if the hostname is not already set + if !comm.test("sudo hostname | grep '#{name}'") + comm.sudo("echo '#{name}' > /etc/HOSTNAME") + comm.sudo("hostname #{name}") + comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + end + end + end end end end