2012-01-17 19:16:02 +00:00
|
|
|
require 'tempfile'
|
|
|
|
|
2012-05-23 22:57:43 +00:00
|
|
|
require "vagrant"
|
2012-02-11 02:14:51 +00:00
|
|
|
require 'vagrant/util/template_renderer'
|
|
|
|
|
2012-05-23 22:57:43 +00:00
|
|
|
require Vagrant.source_root.join("plugins/guests/linux/guest")
|
|
|
|
|
2012-04-19 04:23:25 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestGentoo
|
|
|
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
2012-02-11 02:14:51 +00:00
|
|
|
# Make the TemplateRenderer top-level
|
|
|
|
include Vagrant::Util
|
|
|
|
|
2012-01-17 19:16:02 +00:00
|
|
|
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")
|
2012-04-02 07:33:54 +00:00
|
|
|
vm.channel.sudo("rm /tmp/vagrant-network-interfaces")
|
2012-01-17 19:16:02 +00:00
|
|
|
|
|
|
|
# Configure each network interface
|
|
|
|
networks.each do |network|
|
|
|
|
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
|
|
|
|
:options => network)
|
|
|
|
|
|
|
|
# Upload the entry to a temporary location
|
|
|
|
temp = Tempfile.new("vagrant")
|
2012-02-11 18:36:27 +00:00
|
|
|
temp.binmode
|
2012-01-17 19:16:02 +00:00
|
|
|
temp.write(entry)
|
|
|
|
temp.close
|
2011-01-09 21:12:57 +00:00
|
|
|
|
2012-01-17 19:16:02 +00:00
|
|
|
vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")
|
2010-12-08 20:30:51 +00:00
|
|
|
|
2012-01-17 19:16:02 +00:00
|
|
|
# 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")
|
2012-04-02 07:33:54 +00:00
|
|
|
vm.channel.sudo("rm /tmp/vagrant-network-entry")
|
2012-01-17 19:16:02 +00:00
|
|
|
vm.channel.sudo("/etc/init.d/net.eth#{network[:interface]} start")
|
2010-12-08 20:30:51 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-01 12:57:44 +00:00
|
|
|
|
|
|
|
def change_host_name(name)
|
|
|
|
if !vm.channel.test("sudo hostname --fqdn | grep '#{name}'")
|
|
|
|
vm.channel.sudo("echo 'hostname=#{name.split('.')[0]}' > /etc/conf.d/hostname")
|
2012-05-14 15:16:41 +00:00
|
|
|
vm.channel.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
2012-03-01 12:57:44 +00:00
|
|
|
vm.channel.sudo("hostname #{name.split('.')[0]}")
|
|
|
|
end
|
|
|
|
end
|
2010-12-08 20:30:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|