This fixes a fairly large tempfile leak. Vagrant uses a template renderer to write network configuration files locally to disk. Then, that temporarily file is uploaded to the remote host and moved into place. Since Vagrant is such a short-lived process, GC never came along and cleaned up those tempfiles, resulting in many temporary files being created through regular Vagrant usage. The Util::Tempfile class uses a block to ensure the temporary file is deleted when the block finishes. This API required small tweaks to the usage, but provides more safety to ensure the files are deleted.
46 lines
1.8 KiB
Ruby
46 lines
1.8 KiB
Ruby
require_relative "../../../../lib/vagrant/util/template_renderer"
|
|
require_relative "../../../../lib/vagrant/util/tempfile"
|
|
|
|
module VagrantPlugins
|
|
module GuestFuntoo
|
|
module Cap
|
|
class ConfigureNetworks
|
|
include Vagrant::Util
|
|
|
|
def self.configure_networks(machine, networks)
|
|
machine.communicate.tap do |comm|
|
|
# Configure each network interface
|
|
networks.each do |network|
|
|
# http://www.funtoo.org/Funtoo_Linux_Networking
|
|
# dhcpcd generally runs on all interfaces by default
|
|
# in the future we can change this, dhcpcd has lots of features
|
|
# it would be nice to expose more of its capabilities...
|
|
if not /dhcp/i.match(network[:type])
|
|
line = "denyinterfaces eth#{network[:interface]}"
|
|
cmd = "grep '#{line}' /etc/dhcpcd.conf; if [ $? -ne 0 ]; then echo '#{line}' >> /etc/dhcpcd.conf ; fi"
|
|
comm.sudo(cmd)
|
|
ifFile = "netif.eth#{network[:interface]}"
|
|
entry = TemplateRenderer.render("guests/funtoo/network_#{network[:type]}",
|
|
options: network)
|
|
|
|
# Upload the entry to a temporary location
|
|
Tempfile.create("funtoo-configure-networks") do |f|
|
|
f.write(entry)
|
|
f.fsync
|
|
f.close
|
|
comm.upload(f.path, "/tmp/vagrant-#{ifFile}")
|
|
end
|
|
|
|
comm.sudo("cp /tmp/vagrant-#{ifFile} /etc/conf.d/#{ifFile}")
|
|
comm.sudo("chmod 0644 /etc/conf.d/#{ifFile}")
|
|
comm.sudo("ln -fs /etc/init.d/netif.tmpl /etc/init.d/#{ifFile}")
|
|
comm.sudo("/etc/init.d/#{ifFile} start")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|