Update Gentoo guest to new networks API

This commit is contained in:
Mitchell Hashimoto 2012-01-17 11:16:02 -08:00
parent 13760e81de
commit 3a2546907e
4 changed files with 30 additions and 21 deletions

View File

@ -1,25 +1,30 @@
require 'tempfile'
module Vagrant module Vagrant
module Guest module Guest
class Gentoo < Linux class Gentoo < Linux
def prepare_host_only_network(net_options=nil) def configure_networks(networks)
# Remove any previous host only network additions to the # Remove any previous host only network additions to the interface file
# interface file. vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces")
vm.ssh.execute do |ssh| vm.channel.sudo("cat /tmp/vagrant-network-interfaces > /etc/conf.d/net")
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 enable_host_only_network(net_options) # Configure each network interface
entry = TemplateRenderer.render('guests/gentoo/network_hostonly', networks.each do |network|
:net_options => net_options) entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") :options => network)
vm.ssh.execute do |ssh| # Upload the entry to a temporary location
ssh.exec!("sudo ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{net_options[:adapter]}") temp = Tempfile.new("vagrant")
ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} stop 2> /dev/null") temp.write(entry)
ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/conf.d/net'") temp.close
ssh.exec!("sudo /etc/init.d/net.eth#{net_options[:adapter]} start")
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 end
end end

View File

@ -0,0 +1,4 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_eth<%= options[:interface] %>="dhcp"
#VAGRANT-END

View File

@ -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

View File

@ -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