guests/debian: Use predictable naming for network configuration
This commit is contained in:
parent
dbb2d99278
commit
d9b8352a58
|
@ -11,14 +11,16 @@ module VagrantPlugins
|
||||||
def self.configure_networks(machine, networks)
|
def self.configure_networks(machine, networks)
|
||||||
comm = machine.communicate
|
comm = machine.communicate
|
||||||
|
|
||||||
interfaces = {}
|
commands = []
|
||||||
entries = []
|
entries = []
|
||||||
|
interfaces = []
|
||||||
|
|
||||||
|
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
|
||||||
|
interfaces = stdout.split("\n")
|
||||||
|
end
|
||||||
|
|
||||||
# Accumulate the configurations to add to the interfaces file as
|
|
||||||
# well as what interfaces we're actually configuring since we use that
|
|
||||||
# later.
|
|
||||||
networks.each do |network|
|
networks.each do |network|
|
||||||
interfaces[network[:interface]] = true
|
network[:device] = interfaces[network[:interface]]
|
||||||
|
|
||||||
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
|
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
|
||||||
options: network,
|
options: network,
|
||||||
|
@ -34,17 +36,12 @@ module VagrantPlugins
|
||||||
comm.upload(f.path, "/tmp/vagrant-network-entry")
|
comm.upload(f.path, "/tmp/vagrant-network-entry")
|
||||||
end
|
end
|
||||||
|
|
||||||
commands = []
|
networks.each do |network|
|
||||||
|
|
||||||
# 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, _|
|
|
||||||
# Ubuntu 16.04+ returns an error when downing an interface that
|
# Ubuntu 16.04+ returns an error when downing an interface that
|
||||||
# does not exist. The `|| true` preserves the behavior that older
|
# does not exist. The `|| true` preserves the behavior that older
|
||||||
# Ubuntu versions exhibit and Vagrant expects (GH-7155)
|
# Ubuntu versions exhibit and Vagrant expects (GH-7155)
|
||||||
commands << "/sbin/ifdown 'eth#{interface}' 2> /dev/null || true"
|
commands << "/sbin/ifdown '#{network[:device]}' || true"
|
||||||
commands << "/sbin/ip addr flush dev 'eth#{interface}' 2> /dev/null"
|
commands << "/sbin/ip addr flush dev '#{network[:device]}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reconfigure /etc/network/interfaces.
|
# Reconfigure /etc/network/interfaces.
|
||||||
|
@ -65,8 +62,8 @@ module VagrantPlugins
|
||||||
EOH
|
EOH
|
||||||
|
|
||||||
# Bring back up each network interface, reconfigured.
|
# Bring back up each network interface, reconfigured.
|
||||||
interfaces.each do |interface, _|
|
networks.each do |network|
|
||||||
commands << "/sbin/ifup 'eth#{interface}'"
|
commands << "/sbin/ifup '#{network[:device]}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run all the commands in one session to prevent partial configuration
|
# Run all the commands in one session to prevent partial configuration
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#VAGRANT-BEGIN
|
#VAGRANT-BEGIN
|
||||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
auto eth<%= options[:interface] %>
|
auto <%= options[:device] %>
|
||||||
iface eth<%= options[:interface] %> inet dhcp
|
iface <%= options[:device] %> inet dhcp
|
||||||
<% if !options[:use_dhcp_assigned_default_route] %>
|
<% if !options[:use_dhcp_assigned_default_route] %>
|
||||||
post-up route del default dev $IFACE || true
|
post-up route del default dev $IFACE || true
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#VAGRANT-BEGIN
|
#VAGRANT-BEGIN
|
||||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
auto eth<%= options[:interface] %>
|
auto <%= options[:device] %>
|
||||||
iface eth<%= options[:interface] %> inet static
|
iface <%= options[:device] %> inet static
|
||||||
address <%= options[:ip] %>
|
address <%= options[:ip] %>
|
||||||
netmask <%= options[:netmask] %>
|
netmask <%= options[:netmask] %>
|
||||||
<% if options[:gateway] %>
|
<% if options[:gateway] %>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#VAGRANT-BEGIN
|
#VAGRANT-BEGIN
|
||||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
auto eth<%= options[:interface] %>
|
auto <%= options[:device] %>
|
||||||
iface eth<%= options[:interface] %> inet6 static
|
iface <%= options[:device] %> inet6 static
|
||||||
address <%= options[:ip] %>
|
address <%= options[:ip] %>
|
||||||
netmask <%= options[:netmask] %>
|
netmask <%= options[:netmask] %>
|
||||||
<% if options[:gateway] %>
|
<% if options[:gateway] %>
|
||||||
|
|
Loading…
Reference in New Issue