From f4ea1f800c1319c926eff28db59b3eb102e9cf94 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Jan 2012 11:25:40 -0800 Subject: [PATCH] Update Arch guest to the new networks API --- lib/vagrant/guest/arch.rb | 42 ++++++++++++++-------- templates/guests/arch/network_dhcp.erb | 7 ++++ templates/guests/arch/network_hostonly.erb | 7 ---- templates/guests/arch/network_static.erb | 7 ++++ 4 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 templates/guests/arch/network_dhcp.erb delete mode 100644 templates/guests/arch/network_hostonly.erb create mode 100644 templates/guests/arch/network_static.erb diff --git a/lib/vagrant/guest/arch.rb b/lib/vagrant/guest/arch.rb index e0ece0f09..bc9bad649 100644 --- a/lib/vagrant/guest/arch.rb +++ b/lib/vagrant/guest/arch.rb @@ -1,3 +1,6 @@ +require 'set' +require 'tempfile' + module Vagrant module Guest class Arch < Linux @@ -10,23 +13,34 @@ module Vagrant end end - # TODO: Convert these to the new format - def prepare_host_only_network(net_options=nil) - vm.ssh.execute do |ssh| - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/rc.conf > /tmp/vagrant-network-interfaces") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/rc.conf'") + 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") + + # Configure the network interfaces + interfaces = Set.new + entries = [] + networks.each do |network| + interfaces.add(network[:interface]) + entries << TemplateRenderer.render("guests/arch/network_#{network[:type]}", + :options => network) end - end - def enable_host_only_network(net_options) - entry = TemplateRenderer.render('guests/arch/network_hostonly', - :net_options => net_options) - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + # Perform the careful dance necessary to reconfigure + # the network interfaces + temp = Tempfile.new("vagrant") + temp.write(entries.join("\n")) + temp.close - vm.ssh.execute do |ssh| - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'") - ssh.exec!("sudo /etc/rc.d/network restart") - ssh.exec!("sudo su -c 'dhcpcd -k eth0 && dhcpcd eth0 & sleep 3'") + vm.channel.upload(temp.path, "/tmp/vagrant-network-entry") + + # Reconfigure the network interfaces + vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/rc.conf") + vm.channel.sudo("/etc/rc.d/network restart") + + interfaces.each do |interface| + vm.channel.sudo("dhcpcd -k eth#{interface} && dhcpcd eth#{interface} && sleep 3") end end end diff --git a/templates/guests/arch/network_dhcp.erb b/templates/guests/arch/network_dhcp.erb new file mode 100644 index 000000000..1fa0ef702 --- /dev/null +++ b/templates/guests/arch/network_dhcp.erb @@ -0,0 +1,7 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. Do not modify. +interface=eth<%= options[:interface] %> +address= +netmask= +gateway= +#VAGRANT-END diff --git a/templates/guests/arch/network_hostonly.erb b/templates/guests/arch/network_hostonly.erb deleted file mode 100644 index 6208344fb..000000000 --- a/templates/guests/arch/network_hostonly.erb +++ /dev/null @@ -1,7 +0,0 @@ -#VAGRANT-BEGIN-HOSTONLY -# The contents below are automatically generated by Vagrant. Do not modify. -interface=eth<%= net_options[:adapter] %> -address=<%= net_options[:ip]%> -netmask=<%= net_options[:netmask] %> -gateway= -#VAGRANT-END-HOSTONLY diff --git a/templates/guests/arch/network_static.erb b/templates/guests/arch/network_static.erb new file mode 100644 index 000000000..ae65c2877 --- /dev/null +++ b/templates/guests/arch/network_static.erb @@ -0,0 +1,7 @@ +#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