2016-05-31 03:17:02 +00:00
|
|
|
require "tempfile"
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
require_relative "../../../../lib/vagrant/util/template_renderer"
|
2013-08-28 04:12:09 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module GuestOpenBSD
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
|
|
|
include Vagrant::Util
|
|
|
|
|
|
|
|
def self.configure_networks(machine, networks)
|
|
|
|
networks.each do |network|
|
|
|
|
entry = TemplateRenderer.render("guests/openbsd/network_#{network[:type]}",
|
2014-05-22 16:35:12 +00:00
|
|
|
options: network)
|
2013-08-28 04:12:09 +00:00
|
|
|
|
2016-05-31 04:18:16 +00:00
|
|
|
Tempfile.open("vagrant-openbsd-configure-networks") do |f|
|
2016-05-31 03:17:02 +00:00
|
|
|
f.binmode
|
2016-05-29 03:17:40 +00:00
|
|
|
f.write(entry)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
|
|
|
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry")
|
|
|
|
end
|
2013-08-28 04:12:09 +00:00
|
|
|
|
2014-04-11 23:39:58 +00:00
|
|
|
# Determine the interface prefix...
|
2014-03-08 12:06:32 +00:00
|
|
|
command = "ifconfig -a | grep -o ^[0-9a-z]*"
|
|
|
|
result = ""
|
|
|
|
ifname = ""
|
|
|
|
machine.communicate.execute(command) do |type, data|
|
|
|
|
result << data if type == :stdout
|
|
|
|
if result.split(/\n/).any?{|i| i.match(/vio*/)}
|
|
|
|
ifname = "vio#{network[:interface]}"
|
|
|
|
else
|
|
|
|
ifname = "em#{network[:interface]}"
|
|
|
|
end
|
|
|
|
end
|
2014-04-11 23:39:58 +00:00
|
|
|
|
2013-08-28 04:12:09 +00:00
|
|
|
machine.communicate.sudo("mv /tmp/vagrant-network-entry /etc/hostname.#{ifname}")
|
|
|
|
|
2017-12-13 09:34:17 +00:00
|
|
|
# apply new configurations
|
|
|
|
machine.communicate.sudo("sh /etc/netstart #{ifname}")
|
2013-08-28 04:12:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|