2016-05-29 03:17:40 +00:00
|
|
|
require_relative "../../../../lib/vagrant/util/template_renderer"
|
|
|
|
require_relative "../../../../lib/vagrant/util/tempfile"
|
2013-04-04 18:56:42 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module GuestFreeBSD
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
2013-04-08 17:47:19 +00:00
|
|
|
include Vagrant::Util
|
2013-04-04 18:56:42 +00:00
|
|
|
|
|
|
|
def self.configure_networks(machine, networks)
|
|
|
|
# Remove any previous network additions to the configuration file.
|
2014-05-22 16:35:12 +00:00
|
|
|
machine.communicate.sudo("sed -i '' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf", {shell: "sh"})
|
2013-04-04 18:56:42 +00:00
|
|
|
|
|
|
|
networks.each do |network|
|
2014-04-11 23:39:58 +00:00
|
|
|
# Determine the interface prefix...
|
|
|
|
command = "ifconfig -a | grep -o ^[0-9a-z]*"
|
|
|
|
result = ""
|
|
|
|
ifname = ""
|
|
|
|
machine.communicate.execute(command) do |type, data|
|
|
|
|
result << data if type == :stdout
|
2014-04-11 23:50:42 +00:00
|
|
|
if result.split(/\n/).any?{|i| i.match(/vtnet*/)}
|
|
|
|
ifname = "vtnet#{network[:interface]}"
|
2014-04-11 23:39:58 +00:00
|
|
|
else
|
|
|
|
ifname = "em#{network[:interface]}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-10 20:43:59 +00:00
|
|
|
entry = TemplateRenderer.render("guests/freebsd/network_#{network[:type]}",
|
2014-08-06 21:10:05 +00:00
|
|
|
options: network, ifname: ifname)
|
2013-04-04 18:56:42 +00:00
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
Tempfile.create("freebsd-configure-networks") do |f|
|
|
|
|
f.write(entry)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
|
|
|
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry")
|
|
|
|
end
|
2013-04-04 18:56:42 +00:00
|
|
|
|
2014-05-22 16:35:12 +00:00
|
|
|
machine.communicate.sudo("su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'", {shell: "sh"})
|
2014-08-29 08:51:31 +00:00
|
|
|
machine.communicate.sudo("rm -f /tmp/vagrant-network-entry", {shell: "sh"})
|
2013-04-04 18:56:42 +00:00
|
|
|
|
2016-03-01 22:28:09 +00:00
|
|
|
# Restart interface so it loads configuration stored in /etc/rc.conf
|
|
|
|
machine.communicate.sudo("service netif restart #{ifname}", {shell: "sh"})
|
2013-04-04 18:56:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|