guests/gentoo: Use predictable network interface names
This commit is contained in:
parent
ea9b28f9b6
commit
caafb936f0
|
@ -9,34 +9,47 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
machine.communicate.tap do |comm|
|
||||
# Remove any previous host only network additions to the interface file
|
||||
comm.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces")
|
||||
comm.sudo("cat /tmp/vagrant-network-interfaces > /etc/conf.d/net")
|
||||
comm.sudo("rm -f /tmp/vagrant-network-interfaces")
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
# Remove any previous network additions to the configuration file.
|
||||
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net"
|
||||
|
||||
comm.sudo("ifconfig -a | grep -o ^[0-9a-z]* | grep -v '^lo'") do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
networks.each_with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
# Configure each network interface
|
||||
networks.each do |network|
|
||||
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
|
||||
options: network)
|
||||
options: network,
|
||||
)
|
||||
|
||||
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
||||
|
||||
# Upload the entry to a temporary location
|
||||
Tempfile.open("vagrant-gentoo-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
comm.upload(f.path, "/tmp/vagrant-network-entry")
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
# Configure the interface
|
||||
comm.sudo("ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{network[:interface]}")
|
||||
comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop")
|
||||
comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
|
||||
comm.sudo("rm -f /tmp/vagrant-network-entry")
|
||||
comm.sudo("/etc/init.d/net.eth#{network[:interface]} start")
|
||||
end
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
ln -sf /etc/init.d/net.lo /etc/init.d/net.#{network[:device]}
|
||||
/etc/init.d/net.#{network[:device]} stop || true
|
||||
|
||||
cat '#{remote_path}' >> /etc/conf.d/net
|
||||
rm -f '#{remote_path}'
|
||||
|
||||
/etc/init.d/net.#{network[:device]} start
|
||||
EOH
|
||||
end
|
||||
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
config_eth<%= options[:interface] %>="dhcp"
|
||||
config_<%= options[:device] %>="dhcp"
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
config_eth<%= options[:interface] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>")
|
||||
<% if options[:gateway] %>
|
||||
gateways_eth<%= options[:interface] %>="<%= options[:gateway] %>"
|
||||
<% end %>
|
||||
config_<%= options[:device] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>")
|
||||
<% if options[:gateway] -%>
|
||||
gateways_<%= options[:device] %>="<%= options[:gateway] %>"
|
||||
<% end -%>
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
config_<%= options[:device] %>="<%= options[:ip] %>/<%= options[:netmask] %>"
|
||||
<% if options[:gateway] -%>
|
||||
gateways_<%= options[:device] %>="<%= options[:gateway] %>"
|
||||
<% end -%>
|
||||
#VAGRANT-END
|
Loading…
Reference in New Issue