2015-11-12 13:33:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
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)
|
|
|
|
interfaces = Array.new
|
|
|
|
machine.communicate.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
|
|
|
|
interfaces = result.split("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
networks.each do |network|
|
|
|
|
network[:device] = interfaces[network[:interface]]
|
|
|
|
|
|
|
|
entry = TemplateRenderer.render("guests/slackware/network_#{network[:type]}", options: network)
|
|
|
|
|
2016-05-31 03:17:02 +00:00
|
|
|
Tempfile.open("slackware-configure-networks") do |f|
|
|
|
|
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")
|
|
|
|
end
|
2015-11-12 13:33:04 +00:00
|
|
|
|
|
|
|
machine.communicate.sudo("mv /tmp/vagrant_network /etc/rc.d/rc.inet1.conf")
|
|
|
|
machine.communicate.sudo("/etc/rc.d/rc.inet1")
|
2016-05-29 03:17:40 +00:00
|
|
|
end
|
2015-11-12 13:33:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|