Fix configure networks and templates to work off polled interface names.
This commit is contained in:
parent
6ff81dc29c
commit
5345c1479a
|
@ -13,29 +13,28 @@ module VagrantPlugins
|
|||
|
||||
def self.configure_networks(machine, networks)
|
||||
network_scripts_dir = machine.guest.capability("network_scripts_dir")
|
||||
|
||||
interface_names = machine.guest.capability("interfaces_list")
|
||||
|
||||
# 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])
|
||||
|
||||
# Down the interface before munging the config file. This might fail
|
||||
# if the interface is not actually set up yet so ignore errors.
|
||||
machine.communicate.sudo(
|
||||
"/sbin/ifdown eth#{network[:interface]} 2> /dev/null", error_check: false)
|
||||
|
||||
interface = interface_names[network[:interface]]
|
||||
interfaces.add(interface)
|
||||
network[:device] = interface
|
||||
|
||||
# Remove any previous vagrant configuration in this network interface's
|
||||
# configuration files.
|
||||
machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
|
||||
machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-#{interface}")
|
||||
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-#{interface} > /tmp/vagrant-ifcfg-#{interface}")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-ifcfg-#{interface} > #{network_scripts_dir}/ifcfg-#{interface}")
|
||||
machine.communicate.sudo("rm /tmp/vagrant-ifcfg-#{interface}")
|
||||
|
||||
# Render and upload the network entry file to a deterministic
|
||||
# temporary location.
|
||||
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
||||
# use fedora for now
|
||||
entry = TemplateRenderer.render("guests/fedora/network_#{network[:type]}",
|
||||
:options => network)
|
||||
|
||||
temp = Tempfile.new("vagrant")
|
||||
|
@ -43,25 +42,20 @@ module VagrantPlugins
|
|||
temp.write(entry)
|
||||
temp.close
|
||||
|
||||
machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry_#{network[:interface]}")
|
||||
machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry_#{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|
|
||||
puts interface.inspect
|
||||
retryable(:on => Vagrant::Errors::VagrantError, :tries => 3, :sleep => 2) do
|
||||
# The interface should already be down so this probably
|
||||
# won't do anything, so we run it with error_check false.
|
||||
machine.communicate.sudo(
|
||||
"/sbin/ifdown eth#{interface} 2> /dev/null", error_check: false)
|
||||
|
||||
# Add the new interface and bring it up
|
||||
machine.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}")
|
||||
machine.communicate.sudo("ARPCHECK=no /sbin/ifup eth#{interface} 2> /dev/null")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-#{interface}")
|
||||
machine.communicate.sudo("/sbin/ifdown #{interface}", :error_check => true)
|
||||
machine.communicate.sudo("/sbin/ifup #{interface}")
|
||||
end
|
||||
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-network-entry_#{interface}")
|
||||
machine.communicate.sudo("rm /tmp/vagrant-network-entry_#{interface}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
DEVICE=eth<%= options[:interface] %>
|
||||
DEVICE=<%= options[:device] %>
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -5,6 +5,6 @@ BOOTPROTO=none
|
|||
ONBOOT=yes
|
||||
IPADDR=<%= options[:ip] %>
|
||||
NETMASK=<%= options[:netmask] %>
|
||||
DEVICE=eth<%= options[:interface] %>
|
||||
DEVICE=<%= options[:device] %>
|
||||
PEERDNS=no
|
||||
#VAGRANT-END
|
||||
|
|
Loading…
Reference in New Issue