Skip to content

Commit

Permalink
Fix multiple ethernet interface support on Arch Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Monteiro authored and mitchellh committed Jun 1, 2012
1 parent 48ed18a commit 5bbabaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
35 changes: 8 additions & 27 deletions plugins/guests/arch/guest.rb
Expand Up @@ -22,38 +22,19 @@ def change_host_name(name)
end

def configure_networks(networks)
# Remove previous Vagrant-managed network interfaces
vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces")
vm.channel.sudo("cat /tmp/vagrant-network-interfaces > /etc/rc.conf")
vm.channel.sudo("rm /tmp/vagrant-network-interfaces")

# Configure the network interfaces
interfaces = Set.new
entries = []
networks.each do |network|
interfaces.add(network[:interface])
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
:options => network)

entries << entry
end

# Perform the careful dance necessary to reconfigure
# the network interfaces
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entries.join("\n"))
temp.close

vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}", :options => network)

# Reconfigure the network interfaces
vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/rc.conf")
vm.channel.sudo("rm /tmp/vagrant-network-entry")
vm.channel.sudo("/etc/rc.d/network restart")
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entry)
temp.close

interfaces.each do |interface|
vm.channel.sudo("dhcpcd -k eth#{interface} && dhcpcd eth#{interface} && sleep 3")
vm.channel.upload(temp.path, temp.path)
vm.channel.sudo("mv #{temp.path} /etc/network.d/interfaces/eth#{network[:interface]}")
vm.channel.sudo("netcfg interfaces/eth#{interface}")
end
end
end
Expand Down
11 changes: 4 additions & 7 deletions templates/guests/arch/network_dhcp.erb
@@ -1,7 +1,4 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
interface=eth<%= options[:interface] %>
address=
netmask=
gateway=
#VAGRANT-END
CONNECTION='ethernet'
DESCRIPTION='A basic dhcp ethernet connection'
INTERFACE='eth<%= options[:interface] %>'
IP='dhcp'
13 changes: 6 additions & 7 deletions templates/guests/arch/network_static.erb
@@ -1,7 +1,6 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
interface=eth<%= options[:interface] %>
address=<%= options[:ip]%>
netmask=<%= options[:netmask] %>
gateway=
#VAGRANT-END
CONNECTION='ethernet'
DESCRIPTION='A basic static ethernet connection'
INTERFACE='eth<%= options[:interface] %>'
IP='static'
ADDR='<%= options[:ip]%>'
NETMASK='<%= options[:netmask] %>'

0 comments on commit 5bbabaf

Please sign in to comment.