2011-01-10 14:21:52 +00:00
module Vagrant
2011-12-16 05:05:19 +00:00
module Guest
2011-01-10 14:21:52 +00:00
class Redhat < Linux
2011-01-10 17:15:15 +00:00
def prepare_host_only_network ( net_options )
2011-01-10 14:21:52 +00:00
# Remove any previous host only network additions to the
# interface file.
vm . ssh . execute do | ssh |
# Clear out any previous entries
2011-05-16 22:10:25 +00:00
ssh . exec! ( " sudo touch #{ network_scripts_dir } /ifcfg-eth #{ net_options [ :adapter ] } " )
2012-01-01 03:08:56 +00:00
ssh . exec! ( " sudo sed -e '/^ # VAGRANT-BEGIN-HOSTONLY/,/^ # VAGRANT-END-HOSTONLY/ d' #{ network_scripts_dir } /ifcfg-eth #{ net_options [ :adapter ] } > /tmp/vagrant-ifcfg-eth #{ net_options [ :adapter ] } " )
2011-05-16 22:10:25 +00:00
ssh . exec! ( " sudo su -c 'cat /tmp/vagrant-ifcfg-eth #{ net_options [ :adapter ] } > #{ network_scripts_dir } /ifcfg-eth #{ net_options [ :adapter ] } ' " )
2011-01-10 14:21:52 +00:00
end
end
def enable_host_only_network ( net_options )
2012-01-01 03:08:56 +00:00
entry = TemplateRenderer . render ( 'guests/redhat/network_hostonly' ,
:net_options = > net_options )
2011-01-10 14:21:52 +00:00
vm . ssh . upload! ( StringIO . new ( entry ) , " /tmp/vagrant-network-entry " )
vm . ssh . execute do | ssh |
2011-01-10 17:15:15 +00:00
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
2011-05-16 22:10:25 +00:00
ssh . exec! ( " sudo su -c 'cat /tmp/vagrant-network-entry >> #{ network_scripts_dir } /ifcfg-eth #{ net_options [ :adapter ] } ' " )
2011-01-10 14:21:52 +00:00
ssh . exec! ( " sudo /sbin/ifup eth #{ net_options [ :adapter ] } " )
end
end
2011-01-14 17:51:19 +00:00
2011-05-16 22:10:25 +00:00
# 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
2011-01-14 17:51:19 +00:00
def change_host_name ( name )
vm . ssh . execute do | ssh |
2011-01-29 01:34:26 +00:00
# Only do this if the hostname is not already set
if ! ssh . test? ( " sudo hostname | grep ' #{ name } ' " )
ssh . exec! ( " sudo sed -i 's/ \\ (HOSTNAME= \\ ).*/ \\ 1 #{ name } /' /etc/sysconfig/network " )
ssh . exec! ( " sudo hostname #{ name } " )
2011-08-05 09:52:33 +00:00
ssh . exec! ( " sudo sed -i 's@^ \\ (127[.]0[.]0[.]1[[:space:]] \\ + \\ )@ \\ 1 #{ name } #{ name . split ( '.' ) [ 0 ] } @' /etc/hosts " )
2011-01-29 01:34:26 +00:00
end
2011-01-14 17:51:19 +00:00
end
end
2011-01-10 14:21:52 +00:00
end
end
end