Changes to enable rhel/centos-style bridged & hostonly networking
This commit is contained in:
parent
026a551496
commit
a04fce880c
|
@ -1,27 +1,80 @@
|
||||||
|
require 'set'
|
||||||
|
|
||||||
|
require 'vagrant/util/template_renderer'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Guest
|
module Guest
|
||||||
class Redhat < Linux
|
class Redhat < Linux
|
||||||
def prepare_host_only_network(net_options)
|
# Make the TemplateRenderer top-level
|
||||||
# Remove any previous host only network additions to the
|
include Vagrant::Util
|
||||||
# interface file.
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Since redhat/centos uses a single file for each interface,
|
||||||
|
# we must loop through for each network assigned
|
||||||
|
networks.each do |network|
|
||||||
|
interfaces.add(network[:interface])
|
||||||
|
|
||||||
|
# First, remove any previous network modifications
|
||||||
|
# from the interface file.
|
||||||
|
vm.ssh.execute do |ssh|
|
||||||
|
ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||||
|
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||||
|
ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}'")
|
||||||
|
end
|
||||||
|
|
||||||
|
entry = ""
|
||||||
|
entry << TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
||||||
|
:options => network)
|
||||||
|
|
||||||
|
# Perform the careful dance necessary to to reconfigure
|
||||||
|
# the network interfaces
|
||||||
|
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry_#{network[:interface]}")
|
||||||
|
end
|
||||||
|
|
||||||
vm.ssh.execute do |ssh|
|
vm.ssh.execute do |ssh|
|
||||||
# Clear out any previous entries
|
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||||
ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}")
|
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||||
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]}")
|
# SSH never dies.
|
||||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{net_options[:adapter]} > #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}'")
|
interfaces.each do |interface|
|
||||||
|
ssh.exec!("sudo /sbin/ifdown eth#{interface} 2> /dev/null")
|
||||||
|
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}'")
|
||||||
|
# Bring back up each network interface, reconfigured
|
||||||
|
ssh.exec!("sudo /sbin/ifup eth#{interface}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_host_only_network(net_options)
|
def prepare_bridged_networks(networks)
|
||||||
entry = TemplateRenderer.render('guests/redhat/network_hostonly',
|
# Remove any previous bridged network additions from the
|
||||||
:net_options => net_options)
|
# interface file.
|
||||||
|
vm.ssh.execute do |ssh|
|
||||||
|
networks.each do |network|
|
||||||
|
# Clear out any previous entries
|
||||||
|
ssh.exec!("sudo touch #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}")
|
||||||
|
ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-BRIDGED/,/^#VAGRANT-END-BRIDGED/ d' #{network_scripts_dir}/ifcfg-eth#{network[:adapter]} > /tmp/vagrant-ifcfg-eth#{network[:adapter]}")
|
||||||
|
ssh.exec!("sudo su -c 'cat /tmp/vagrant-ifcfg-eth#{network[:adapter]} > #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}'")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable_bridged_networks(networks)
|
||||||
|
entry = TemplateRenderer.render('guests/redhat/network_bridged',
|
||||||
|
:networks => networks)
|
||||||
|
|
||||||
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
|
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry")
|
||||||
|
|
||||||
vm.ssh.execute do |ssh|
|
vm.ssh.execute do |ssh|
|
||||||
interface_up = ssh.test?("/sbin/ifconfig eth#{net_options[:adapter]} | grep 'inet addr:'")
|
networks.each do |network|
|
||||||
ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") if interface_up
|
interface_up = ssh.test?("/sbin/ifconfig eth#{network[:adapter]} | grep 'inet addr:'")
|
||||||
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> #{network_scripts_dir}/ifcfg-eth#{net_options[:adapter]}'")
|
ssh.exec!("sudo /sbin/ifdown eth#{network[:adapter]} 2> /dev/null") if interface_up
|
||||||
ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}")
|
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> #{network_scripts_dir}/ifcfg-eth#{network[:adapter]}'")
|
||||||
|
ssh.exec!("sudo /sbin/ifup eth#{network[:adapter]}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +83,7 @@ module Vagrant
|
||||||
# operationg systems (SuSE) which behave similarly but with a different
|
# operationg systems (SuSE) which behave similarly but with a different
|
||||||
# path to the network scripts.
|
# path to the network scripts.
|
||||||
def network_scripts_dir
|
def network_scripts_dir
|
||||||
'/etc/sysconfig/network-scripts/'
|
'/etc/sysconfig/network-scripts'
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_host_name(name)
|
def change_host_name(name)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#VAGRANT-BEGIN
|
||||||
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
|
BOOTPROTO=dhcp
|
||||||
|
ONBOOT=yes
|
||||||
|
DEVICE=eth<%= options[:interface] %>
|
||||||
|
#VAGRANT-END
|
|
@ -1,8 +0,0 @@
|
||||||
#VAGRANT-BEGIN-HOSTONLY
|
|
||||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
|
||||||
BOOTPROTO=static
|
|
||||||
DHCPCLASS=
|
|
||||||
IPADDR=<%= net_options[:ip] %>
|
|
||||||
NETMASK=<%= net_options[:netmask] %>
|
|
||||||
DEVICE=eth<%= net_options[:adapter] %>
|
|
||||||
#VAGRANT-END-HOSTONLY
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#VAGRANT-BEGIN
|
||||||
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
|
BOOTPROTO=static
|
||||||
|
IPADDR=<%= options[:ip] %>
|
||||||
|
NETMASK=<%= options[:netmask] %>
|
||||||
|
DEVICE=eth<%= options[:interface] %>
|
||||||
|
#VAGRANT-END
|
Loading…
Reference in New Issue