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"
|
2015-11-12 13:33:04 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module GuestSlackware
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
|
|
|
include Vagrant::Util
|
|
|
|
|
|
|
|
def self.configure_networks(machine, networks)
|
2016-06-05 23:55:36 +00:00
|
|
|
comm = machine.communicate
|
|
|
|
|
|
|
|
commands = []
|
2016-06-23 02:08:02 +00:00
|
|
|
interfaces = machine.guest.capability(:network_interfaces)
|
2015-11-12 13:33:04 +00:00
|
|
|
|
2016-06-05 23:55:36 +00:00
|
|
|
# Remove any previous configuration
|
|
|
|
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.d/rc.inet1.conf"
|
|
|
|
|
|
|
|
networks.each.with_index do |network, i|
|
2015-11-12 13:33:04 +00:00
|
|
|
network[:device] = interfaces[network[:interface]]
|
|
|
|
|
2016-06-05 23:55:36 +00:00
|
|
|
entry = TemplateRenderer.render("guests/slackware/network_#{network[:type]}",
|
|
|
|
i: i+1,
|
|
|
|
options: network,
|
|
|
|
)
|
2015-11-12 13:33:04 +00:00
|
|
|
|
2016-06-05 23:55:36 +00:00
|
|
|
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now}-#{i}"
|
2016-05-31 04:18:16 +00:00
|
|
|
Tempfile.open("vagrant-slackware-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
|
2016-06-05 23:55:36 +00:00
|
|
|
comm.upload(f.path, remote_path)
|
2016-05-29 03:17:40 +00:00
|
|
|
end
|
2015-11-12 13:33:04 +00:00
|
|
|
|
2016-06-05 23:55:36 +00:00
|
|
|
commands << "cat '#{remote_path}' >> /etc/rc.d/rc.inet1.conf"
|
2016-05-29 03:17:40 +00:00
|
|
|
end
|
2016-06-05 23:55:36 +00:00
|
|
|
|
|
|
|
# Restart networking
|
|
|
|
commands << "/etc/rc.d/rc.inet1"
|
|
|
|
|
|
|
|
comm.sudo(commands.join("\n"))
|
2015-11-12 13:33:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|