2012-01-03 03:40:19 +00:00
|
|
|
require 'set'
|
2012-01-07 05:42:25 +00:00
|
|
|
require 'tempfile'
|
2012-01-03 03:40:19 +00:00
|
|
|
|
|
|
|
require 'vagrant/util/template_renderer'
|
|
|
|
|
2012-04-19 04:23:25 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestDebian
|
|
|
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
2012-01-03 03:40:19 +00:00
|
|
|
# Make the TemplateRenderer top-level
|
|
|
|
include Vagrant::Util
|
2011-01-09 21:19:50 +00:00
|
|
|
|
2012-01-03 03:40:19 +00:00
|
|
|
def configure_networks(networks)
|
|
|
|
# First, remove any previous network modifications
|
|
|
|
# from the interface file.
|
2012-01-07 04:03:56 +00:00
|
|
|
vm.channel.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
|
|
|
|
vm.channel.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'")
|
2012-04-02 07:33:54 +00:00
|
|
|
vm.channel.sudo("rm /tmp/vagrant-network-interfaces")
|
2011-12-31 19:53:04 +00:00
|
|
|
|
2012-01-03 03:40:19 +00:00
|
|
|
# Accumulate the configurations to add to the interfaces file as
|
|
|
|
# well as what interfaces we're actually configuring since we use that
|
|
|
|
# later.
|
|
|
|
interfaces = Set.new
|
|
|
|
entries = []
|
|
|
|
networks.each do |network|
|
|
|
|
interfaces.add(network[:interface])
|
2012-02-11 02:14:51 +00:00
|
|
|
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
|
|
|
|
:options => network)
|
|
|
|
|
|
|
|
entries << entry
|
2012-01-03 03:40:19 +00:00
|
|
|
end
|
2011-12-31 19:53:04 +00:00
|
|
|
|
2012-01-05 05:43:14 +00:00
|
|
|
# Perform the careful dance necessary to reconfigure
|
2012-01-03 03:40:19 +00:00
|
|
|
# the network interfaces
|
2012-01-07 05:42:25 +00:00
|
|
|
temp = Tempfile.new("vagrant")
|
2012-02-11 18:36:27 +00:00
|
|
|
temp.binmode
|
2012-01-07 05:42:25 +00:00
|
|
|
temp.write(entries.join("\n"))
|
|
|
|
temp.close
|
|
|
|
|
|
|
|
vm.channel.upload(temp.path, "/tmp/vagrant-network-entry")
|
2012-01-07 04:03:56 +00:00
|
|
|
|
|
|
|
# Bring down all the interfaces we're reconfiguring. By bringing down
|
|
|
|
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
|
|
|
# SSH never dies.
|
|
|
|
interfaces.each do |interface|
|
2012-01-20 01:36:29 +00:00
|
|
|
vm.channel.sudo("/sbin/ifdown eth#{interface} 2> /dev/null")
|
2012-01-07 04:03:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
vm.channel.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces")
|
2012-04-02 07:33:54 +00:00
|
|
|
vm.channel.sudo("rm /tmp/vagrant-network-entry")
|
2012-01-07 04:03:56 +00:00
|
|
|
|
|
|
|
# Bring back up each network interface, reconfigured
|
|
|
|
interfaces.each do |interface|
|
|
|
|
vm.channel.sudo("/sbin/ifup eth#{interface}")
|
2011-12-31 19:53:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-14 17:51:19 +00:00
|
|
|
def change_host_name(name)
|
2012-01-17 22:43:32 +00:00
|
|
|
if !vm.channel.test("hostname --fqdn | grep '^#{name}$' || hostname --short | grep '^#{name}$'")
|
2012-01-14 01:08:03 +00:00
|
|
|
vm.channel.sudo("sed -r -i 's/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1#{name} #{name.split('.')[0]}/' /etc/hosts")
|
|
|
|
vm.channel.sudo("sed -i 's/.*$/#{name.split('.')[0]}/' /etc/hostname")
|
2012-01-07 04:03:56 +00:00
|
|
|
vm.channel.sudo("hostname -F /etc/hostname")
|
2011-01-14 17:51:19 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-09 21:19:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|