2012-01-04 04:46:26 +00:00
|
|
|
require 'set'
|
2012-01-08 05:16:18 +00:00
|
|
|
require 'tempfile'
|
2012-01-04 04:46:26 +00:00
|
|
|
|
2012-02-11 02:07:59 +00:00
|
|
|
require 'vagrant/util/line_ending_helpers'
|
2012-01-04 04:46:26 +00:00
|
|
|
require 'vagrant/util/template_renderer'
|
|
|
|
|
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
|
2012-01-04 04:46:26 +00:00
|
|
|
# Make the TemplateRenderer top-level
|
|
|
|
include Vagrant::Util
|
2012-02-11 02:07:59 +00:00
|
|
|
include Vagrant::Util::LineEndingHelpers
|
2012-01-04 04:46:26 +00:00
|
|
|
|
|
|
|
def configure_networks(networks)
|
|
|
|
# Accumulate the configurations to add to the interfaces file as
|
|
|
|
# well as what interfaces we're actually configuring since we use that
|
|
|
|
# later.
|
|
|
|
interfaces = Set.new
|
|
|
|
networks.each do |network|
|
|
|
|
interfaces.add(network[:interface])
|
|
|
|
|
2012-01-05 05:43:14 +00:00
|
|
|
# Remove any previous vagrant configuration in this network interface's
|
|
|
|
# configuration files.
|
2012-01-07 04:03:56 +00:00
|
|
|
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]}")
|
2012-01-04 04:46:26 +00:00
|
|
|
|
2012-01-05 05:43:14 +00:00
|
|
|
# Render and upload the network entry file to a deterministic
|
|
|
|
# temporary location.
|
|
|
|
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
|
|
|
:options => network)
|
2012-01-07 05:42:25 +00:00
|
|
|
|
2012-02-11 02:07:59 +00:00
|
|
|
# Convert line endings to unix-style
|
|
|
|
entry = dos_to_unix(entry)
|
|
|
|
|
2012-01-07 05:42:25 +00:00
|
|
|
temp = Tempfile.new("vagrant")
|
|
|
|
temp.write(entry)
|
|
|
|
temp.close
|
|
|
|
|
|
|
|
vm.channel.upload(temp.path, "/tmp/vagrant-network-entry_#{network[:interface]}")
|
2012-01-04 04:46:26 +00:00
|
|
|
end
|
|
|
|
|
2012-01-07 04:03:56 +00:00
|
|
|
# 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|
|
2012-02-07 23:42:28 +00:00
|
|
|
vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null", :error_check => false)
|
2012-01-07 04:03:56 +00:00
|
|
|
vm.channel.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}")
|
2012-02-07 23:42:28 +00:00
|
|
|
vm.channel.sudo("/sbin/ifup eth#{interface} 2> /dev/null")
|
2011-01-10 14:21:52 +00:00
|
|
|
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
|
2012-01-08 05:16:18 +00:00
|
|
|
# operating systems (SuSE) which behave similarly but with a different
|
2011-05-16 22:10:25 +00:00
|
|
|
# path to the network scripts.
|
|
|
|
def network_scripts_dir
|
2012-01-04 04:46:26 +00:00
|
|
|
'/etc/sysconfig/network-scripts'
|
2011-05-16 22:10:25 +00:00
|
|
|
end
|
|
|
|
|
2011-01-14 17:51:19 +00:00
|
|
|
def change_host_name(name)
|
2012-01-07 04:03:56 +00:00
|
|
|
# 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")
|
2011-01-14 17:51:19 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-10 14:21:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|