diff --git a/lib/vagrant/guest/gentoo.rb b/lib/vagrant/guest/gentoo.rb index 69d11bf89..a5af9abb0 100644 --- a/lib/vagrant/guest/gentoo.rb +++ b/lib/vagrant/guest/gentoo.rb @@ -1,25 +1,30 @@ +require 'tempfile' + module Vagrant module Guest class Gentoo < Linux - def prepare_host_only_network(net_options=nil) - # Remove any previous host only network additions to the - # interface file. - vm.ssh.execute do |ssh| - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN-HOSTONLY/,/^#VAGRANT-END-HOSTONLY/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/conf.d/net'") - end - end + def configure_networks(networks) + # Remove any previous host only network additions to the interface file + vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces") + vm.channel.sudo("cat /tmp/vagrant-network-interfaces > /etc/conf.d/net") - def enable_host_only_network(net_options) - entry = TemplateRenderer.render('guests/gentoo/network_hostonly', - :net_options => net_options) - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + # Configure each network interface + networks.each do |network| + entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}", + :options => network) - vm.ssh.execute do |ssh| - ssh.exec!("sudo ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{net_options[:adapter]}") - ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} stop 2> /dev/null") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/conf.d/net'") - ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} start") + # Upload the entry to a temporary location + temp = Tempfile.new("vagrant") + temp.write(entry) + temp.close + + vm.channel.upload(temp.path, "/tmp/vagrant-network-entry") + + # Configure the interface + vm.channel.sudo("ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{network[:interface]}") + vm.channel.sudo("/etc/init.d/net.eth#{network[:interface]} stop 2> /dev/null") + vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net") + vm.channel.sudo("/etc/init.d/net.eth#{network[:interface]} start") end end end diff --git a/templates/guests/gentoo/network_dhcp.erb b/templates/guests/gentoo/network_dhcp.erb new file mode 100644 index 000000000..df1092987 --- /dev/null +++ b/templates/guests/gentoo/network_dhcp.erb @@ -0,0 +1,4 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. Do not modify. +config_eth<%= options[:interface] %>="dhcp" +#VAGRANT-END diff --git a/templates/guests/gentoo/network_hostonly.erb b/templates/guests/gentoo/network_hostonly.erb deleted file mode 100644 index 19ebaaf2e..000000000 --- a/templates/guests/gentoo/network_hostonly.erb +++ /dev/null @@ -1,4 +0,0 @@ -#VAGRANT-BEGIN-HOSTONLY -# The contents below are automatically generated by Vagrant. Do not modify. -config_eth<%= net_options[:adapter] %>=("<%= net_options[:ip] %> netmask <%= net_options[:netmask] %>") -#VAGRANT-END-HOSTONLY diff --git a/templates/guests/gentoo/network_static.erb b/templates/guests/gentoo/network_static.erb new file mode 100644 index 000000000..0df432cb0 --- /dev/null +++ b/templates/guests/gentoo/network_static.erb @@ -0,0 +1,4 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. Do not modify. +config_eth<%= options[:interface] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>") +#VAGRANT-END