Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new 'predictable' network interface naming style #7241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions plugins/guests/debian/cap/configure_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ def self.configure_networks(machine, networks)
comm.sudo("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre")
comm.sudo("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tac | sed -e '/^#VAGRANT-END/,$ d' | tac > /tmp/vagrant-network-interfaces.post")

kernel_ifnames = []
comm.sudo("/usr/bin/find /sys/class/net -type l -print | sort") do |type, data|
if type == :stdout then
data.split("\n").each do |line|
if (line =~ /^\/sys\/class\/net\/(enp[0-9]+s[0-9]+|eth[0-9]+)$/) then
kernel_ifnames << $1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is technically correct. My systemd based machine (though not Ubuntu) has an ethernet adapter named enp0s31f6. This wouldn't be caught by this RE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only be for debian-based guests... is your machine running a Debian derivative, or something else (e.g. RHEL)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debian GNU/Linux stretch/sid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name format appears to be described in systemd's udev-builtin-net_id.c

end
end
end
end

# Accumulate the configurations to add to the interfaces file as
# well as what interfaces we're actually configuring since we use that
# later.
Expand All @@ -24,7 +35,7 @@ def self.configure_networks(machine, networks)
networks.each do |network|
interfaces.add(network[:interface])
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
options: network)
options: network, kernel_ifnames: kernel_ifnames)

entries << entry
end
Expand All @@ -45,16 +56,16 @@ def self.configure_networks(machine, networks)
# Ubuntu 16.04+ returns an error when downing an interface that
# does not exist. The `|| true` preserves the behavior that older
# Ubuntu versions exhibit and Vagrant expects (GH-7155)
comm.sudo("/sbin/ifdown eth#{interface} 2> /dev/null || true")
comm.sudo("/sbin/ip addr flush dev eth#{interface} 2> /dev/null")
comm.sudo("/sbin/ifdown #{kernel_ifnames[interface]} 2> /dev/null || true")
comm.sudo("/sbin/ip addr flush dev #{kernel_ifnames[interface]} 2> /dev/null")
end

comm.sudo('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces')
comm.sudo('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post')

# Bring back up each network interface, reconfigured
interfaces.each do |interface|
comm.sudo("/sbin/ifup eth#{interface}")
comm.sudo("/sbin/ifup #{kernel_ifnames[interface]}")
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions templates/guests/debian/network_dhcp.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth<%= options[:interface] %>
iface eth<%= options[:interface] %> inet dhcp
auto <%= kernel_ifnames[options[:interface]] %>
iface <%= kernel_ifnames[options[:interface]] %> inet dhcp
<% if !options[:use_dhcp_assigned_default_route] %>
post-up route del default dev $IFACE || true
<% else %>
# We need to disable eth0, see GH-2648
post-up route del default dev eth0 || true
# We need to disable <%= kernel_ifnames[0] %>, see GH-2648
post-up route del default dev <%= kernel_ifnames[0] %> || true
post-up dhclient $IFACE
pre-down route add default dev eth0
pre-down route add default dev <%= kernel_ifnames[0] %>
<% end %>
#VAGRANT-END
4 changes: 2 additions & 2 deletions templates/guests/debian/network_static.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth<%= options[:interface] %>
iface eth<%= options[:interface] %> inet static
auto <%= kernel_ifnames[options[:interface]] %>
iface <%= kernel_ifnames[options[:interface]] %> inet static
address <%= options[:ip] %>
netmask <%= options[:netmask] %>
<% if options[:gateway] %>
Expand Down
4 changes: 2 additions & 2 deletions templates/guests/debian/network_static6.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth<%= options[:interface] %>
iface eth<%= options[:interface] %> inet6 static
auto <%= kernel_ifnames[options[:interface]] %>
iface <%= kernel_ifnames[options[:interface]] %> inet6 static
address <%= options[:ip] %>
netmask <%= options[:netmask] %>
<% if options[:gateway] %>
Expand Down