Merge pull request #7393 from mitchellh/sethvargo/guest_caps
Update guest capabilities
This commit is contained in:
commit
b98c134a49
|
@ -3,12 +3,21 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
# Only do this if the hostname is not already set
|
||||
if !comm.test("sudo hostname | grep '#{name}'")
|
||||
comm.sudo("hostnamectl set-hostname #{name}")
|
||||
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH
|
||||
hostnamectl set-hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
|
@ -10,32 +9,45 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
tempfiles = []
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
machine.communicate.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
|
||||
interfaces = result.split("\n")
|
||||
# The result will be something like:
|
||||
# eth0\nenp0s8\nenp0s9
|
||||
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
networks.each.with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
||||
options: network)
|
||||
options: network,
|
||||
)
|
||||
|
||||
remote_path = "/tmp/vagrant-network-#{Time.now.to_i}-#{i}"
|
||||
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
||||
|
||||
Tempfile.open("vagrant-arch-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
machine.communicate.upload(f.path, remote_path)
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
machine.communicate.sudo("mv #{remote_path} /etc/netctl/#{network[:device]}")
|
||||
machine.communicate.sudo("ip link set #{network[:device]} down && netctl restart #{network[:device]} && netctl enable #{network[:device]}")
|
||||
end
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
# Configure #{network[:device]}
|
||||
mv '#{remote_path}' '/etc/netctl/#{network[:device]}'
|
||||
ip link set '#{network[:device]}' down
|
||||
netctl restart '#{network[:device]}'
|
||||
netctl enable '#{network[:device]}'
|
||||
EOH
|
||||
end
|
||||
|
||||
# Run all the network modification commands in one communicator call.
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Arch guest support."
|
||||
|
||||
guest("arch", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,22 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.sudo("hostnamectl set-hostname #{name}")
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH
|
||||
hostnamectl set-hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'vagrant'
|
||||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestAtomic
|
||||
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Atomic Host guest support."
|
||||
|
||||
guest("atomic", "fedora") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,10 +3,16 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
if !comm.test("sudo hostname --fqdn | grep '#{name}'")
|
||||
comm.sudo("hostname #{name.split('.')[0]}")
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname --fqdn | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo("hostname '#{basename}'")
|
||||
|
||||
# Note that when working with CoreOS, we explicitly do not add the
|
||||
# entry to /etc/hosts because this file does not exist on CoreOS.
|
||||
# We could create it, but the recommended approach on CoreOS is to
|
||||
# use Fleet to manage /etc/hosts files.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,47 +10,26 @@ module VagrantPlugins
|
|||
|
||||
def self.configure_networks(machine, networks)
|
||||
machine.communicate.tap do |comm|
|
||||
# Disable default etcd
|
||||
comm.sudo("systemctl stop etcd")
|
||||
|
||||
# Read network interface names
|
||||
interfaces = []
|
||||
comm.sudo("ifconfig | grep '(e[n,t][h,s,p][[:digit:]]([a-z][[:digit:]])?' | cut -f1 -d:") do |_, result|
|
||||
interfaces = result.split("\n")
|
||||
end
|
||||
|
||||
# Configure interfaces
|
||||
# FIXME: fix matching of interfaces with IP adresses
|
||||
networks.each do |network|
|
||||
comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}")
|
||||
end
|
||||
|
||||
primary_machine_config = machine.env.active_machines.first
|
||||
primary_machine = machine.env.machine(*primary_machine_config, true)
|
||||
|
||||
get_ip = lambda do |machine|
|
||||
ip = nil
|
||||
machine.config.vm.networks.each do |type, opts|
|
||||
if type == :private_network && opts[:ip]
|
||||
ip = opts[:ip]
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
ip
|
||||
end
|
||||
|
||||
primary_machine_ip = get_ip.(primary_machine)
|
||||
current_ip = get_ip.(machine)
|
||||
primary_machine_ip = get_ip(primary_machine)
|
||||
current_ip = get_ip(machine)
|
||||
if current_ip == primary_machine_ip
|
||||
entry = TemplateRenderer.render("guests/coreos/etcd.service", options: {
|
||||
my_ip: current_ip
|
||||
my_ip: current_ip,
|
||||
})
|
||||
else
|
||||
connection_string = "#{primary_machine_ip}:7001"
|
||||
entry = TemplateRenderer.render("guests/coreos/etcd.service", options: {
|
||||
connection_string: connection_string,
|
||||
my_ip: current_ip
|
||||
my_ip: current_ip,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -62,12 +41,44 @@ module VagrantPlugins
|
|||
comm.upload(f.path, "/tmp/etcd-cluster.service")
|
||||
end
|
||||
|
||||
comm.sudo("mv /tmp/etcd-cluster.service /media/state/units/")
|
||||
comm.sudo("systemctl restart local-enable.service")
|
||||
# Build a list of commands
|
||||
commands = []
|
||||
|
||||
# Stop default systemd
|
||||
commands << "systemctl stop etcd"
|
||||
|
||||
# Configure interfaces
|
||||
# FIXME: fix matching of interfaces with IP adresses
|
||||
networks.each do |network|
|
||||
iface = interfaces[network[:interface].to_i]
|
||||
commands << "ifconfig #{iface} #{network[:ip]} netmask #{network[:netmask]}".squeeze(" ")
|
||||
end
|
||||
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
mv /tmp/etcd-cluster.service /media/state/units/
|
||||
systemctl restart local-enable.service
|
||||
|
||||
# Restart default etcd
|
||||
comm.sudo("systemctl start etcd")
|
||||
end
|
||||
systemctl start etcd
|
||||
EOH
|
||||
|
||||
# Run all network configuration commands in one communicator session.
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.get_ip(machine)
|
||||
ip = nil
|
||||
machine.config.vm.networks.each do |type, opts|
|
||||
if type == :private_network && opts[:ip]
|
||||
ip = opts[:ip]
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
ip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestCoreOS
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "CoreOS guest support."
|
||||
|
||||
guest("coreos", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,13 +3,31 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
if !machine.communicate.test("hostname -f | grep '^#{name}$' || hostname -s | grep '^#{name}$'")
|
||||
machine.communicate.sudo("scutil --set ComputerName #{name}")
|
||||
machine.communicate.sudo("scutil --set HostName #{name}")
|
||||
# LocalHostName shouldn't contain dots.
|
||||
# It is used by Bonjour and visible through file sharing services.
|
||||
machine.communicate.sudo("scutil --set LocalHostName #{name.gsub(/\.+/, '')}")
|
||||
machine.communicate.sudo("hostname #{name}")
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
scutil --set ComputerName '#{name}'
|
||||
scutil --set HostName '#{name}'
|
||||
|
||||
# LocalHostName should not contain dots - it is used by Bonjour and
|
||||
# visible through file sharing services.
|
||||
scutil --set LocalHostName '#{basename}'
|
||||
|
||||
hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' /etc/hosts
|
||||
sed -i'' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts - sed on bsd is sad
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
|
||||
mv /tmp/tmp-hosts /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,16 +3,16 @@ module VagrantPlugins
|
|||
module Cap
|
||||
module ChooseAddressableIPAddr
|
||||
def self.choose_addressable_ip_addr(machine, possible)
|
||||
machine.communicate.tap do |comm|
|
||||
comm = machine.communicate
|
||||
|
||||
possible.each do |ip|
|
||||
command = "ping -c1 -t1 #{ip}"
|
||||
if comm.test(command)
|
||||
if comm.test("ping -c1 -t1 #{ip}")
|
||||
return ip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
# If we got this far, there are no addressable IPs
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,31 @@
|
|||
require "vagrant/util/shell_quote"
|
||||
require "tempfile"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestDarwin
|
||||
module Cap
|
||||
class InsertPublicKey
|
||||
def self.insert_public_key(machine, contents)
|
||||
comm = machine.communicate
|
||||
contents = contents.chomp
|
||||
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p ~/.ssh")
|
||||
comm.execute("chmod 0700 ~/.ssh")
|
||||
comm.execute("printf '#{contents}\\n' >> ~/.ssh/authorized_keys")
|
||||
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
|
||||
end
|
||||
remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}"
|
||||
Tempfile.open("vagrant-darwin-insert-public-key") do |f|
|
||||
f.binmode
|
||||
f.write(contents)
|
||||
f.fsync
|
||||
f.close
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
comm.execute <<-EOH.gsub(/^ {12}/, '')
|
||||
mkdir -p ~/.ssh
|
||||
chmod 0700 ~/.ssh
|
||||
cat '#{remote_path}' >> ~/.ssh/authorized_keys
|
||||
chmod 0600 ~/.ssh/authorized_keys
|
||||
|
||||
# Remove the temporary file
|
||||
rm -f '#{remote_path}'
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'vagrant/util/template_renderer'
|
||||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestDarwin
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Darwin guest support."
|
||||
|
||||
guest("darwin") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -2,92 +2,45 @@ module VagrantPlugins
|
|||
module GuestDebian
|
||||
module Cap
|
||||
class ChangeHostName
|
||||
# For more information, please see:
|
||||
#
|
||||
# https://wiki.debian.org/HowTo/ChangeHostname
|
||||
#
|
||||
def self.change_host_name(machine, name)
|
||||
new(machine, name).change!
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
attr_reader :machine, :new_hostname
|
||||
if !comm.test("hostname -f | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set the hostname
|
||||
echo '#{name}' > /etc/hostname
|
||||
hostname -F /etc/hostname
|
||||
|
||||
def initialize(machine, new_hostname)
|
||||
@machine = machine
|
||||
@new_hostname = new_hostname
|
||||
end
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
def change!
|
||||
return unless should_change?
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
|
||||
update_etc_hostname
|
||||
update_etc_hosts
|
||||
refresh_hostname_service
|
||||
update_mailname
|
||||
renew_dhcp
|
||||
end
|
||||
# Update mailname
|
||||
echo '#{name}' > /etc/mailname
|
||||
|
||||
def should_change?
|
||||
new_hostname != current_hostname
|
||||
end
|
||||
# Restart networking and force new DHCP
|
||||
if [ test -f /etc/init.d/hostname.sh ]; then
|
||||
invoke-rc.d hostname.sh start
|
||||
fi
|
||||
|
||||
def current_hostname
|
||||
@current_hostname ||= get_current_hostname
|
||||
end
|
||||
if [ test -f /etc/init.d/networking ]; then
|
||||
invoke-rc.d networking force-reload
|
||||
fi
|
||||
|
||||
def get_current_hostname
|
||||
hostname = ""
|
||||
sudo "hostname -f" do |type, data|
|
||||
hostname = data.chomp if type == :stdout && hostname.empty?
|
||||
end
|
||||
|
||||
hostname
|
||||
end
|
||||
|
||||
def update_etc_hostname
|
||||
sudo("echo '#{short_hostname}' > /etc/hostname")
|
||||
end
|
||||
|
||||
# /etc/hosts should resemble:
|
||||
# 127.0.0.1 localhost
|
||||
# 127.0.1.1 host.fqdn.com host.fqdn host
|
||||
def update_etc_hosts
|
||||
if test("grep '#{current_hostname}' /etc/hosts")
|
||||
# Current hostname entry is in /etc/hosts
|
||||
ip_address = '([0-9]{1,3}\.){3}[0-9]{1,3}'
|
||||
search = "^(#{ip_address})\\s+#{Regexp.escape(current_hostname)}(\\s.*)?$"
|
||||
replace = "\\1 #{fqdn} #{short_hostname}"
|
||||
expression = ['s', search, replace, 'g'].join('@')
|
||||
|
||||
sudo("sed -ri '#{expression}' /etc/hosts")
|
||||
else
|
||||
# Current hostname entry isn't in /etc/hosts, just append it
|
||||
sudo("echo '127.0.1.1 #{fqdn} #{short_hostname}' >>/etc/hosts")
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_hostname_service
|
||||
sudo("hostname -F /etc/hostname")
|
||||
end
|
||||
|
||||
def update_mailname
|
||||
sudo("hostname --fqdn > /etc/mailname")
|
||||
end
|
||||
|
||||
def renew_dhcp
|
||||
sudo("ifdown -a; ifup -a; ifup eth0")
|
||||
end
|
||||
|
||||
def fqdn
|
||||
new_hostname
|
||||
end
|
||||
|
||||
def short_hostname
|
||||
new_hostname.split('.').first
|
||||
end
|
||||
|
||||
def sudo(cmd, &block)
|
||||
machine.communicate.sudo(cmd, &block)
|
||||
end
|
||||
|
||||
def test(cmd)
|
||||
machine.communicate.test(cmd)
|
||||
if [ test -f /etc/init.d/network-manager ]; then
|
||||
invoke-rc.d network-manager force-reload
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "set"
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
|
@ -10,27 +9,25 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
machine.communicate.tap do |comm|
|
||||
# First, remove any previous network modifications
|
||||
# from the interface file.
|
||||
comm.sudo("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre")
|
||||
comm.sudo("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tac | sed -e '/^#VAGRANT-END/,$ d' | tac > /tmp/vagrant-network-interfaces.post")
|
||||
comm = machine.communicate
|
||||
|
||||
# Accumulate the configurations to add to the interfaces file as
|
||||
# well as what interfaces we're actually configuring since we use that
|
||||
# later.
|
||||
interfaces = Set.new
|
||||
commands = []
|
||||
entries = []
|
||||
networks.each do |network|
|
||||
interfaces.add(network[:interface])
|
||||
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
|
||||
options: network)
|
||||
interfaces = []
|
||||
|
||||
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
networks.each do |network|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
entry = TemplateRenderer.render("guests/debian/network_#{network[:type]}",
|
||||
options: network,
|
||||
)
|
||||
entries << entry
|
||||
end
|
||||
|
||||
# Perform the careful dance necessary to reconfigure the network
|
||||
# interfaces.
|
||||
Tempfile.open("vagrant-debian-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entries.join("\n"))
|
||||
|
@ -39,25 +36,39 @@ module VagrantPlugins
|
|||
comm.upload(f.path, "/tmp/vagrant-network-entry")
|
||||
end
|
||||
|
||||
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||
# SSH never dies.
|
||||
interfaces.each do |interface|
|
||||
networks.each do |network|
|
||||
# Ubuntu 16.04+ returns an error when downing an interface that
|
||||
# does not exist. The `|| true` preserves the behavior that older
|
||||
# Ubuntu versions exhibit and Vagrant expects (GH-7155)
|
||||
comm.sudo("/sbin/ifdown eth#{interface} 2> /dev/null || true")
|
||||
comm.sudo("/sbin/ip addr flush dev eth#{interface} 2> /dev/null")
|
||||
commands << "/sbin/ifdown '#{network[:device]}' || true"
|
||||
commands << "/sbin/ip addr flush dev '#{network[:device]}'"
|
||||
end
|
||||
|
||||
comm.sudo('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces')
|
||||
comm.sudo('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post')
|
||||
# Reconfigure /etc/network/interfaces.
|
||||
commands << <<-EOH.gsub(/^ {12}/, "")
|
||||
# Remove any previous network modifications from the interfaces file
|
||||
sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre
|
||||
sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tac | sed -e '/^#VAGRANT-END/,$ d' | tac > /tmp/vagrant-network-interfaces.post
|
||||
|
||||
# Bring back up each network interface, reconfigured
|
||||
interfaces.each do |interface|
|
||||
comm.sudo("/sbin/ifup eth#{interface}")
|
||||
end
|
||||
end
|
||||
cat \\
|
||||
/tmp/vagrant-network-interfaces.pre \\
|
||||
/tmp/vagrant-network-entry \\
|
||||
/tmp/vagrant-network-interfaces.post \\
|
||||
> /etc/network/interfaces
|
||||
|
||||
rm -f /tmp/vagrant-network-interfaces.pre
|
||||
rm -f /tmp/vagrant-network-entry
|
||||
rm -f /tmp/vagrant-network-interfaces.post
|
||||
EOH
|
||||
|
||||
# Bring back up each network interface, reconfigured.
|
||||
networks.each do |network|
|
||||
commands << "/sbin/ifup '#{network[:device]}'"
|
||||
end
|
||||
|
||||
# Run all the commands in one session to prevent partial configuration
|
||||
# due to a severed network.
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,11 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class NFSClient
|
||||
def self.nfs_client_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("apt-get -y update")
|
||||
comm.sudo("apt-get -y install nfs-common portmap")
|
||||
end
|
||||
comm = machine.communicate
|
||||
comm.sudo <<-EOH.gsub(/^ {12}/, '')
|
||||
apt-get -yqq update
|
||||
apt-get -yqq install nfs-common portmap
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,9 +3,12 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("apt-get -y update")
|
||||
comm.sudo("apt-get -y install rsync")
|
||||
comm = machine.communicate
|
||||
if !comm.test("command -v rsync")
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
apt-get -yqq update
|
||||
apt-get -yqq install rsync
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,12 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class SMB
|
||||
def self.smb_install(machine)
|
||||
# Deb/Ubuntu require mount.cifs which doesn't come by default.
|
||||
machine.communicate.tap do |comm|
|
||||
comm = machine.communicate
|
||||
if !comm.test("test -f /sbin/mount.cifs")
|
||||
machine.ui.detail(I18n.t("vagrant.guest_deb_installing_smb"))
|
||||
comm.sudo("apt-get -y update")
|
||||
comm.sudo("apt-get -y install cifs-utils")
|
||||
end
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
apt-get -yqq update
|
||||
apt-get -yqq install cifs-utils
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestDebian
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Debian guest support."
|
||||
|
||||
guest("debian", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,71 +3,25 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
new(machine, name).change!
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
attr_reader :machine, :new_hostname
|
||||
if !comm.test("hostname | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH
|
||||
echo '#{name}' > /etc/hostname
|
||||
hostname -F /etc/hostname
|
||||
hostnamectl set-hostname --static '#{name}'
|
||||
hostnamectl set-hostname --transient '#{name}'
|
||||
|
||||
def initialize(machine, new_hostname)
|
||||
@machine = machine
|
||||
@new_hostname = new_hostname
|
||||
end
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
def change!
|
||||
return unless should_change?
|
||||
|
||||
update_etc_hostname
|
||||
update_etc_hosts
|
||||
refresh_hostname_service
|
||||
end
|
||||
|
||||
def should_change?
|
||||
new_hostname != current_hostname
|
||||
end
|
||||
|
||||
def current_hostname
|
||||
@current_hostname ||= get_current_hostname
|
||||
end
|
||||
|
||||
def get_current_hostname
|
||||
hostname = ""
|
||||
sudo "hostname -f" do |type, data|
|
||||
hostname = data.chomp if type == :stdout && hostname.empty?
|
||||
end
|
||||
|
||||
hostname
|
||||
end
|
||||
|
||||
def update_etc_hostname
|
||||
sudo("echo '#{short_hostname}' > /etc/hostname")
|
||||
end
|
||||
|
||||
# /etc/hosts should resemble:
|
||||
# 127.0.0.1 localhost
|
||||
# 127.0.1.1 host.fqdn.com host.fqdn host
|
||||
def update_etc_hosts
|
||||
ip_address = '([0-9]{1,3}\.){3}[0-9]{1,3}'
|
||||
search = "^(#{ip_address})\\s+#{Regexp.escape(current_hostname)}(\\s.*)?$"
|
||||
replace = "\\1 #{fqdn} #{short_hostname} \\3"
|
||||
expression = ['s', search, replace, 'g'].join('@')
|
||||
|
||||
sudo("sed -ri '#{expression}' /etc/hosts")
|
||||
end
|
||||
|
||||
def refresh_hostname_service
|
||||
sudo("hostname -F /etc/hostname")
|
||||
end
|
||||
|
||||
def fqdn
|
||||
new_hostname
|
||||
end
|
||||
|
||||
def short_hostname
|
||||
new_hostname.split('.').first
|
||||
end
|
||||
|
||||
def sudo(cmd, &block)
|
||||
machine.communicate.sudo(cmd, &block)
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Fedora guest support."
|
||||
|
||||
guest("fedora", "redhat") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,9 +3,27 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
if !machine.communicate.test("hostname -f | grep '^#{name}$' || hostname -s | grep '^#{name}$'", {shell: "sh"})
|
||||
machine.communicate.sudo("sed -i '' 's/^hostname=.*$/hostname=\"#{name}\"/' /etc/rc.conf", {shell: "sh"})
|
||||
machine.communicate.sudo("hostname #{name}", {shell: "sh"})
|
||||
options = { shell: "sh" }
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", options)
|
||||
basename = name.split(".", 2)[0]
|
||||
command = <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set the hostname
|
||||
hostname '#{name}'
|
||||
sed -i '' 's/^hostname=.*$/hostname=\"#{name}\"/' /etc/rc.conf
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' /etc/hosts
|
||||
sed -i'' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
|
||||
mv /tmp/tmp-hosts /etc/hosts
|
||||
}
|
||||
EOH
|
||||
comm.sudo(command, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,40 +9,57 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
# Remove any previous network additions to the configuration file.
|
||||
machine.communicate.sudo("sed -i '' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf", {shell: "sh"})
|
||||
options = { shell: "sh" }
|
||||
comm = machine.communicate
|
||||
|
||||
networks.each do |network|
|
||||
# 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
|
||||
if result.split(/\n/).any?{|i| i.match(/vtnet*/)}
|
||||
ifname = "vtnet#{network[:interface]}"
|
||||
else
|
||||
ifname = "em#{network[:interface]}"
|
||||
end
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
# Remove any previous network additions to the configuration file.
|
||||
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.conf"
|
||||
|
||||
comm.sudo("ifconfig -a | grep -o ^[0-9a-z]* | grep -v '^lo'", options) do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
networks.each.with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
entry = TemplateRenderer.render("guests/freebsd/network_#{network[:type]}",
|
||||
options: network, ifname: ifname)
|
||||
options: network,
|
||||
)
|
||||
|
||||
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
||||
|
||||
Tempfile.open("vagrant-freebsd-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry")
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
machine.communicate.sudo("su -m root -c 'cat /tmp/vagrant-network-entry >> /etc/rc.conf'", {shell: "sh"})
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-network-entry", {shell: "sh"})
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
cat '#{remote_path}' >> /etc/rc.conf
|
||||
rm -f '#{remote_path}'
|
||||
EOH
|
||||
|
||||
# Restart interface so it loads configuration stored in /etc/rc.conf
|
||||
machine.communicate.sudo("service netif restart #{ifname}", {shell: "sh"})
|
||||
end
|
||||
# If the network is DHCP, then we have to start the dhclient, unless
|
||||
# it is already running. See GH-5852 for more information
|
||||
if network[:type].to_sym == :dhcp
|
||||
file = "/var/run/dhclient.#{network[:device]}.pid"
|
||||
commands << <<-EOH.gsub(/^ {16}/, '')
|
||||
if ! test -f '#{file}' || ! kill -0 $(cat '#{file}'); then
|
||||
dhclient '#{network[:device]}'
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
|
||||
# For some reason, this returns status 1... every time
|
||||
commands << "/etc/rc.d/netif restart '#{network[:device]}' || true"
|
||||
end
|
||||
|
||||
comm.sudo(commands.join("\n"), options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,32 @@
|
|||
require "vagrant/util/shell_quote"
|
||||
require "tempfile"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestFreeBSD
|
||||
module Cap
|
||||
class InsertPublicKey
|
||||
def self.insert_public_key(machine, contents)
|
||||
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
|
||||
contents = contents.gsub("\n", "\\n")
|
||||
comm = machine.communicate
|
||||
contents = contents.chomp
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p ~/.ssh", shell: "sh")
|
||||
comm.execute("chmod 0700 ~/.ssh", shell: "sh")
|
||||
comm.execute("printf '#{contents}' >> ~/.ssh/authorized_keys", shell: "sh")
|
||||
comm.execute("chmod 0600 ~/.ssh/authorized_keys", shell: "sh")
|
||||
end
|
||||
remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}"
|
||||
Tempfile.open("vagrant-freebsd-insert-public-key") do |f|
|
||||
f.binmode
|
||||
f.write(contents)
|
||||
f.fsync
|
||||
f.close
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
command = <<-EOH.gsub(/^ {12}/, '')
|
||||
mkdir -p ~/.ssh
|
||||
chmod 0700 ~/.ssh
|
||||
cat '#{remote_path}' >> ~/.ssh/authorized_keys
|
||||
chmod 0600 ~/.ssh/authorized_keys
|
||||
|
||||
# Remove the temporary file
|
||||
rm -f '#{remote_path}'
|
||||
EOH
|
||||
comm.execute(command, { shell: "sh" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,17 +3,20 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class MountNFSFolder
|
||||
def self.mount_nfs_folder(machine, ip, folders)
|
||||
folders.each do |name, opts|
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
|
||||
folders.each do |_, opts|
|
||||
if opts[:nfs_version]
|
||||
nfs_version_mount_option="-o nfsv#{opts[:nfs_version]}"
|
||||
mount_opts = "-o nfsv#{opts[:nfs_version]}"
|
||||
end
|
||||
|
||||
machine.communicate.sudo("mkdir -p #{opts[:guestpath]}", {shell: "sh"})
|
||||
commands << "mkdir -p '#{opts[:guestpath]}'"
|
||||
commands << "mount -t nfs #{mount_opts} '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'"
|
||||
end
|
||||
|
||||
machine.communicate.sudo(
|
||||
"mount -t nfs #{nfs_version_mount_option} " +
|
||||
"'#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'", {shell: "sh"})
|
||||
end
|
||||
comm.sudo(commands.join("\n"), { shell: "sh" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,7 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
version = nil
|
||||
machine.communicate.execute("uname -r") do |type, result|
|
||||
version = result.split('.')[0].to_i if type == :stdout
|
||||
end
|
||||
|
||||
pkg_cmd = "pkg install -y"
|
||||
|
||||
machine.communicate.sudo("#{pkg_cmd} rsync")
|
||||
machine.communicate.sudo("pkg install -y rsync")
|
||||
end
|
||||
|
||||
def self.rsync_installed(machine)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "FreeBSD guest support."
|
||||
|
||||
guest("freebsd") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ module VagrantPlugins
|
|||
|
||||
# Configure the interface
|
||||
comm.sudo("ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{network[:interface]}")
|
||||
comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop 2> /dev/null")
|
||||
comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop")
|
||||
comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
|
||||
comm.sudo("rm -f /tmp/vagrant-network-entry")
|
||||
comm.sudo("/etc/init.d/net.eth#{network[:interface]} start")
|
||||
|
|
|
@ -3,14 +3,14 @@ module VagrantPlugins
|
|||
module Cap
|
||||
module ChooseAddressableIPAddr
|
||||
def self.choose_addressable_ip_addr(machine, possible)
|
||||
machine.communicate.tap do |comm|
|
||||
comm = machine.communicate
|
||||
|
||||
possible.each do |ip|
|
||||
command = "ping -c1 -w1 -W1 #{ip}"
|
||||
if comm.test(command)
|
||||
return ip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -1,19 +1,29 @@
|
|||
require "vagrant/util/shell_quote"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
module Cap
|
||||
class InsertPublicKey
|
||||
def self.insert_public_key(machine, contents)
|
||||
comm = machine.communicate
|
||||
contents = contents.chomp
|
||||
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p ~/.ssh")
|
||||
comm.execute("chmod 0700 ~/.ssh")
|
||||
comm.execute("printf '#{contents}\\n' >> ~/.ssh/authorized_keys")
|
||||
comm.execute("chmod 0600 ~/.ssh/authorized_keys")
|
||||
end
|
||||
remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}"
|
||||
Tempfile.open("vagrant-linux-insert-public-key") do |f|
|
||||
f.binmode
|
||||
f.write(contents)
|
||||
f.fsync
|
||||
f.close
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
comm.execute <<-EOH.gsub(/^ {12}/, '')
|
||||
mkdir -p ~/.ssh
|
||||
chmod 0700 ~/.ssh
|
||||
cat '#{remote_path}' >> ~/.ssh/authorized_keys
|
||||
chmod 0600 ~/.ssh/authorized_keys
|
||||
|
||||
# Remove the temporary file
|
||||
rm -f '#{remote_path}'
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,13 +7,17 @@ module VagrantPlugins
|
|||
extend Vagrant::Util::Retryable
|
||||
|
||||
def self.mount_nfs_folder(machine, ip, folders)
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
|
||||
folders.each do |name, opts|
|
||||
# Expand the guest path so we can handle things like "~/vagrant"
|
||||
expanded_guest_path = machine.guest.capability(
|
||||
:shell_expand_guest_path, opts[:guestpath])
|
||||
|
||||
# Do the actual creating and mounting
|
||||
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
|
||||
commands << "mkdir -p '#{expanded_guest_path}'"
|
||||
|
||||
# Mount
|
||||
hostpath = opts[:hostpath].dup
|
||||
|
@ -26,18 +30,18 @@ module VagrantPlugins
|
|||
mount_opts = opts[:mount_options].dup
|
||||
end
|
||||
|
||||
mount_command = "mount -o '#{mount_opts.join(",")}' #{ip}:'#{hostpath}' #{expanded_guest_path}"
|
||||
retryable(on: Vagrant::Errors::LinuxNFSMountFailed, tries: 8, sleep: 3) do
|
||||
machine.communicate.sudo(mount_command,
|
||||
error_class: Vagrant::Errors::LinuxNFSMountFailed)
|
||||
end
|
||||
commands << "mount -o #{mount_opts.join(",")} '#{ip}:#{hostpath}' '#{expanded_guest_path}'"
|
||||
|
||||
# Emit an upstart event if we can
|
||||
machine.communicate.sudo <<-SCRIPT
|
||||
if command -v /sbin/init &>/dev/null && /sbin/init --version | grep upstart &>/dev/null; then
|
||||
# Emit a mount event
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
if command -v /sbin/init && /sbin/init --version | grep upstart; then
|
||||
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
|
||||
fi
|
||||
SCRIPT
|
||||
EOH
|
||||
end
|
||||
|
||||
retryable(on: Vagrant::Errors::LinuxNFSMountFailed, tries: 8, sleep: 3) do
|
||||
comm.sudo(commands.join("\n"), error_class: Vagrant::Errors::LinuxNFSMountFailed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,7 +94,7 @@ SCRIPT
|
|||
|
||||
# Emit an upstart event if we can
|
||||
machine.communicate.sudo <<-SCRIPT
|
||||
if command -v /sbin/init &>/dev/null && /sbin/init --version | grep upstart &>/dev/null; then
|
||||
if command -v /sbin/init && /sbin/init --version | grep upstart; then
|
||||
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
|
||||
fi
|
||||
SCRIPT
|
||||
|
|
|
@ -81,7 +81,7 @@ module VagrantPlugins
|
|||
|
||||
# Emit an upstart event if we can
|
||||
machine.communicate.sudo <<-SCRIPT
|
||||
if command -v /sbin/init &>/dev/null && /sbin/init --version | grep upstart &>/dev/null; then
|
||||
if command -v /sbin/init && /sbin/init --version | grep upstart; then
|
||||
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
|
||||
fi
|
||||
SCRIPT
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Linux guest support."
|
||||
|
||||
guest("linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestMint
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Mint guest support."
|
||||
|
||||
guest("mint", "ubuntu") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,24 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
su_cmd = machine.config.solaris.suexec_cmd
|
||||
comm = machine.communicate
|
||||
|
||||
# Only do this if the hostname is not already set
|
||||
if !machine.communicate.test("#{su_cmd} hostname | grep '#{name}'")
|
||||
machine.communicate.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"")
|
||||
machine.communicate.execute("#{su_cmd} hostname #{name}")
|
||||
if !comm.test("hostname | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set hostname
|
||||
echo '#{name}' > /etc/nodename
|
||||
hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
|
||||
mv /tmp/tmp-hosts /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,17 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class MountNFSFolder
|
||||
def self.mount_nfs_folder(machine, ip, folders)
|
||||
su_cmd = machine.config.solaris.suexec_cmd
|
||||
folders.each do |name, opts|
|
||||
machine.communicate.execute("#{su_cmd} mkdir -p #{opts[:guestpath]}")
|
||||
machine.communicate.execute("#{su_cmd} /sbin/mount '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'")
|
||||
end
|
||||
comm = machine.communicate
|
||||
commands = []
|
||||
|
||||
folders.each do |_, opts|
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
mkdir -p '#{opts[:guestpath]}'
|
||||
/sbin/mount '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'
|
||||
EOH
|
||||
end
|
||||
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
module VagrantPlugins
|
||||
module GuestOmniOS
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.sudo("pkg install rsync")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestOmniOS
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "OmniOS guest support."
|
||||
|
||||
guest("omnios", "solaris") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
@ -20,6 +20,11 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_nfs_folder"
|
||||
Cap::MountNFSFolder
|
||||
end
|
||||
|
||||
guest_capability("omnios", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,23 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
unless comm.test("sudo hostname --fqdn | grep '#{name}'")
|
||||
comm.sudo("hostname #{name.split('.')[0]}")
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set the hostname
|
||||
echo '#{name}' > /etc/hostname
|
||||
hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
require 'tempfile'
|
||||
require 'vagrant/util/template_renderer'
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestPhoton
|
||||
module Cap
|
||||
|
@ -8,33 +5,24 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
machine.communicate.tap do |comm|
|
||||
# Read network interface names
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
comm.sudo("ifconfig | grep 'eth' | cut -f1 -d' '") do |_, result|
|
||||
interfaces = result.split("\n")
|
||||
end
|
||||
|
||||
# Configure interfaces
|
||||
networks.each do |network|
|
||||
comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}")
|
||||
device = interfaces[network[:interface]]
|
||||
command = "ifconfig #{device}"
|
||||
command << " #{network[:ip]}" if network[:ip]
|
||||
command << " netmast #{network[:netmask]}" if network[:netmask]
|
||||
commands << command
|
||||
end
|
||||
|
||||
primary_machine_config = machine.env.active_machines.first
|
||||
primary_machine = machine.env.machine(*primary_machine_config, true)
|
||||
|
||||
get_ip = lambda do |machine|
|
||||
ip = nil
|
||||
machine.config.vm.networks.each do |type, opts|
|
||||
if type == :private_network && opts[:ip]
|
||||
ip = opts[:ip]
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
ip
|
||||
end
|
||||
end
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module VagrantPlugins
|
||||
module GuestPhoton
|
||||
class Guest < Vagrant.plugin('2', :guest)
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
def detect?(machine)
|
||||
machine.communicate.test("cat /etc/photon-release | grep 'VMware Photon Linux'")
|
||||
end
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
require 'vagrant'
|
||||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestPhoton
|
||||
class Plugin < Vagrant.plugin('2')
|
||||
name 'VMware Photon guest'
|
||||
description 'VMware Photon guest support.'
|
||||
class Plugin < Vagrant.plugin("2")
|
||||
name "VMware Photon guest"
|
||||
description "VMware Photon guest support."
|
||||
|
||||
guest('photon', 'linux') do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
guest("photon", "linux") do
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
guest_capability('photon', 'change_host_name') do
|
||||
require_relative 'cap/change_host_name'
|
||||
guest_capability("photon", "change_host_name") do
|
||||
require_relative "cap/change_host_name"
|
||||
Cap::ChangeHostName
|
||||
end
|
||||
|
||||
guest_capability('photon', 'configure_networks') do
|
||||
require_relative 'cap/configure_networks'
|
||||
guest_capability("photon", "configure_networks") do
|
||||
require_relative "cap/configure_networks"
|
||||
Cap::ConfigureNetworks
|
||||
end
|
||||
|
||||
guest_capability('photon', 'docker_daemon_running') do
|
||||
require_relative 'cap/docker'
|
||||
guest_capability("photon", "docker_daemon_running") do
|
||||
require_relative "cap/docker"
|
||||
Cap::Docker
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,15 +3,27 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
# Only do this if the hostname is not already set
|
||||
if !comm.test("sudo hostname | grep --line-regexp '#{name}'")
|
||||
comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
|
||||
comm.sudo("hostname #{name}")
|
||||
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
||||
comm.sudo("sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*")
|
||||
comm.sudo("service network restart")
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
hostname '#{name}'
|
||||
sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network
|
||||
|
||||
sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
|
||||
# Restart networking
|
||||
service network restart
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestPld
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "PLD Linux guest support."
|
||||
|
||||
guest("pld", "redhat") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -3,103 +3,37 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
new(machine, name).change!
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
attr_reader :machine, :new_hostname
|
||||
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split('.', 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Update sysconfig
|
||||
sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network
|
||||
|
||||
def initialize(machine, new_hostname)
|
||||
@machine = machine
|
||||
@new_hostname = new_hostname
|
||||
end
|
||||
# Update DNS
|
||||
sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{basename}\"/' /etc/sysconfig/network-scripts/ifcfg-*
|
||||
|
||||
def change!
|
||||
return unless should_change?
|
||||
|
||||
case machine.guest.capability("flavor")
|
||||
when :rhel_7
|
||||
update_hostname_rhel7
|
||||
update_etc_hosts
|
||||
# Set the hostname - use hostnamectl if available
|
||||
echo '#{name}' > /etc/hostname
|
||||
if command -v hostnamectl; then
|
||||
hostnamectl set-hostname '#{name}'
|
||||
else
|
||||
update_sysconfig
|
||||
update_hostname
|
||||
update_etc_hosts
|
||||
update_dhcp_hostnames
|
||||
restart_networking
|
||||
end
|
||||
end
|
||||
hostname '#{name}'
|
||||
fi
|
||||
|
||||
def should_change?
|
||||
new_hostname != current_hostname
|
||||
end
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
def current_hostname
|
||||
@current_hostname ||= get_current_hostname
|
||||
end
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
|
||||
def get_current_hostname
|
||||
hostname = ''
|
||||
block = lambda do |type, data|
|
||||
if type == :stdout
|
||||
hostname += data.chomp
|
||||
end
|
||||
end
|
||||
|
||||
execute 'hostname -f', error_check: false, &block
|
||||
execute 'hostname',&block if hostname.empty?
|
||||
/localhost(\..*)?/.match(hostname) ? '' : hostname
|
||||
end
|
||||
|
||||
def update_sysconfig
|
||||
sudo "sed -i 's/\\(HOSTNAME=\\).*/\\1#{fqdn}/' /etc/sysconfig/network"
|
||||
end
|
||||
|
||||
def update_hostname
|
||||
sudo "hostname #{fqdn}"
|
||||
end
|
||||
|
||||
def update_hostname_rhel7
|
||||
sudo "hostnamectl set-hostname #{fqdn}"
|
||||
end
|
||||
|
||||
# /etc/hosts should resemble:
|
||||
# 127.0.0.1 host.fqdn.com host localhost ...
|
||||
def update_etc_hosts
|
||||
s = '[[:space:]]'
|
||||
current_fqdn = Regexp.escape(current_hostname)
|
||||
current_short = Regexp.escape(current_hostname.split('.').first.to_s)
|
||||
currents = "\\(#{current_fqdn}#{s}\\+\\|#{current_short}#{s}\\+\\)*" unless current_hostname.empty?
|
||||
local_ip = '127[.]0[.]0[.]1'
|
||||
search = "^\\(#{local_ip}#{s}\\+\\)#{currents}"
|
||||
replace = "\\1#{fqdn} "
|
||||
replace = "#{replace}#{short_hostname} " unless fqdn == short_hostname
|
||||
expression = ['s', search, replace,''].join('@')
|
||||
|
||||
sudo "sed -i '#{expression}' /etc/hosts"
|
||||
end
|
||||
|
||||
def update_dhcp_hostnames
|
||||
sudo "sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{short_hostname}\"/' /etc/sysconfig/network-scripts/ifcfg-*"
|
||||
end
|
||||
|
||||
def restart_networking
|
||||
sudo 'service network restart'
|
||||
end
|
||||
|
||||
def fqdn
|
||||
new_hostname
|
||||
end
|
||||
|
||||
def short_hostname
|
||||
new_hostname.split('.').first
|
||||
end
|
||||
|
||||
def execute(cmd, opts=nil, &block)
|
||||
machine.communicate.execute(cmd, opts, &block)
|
||||
end
|
||||
|
||||
def sudo(cmd, opts=nil, &block)
|
||||
machine.communicate.sudo(cmd, opts, &block)
|
||||
# Restart network
|
||||
service network restart
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "set"
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/retryable"
|
||||
|
@ -12,7 +11,7 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
case machine.guest.capability("flavor")
|
||||
case machine.guest.capability(:flavor)
|
||||
when :rhel_7
|
||||
configure_networks_rhel7(machine, networks)
|
||||
else
|
||||
|
@ -21,66 +20,60 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def self.configure_networks_rhel7(machine, networks)
|
||||
# This is kind of jank but the configure networks is the same
|
||||
# as Fedora at this point.
|
||||
require File.expand_path("../../../fedora/cap/configure_networks", __FILE__)
|
||||
::VagrantPlugins::GuestFedora::Cap::ConfigureNetworks.
|
||||
configure_networks(machine, networks)
|
||||
# This is kind of jank but the configure networks is the same as
|
||||
# Fedora at this point.
|
||||
require_relative "../../fedora/cap/configure_networks"
|
||||
::VagrantPlugins::GuestFedora::Cap::ConfigureNetworks
|
||||
.configure_networks(machine, networks)
|
||||
end
|
||||
|
||||
def self.configure_networks_default(machine, networks)
|
||||
network_scripts_dir = machine.guest.capability("network_scripts_dir")
|
||||
comm = machine.communicate
|
||||
|
||||
# Accumulate the configurations to add to the interfaces file as
|
||||
# well as what interfaces we're actually configuring since we use that
|
||||
# later.
|
||||
interfaces = Set.new
|
||||
networks.each do |network|
|
||||
interfaces.add(network[:interface])
|
||||
network_scripts_dir = machine.guest.capability(:network_scripts_dir)
|
||||
|
||||
# Down the interface before munging the config file. This might fail
|
||||
# if the interface is not actually set up yet so ignore errors.
|
||||
machine.communicate.sudo(
|
||||
"/sbin/ifdown eth#{network[:interface]} 2> /dev/null", error_check: false)
|
||||
interfaces = []
|
||||
commands = []
|
||||
|
||||
# Remove any previous vagrant configuration in this network interface's
|
||||
# configuration files.
|
||||
machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
comm.sudo("ifconfig -a | grep -o ^[0-9a-z]* | grep -v '^lo'") do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
# Render and upload the network entry file to a deterministic
|
||||
# temporary location.
|
||||
networks.each.with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
# Render a new configuration
|
||||
entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}",
|
||||
options: network)
|
||||
options: network,
|
||||
)
|
||||
|
||||
Tempfile.open("vagrant-red-hat-configure-networks") do |f|
|
||||
# Upload the new configuration
|
||||
remote_path = "/tmp/vagrant-network-entry-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
||||
Tempfile.open("vagrant-redhat-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry_#{network[:interface]}")
|
||||
end
|
||||
machine.communicate.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||
# SSH never dies.
|
||||
interfaces.each do |interface|
|
||||
retryable(on: Vagrant::Errors::VagrantError, tries: 3, sleep: 2) do
|
||||
# The interface should already be down so this probably
|
||||
# won't do anything, so we run it with error_check false.
|
||||
machine.communicate.sudo(
|
||||
"/sbin/ifdown eth#{interface} 2> /dev/null", error_check: false)
|
||||
# Add the new interface and bring it back up
|
||||
final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}"
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
# Down the interface before munging the config file. This might
|
||||
# fail if the interface is not actually set up yet so ignore
|
||||
# errors.
|
||||
/sbin/ifdown '#{network[:device]}' || true
|
||||
|
||||
# Add the new interface and bring it up
|
||||
machine.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}")
|
||||
machine.communicate.sudo("ARPCHECK=no /sbin/ifup eth#{interface} 2> /dev/null")
|
||||
# Move new config into place
|
||||
mv '#{remote_path}' '#{final_path}'
|
||||
|
||||
# Bring the interface up
|
||||
ARPCHECK=no /sbin/ifup '#{network[:device]}'
|
||||
EOH
|
||||
end
|
||||
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-network-entry_#{interface}")
|
||||
end
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,10 +5,9 @@ module VagrantPlugins
|
|||
def self.flavor(machine)
|
||||
# Read the version file
|
||||
output = ""
|
||||
machine.communicate.sudo("cat /etc/redhat-release") do |type, data|
|
||||
output += data if type == :stdout
|
||||
machine.communicate.sudo("cat /etc/redhat-release") do |_, data|
|
||||
output = data
|
||||
end
|
||||
output.chomp!
|
||||
|
||||
# Detect various flavors we care about
|
||||
if output =~ /(CentOS|Red Hat Enterprise|Scientific) Linux( .+)? release 7/i
|
||||
|
|
|
@ -3,32 +3,20 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class NFSClient
|
||||
def self.nfs_client_install(machine)
|
||||
if VagrantPlugins::GuestRedHat::Plugin.dnf?(machine)
|
||||
machine.communicate.sudo("dnf -y install nfs-utils nfs-utils-lib")
|
||||
machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '')
|
||||
if command -v dnf; then
|
||||
dnf -y install nfs-utils nfs-utils-lib portmap
|
||||
else
|
||||
machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")
|
||||
end
|
||||
restart_nfs(machine)
|
||||
end
|
||||
yum -y install nfs-utils nfs-utils-lib portmap
|
||||
fi
|
||||
|
||||
def self.nfs_client_installed(machine)
|
||||
installed = machine.communicate.test("test -x /sbin/mount.nfs")
|
||||
restart_nfs(machine) if installed
|
||||
installed
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.systemd?(machine)
|
||||
machine.communicate.test("test $(ps -o comm= 1) == 'systemd'")
|
||||
end
|
||||
|
||||
def self.restart_nfs(machine)
|
||||
if systemd?(machine)
|
||||
machine.communicate.sudo("/bin/systemctl restart rpcbind nfs")
|
||||
if test $(ps -o comm= 1) == 'systemd'; then
|
||||
/bin/systemctl restart rpcbind nfs
|
||||
else
|
||||
machine.communicate.sudo("/etc/init.d/rpcbind restart; /etc/init.d/nfs restart")
|
||||
end
|
||||
/etc/init.d/rpcbind restart
|
||||
/etc/init.d/nfs restart
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,13 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
if VagrantPlugins::GuestRedHat::Plugin.dnf?(machine)
|
||||
comm.sudo("dnf -y install rsync")
|
||||
machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '')
|
||||
if command -v dnf; then
|
||||
dnf -y install rsync
|
||||
else
|
||||
comm.sudo("yum -y install rsync")
|
||||
end
|
||||
end
|
||||
yum -y install rsync
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestRedHat
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Red Hat Enterprise Linux guest support."
|
||||
|
||||
guest("redhat", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
@ -36,19 +36,10 @@ module VagrantPlugins
|
|||
Cap::NFSClient
|
||||
end
|
||||
|
||||
guest_capability("redhat", "nfs_client_installed") do
|
||||
require_relative "cap/nfs_client"
|
||||
Cap::NFSClient
|
||||
end
|
||||
|
||||
guest_capability("redhat", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
def self.dnf?(machine)
|
||||
machine.communicate.test("/usr/bin/which -s dnf")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,25 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
# Only do this if the hostname is not already set
|
||||
if !comm.test("sudo hostname | grep '#{name}'")
|
||||
comm.sudo("chmod o+w /etc/hostname")
|
||||
comm.sudo("echo #{name} > /etc/hostname")
|
||||
comm.sudo("chmod o-w /etc/hostname")
|
||||
comm.sudo("hostname -F /etc/hostname")
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set the hostname
|
||||
chmod o+w /etc/hostname
|
||||
echo '#{name}' > /etc/hostname
|
||||
chmod o-w /etc/hostname
|
||||
hostname -F /etc/hostname
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
|
@ -10,27 +9,42 @@ module VagrantPlugins
|
|||
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|
|
||||
comm = machine.communicate
|
||||
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
|
||||
interfaces = result.split("\n")
|
||||
end
|
||||
|
||||
networks.each do |network|
|
||||
# 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|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
entry = TemplateRenderer.render("guests/slackware/network_#{network[:type]}", options: network)
|
||||
entry = TemplateRenderer.render("guests/slackware/network_#{network[:type]}",
|
||||
i: i+1,
|
||||
options: network,
|
||||
)
|
||||
|
||||
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now}-#{i}"
|
||||
Tempfile.open("vagrant-slackware-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
machine.communicate.upload(f.path, "/tmp/vagrant_network")
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
machine.communicate.sudo("mv /tmp/vagrant_network /etc/rc.d/rc.inet1.conf")
|
||||
machine.communicate.sudo("/etc/rc.d/rc.inet1")
|
||||
end
|
||||
commands << "cat '#{remote_path}' >> /etc/rc.d/rc.inet1.conf"
|
||||
end
|
||||
|
||||
# Restart networking
|
||||
commands << "/etc/rc.d/rc.inet1"
|
||||
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSlackware
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Slackware guest support."
|
||||
|
||||
guest("slackware", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -1,27 +1,15 @@
|
|||
module VagrantPlugins
|
||||
module GuestSmartos
|
||||
class Config < Vagrant.plugin("2", :config)
|
||||
attr_accessor :halt_timeout
|
||||
attr_accessor :halt_check_interval
|
||||
# This sets the command to use to execute items as a superuser. sudo is default
|
||||
# This sets the command to use to execute items as a superuser.
|
||||
# @default sudo
|
||||
attr_accessor :suexec_cmd
|
||||
attr_accessor :device
|
||||
|
||||
def initialize
|
||||
@halt_timeout = UNSET_VALUE
|
||||
@halt_check_interval = UNSET_VALUE
|
||||
@suexec_cmd = 'pfexec'
|
||||
@device = "e1000g"
|
||||
end
|
||||
|
||||
def finalize!
|
||||
if @halt_timeout != UNSET_VALUE
|
||||
puts "smartos.halt_timeout is deprecated and will be removed in Vagrant 1.7"
|
||||
end
|
||||
if @halt_check_interval != UNSET_VALUE
|
||||
puts "smartos.halt_check_interval is deprecated and will be removed in Vagrant 1.7"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,22 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
machine.communicate.tap do |comm|
|
||||
# Only do this if the hostname is not already set
|
||||
if !comm.test("sudo hostname | grep '#{name}'")
|
||||
comm.sudo("echo #{name} > /etc/HOSTNAME")
|
||||
comm.sudo("hostname #{name}")
|
||||
comm = machine.communicate
|
||||
|
||||
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
||||
end
|
||||
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
echo '#{name}' > /etc/HOSTNAME
|
||||
hostname '#{name}'
|
||||
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
require "set"
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/retryable"
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
|
||||
module VagrantPlugins
|
||||
|
@ -12,48 +10,43 @@ module VagrantPlugins
|
|||
include Vagrant::Util
|
||||
|
||||
def self.configure_networks(machine, networks)
|
||||
network_scripts_dir = machine.guest.capability("network_scripts_dir")
|
||||
comm = machine.communicate
|
||||
|
||||
# Accumulate the configurations to add to the interfaces file as
|
||||
# well as what interfaces we're actually configuring since we use that
|
||||
# later.
|
||||
interfaces = Set.new
|
||||
networks.each do |network|
|
||||
interfaces.add(network[:interface])
|
||||
network_scripts_dir = machine.guest.capability(:network_scripts_dir)
|
||||
|
||||
# Remove any previous vagrant configuration in this network interface's
|
||||
# configuration files.
|
||||
machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-eth#{network[:interface]} > /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("cat /tmp/vagrant-ifcfg-eth#{network[:interface]} > #{network_scripts_dir}/ifcfg-eth#{network[:interface]}")
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-ifcfg-eth#{network[:interface]}")
|
||||
commands = []
|
||||
interfaces = []
|
||||
|
||||
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
|
||||
interfaces = stdout.split("\n")
|
||||
end
|
||||
|
||||
networks.each.with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
# Render and upload the network entry file to a deterministic
|
||||
# temporary location.
|
||||
entry = TemplateRenderer.render("guests/suse/network_#{network[:type]}",
|
||||
options: network)
|
||||
options: network,
|
||||
)
|
||||
|
||||
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
||||
|
||||
Tempfile.open("vagrant-suse-configure-networks") do |f|
|
||||
f.binmode
|
||||
f.write(entry)
|
||||
f.fsync
|
||||
f.close
|
||||
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry_#{network[:interface]}")
|
||||
end
|
||||
comm.upload(f.path, remote_path)
|
||||
end
|
||||
|
||||
# Bring down all the interfaces we're reconfiguring. By bringing down
|
||||
# each specifically, we avoid reconfiguring eth0 (the NAT interface) so
|
||||
# SSH never dies.
|
||||
interfaces.each do |interface|
|
||||
retryable(on: Vagrant::Errors::VagrantError, tries: 3, sleep: 2) do
|
||||
machine.communicate.sudo("/sbin/ifdown eth#{interface} 2> /dev/null", error_check: false)
|
||||
machine.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-eth#{interface}")
|
||||
machine.communicate.sudo("/sbin/ifup eth#{interface} 2> /dev/null")
|
||||
local_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}"
|
||||
commands << <<-EOH.gsub(/^ {14}/, '')
|
||||
/sbin/ifdown '#{network[:device]}' || true
|
||||
mv '#{remote_path}' '#{local_path}'
|
||||
/sbin/ifup '#{network[:device]}'
|
||||
EOH
|
||||
end
|
||||
|
||||
machine.communicate.sudo("rm -f /tmp/vagrant-network-entry_#{interface}")
|
||||
end
|
||||
comm.sudo(commands.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,11 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class NFSClient
|
||||
def self.nfs_client_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("zypper -n install nfs-client")
|
||||
|
||||
comm.sudo("/sbin/service rpcbind restart")
|
||||
comm.sudo("/sbin/service nfs restart")
|
||||
end
|
||||
machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '')
|
||||
zypper -n install nfs-client
|
||||
/sbin/service rpcbind restart
|
||||
/sbin/service nfs restart
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,9 +7,7 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("zypper -n install rsync")
|
||||
end
|
||||
machine.communicate.sudo("zypper -n install rsync")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestSUSE
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "SUSE guest support."
|
||||
|
||||
guest("suse", "linux") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module VagrantPlugins
|
|||
|
||||
# Emit an upstart event if we can
|
||||
machine.communicate.sudo <<-SCRIPT
|
||||
if command -v /sbin/init &>/dev/null && /sbin/init --version | grep upstart &>/dev/null; then
|
||||
if command -v /sbin/init && /sbin/init --version | grep upstart; then
|
||||
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
|
||||
fi
|
||||
SCRIPT
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestTrisquel
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,7 +7,7 @@ module VagrantPlugins
|
|||
description "Trisquel guest support."
|
||||
|
||||
guest("trisquel", "ubuntu") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,49 +1,50 @@
|
|||
module VagrantPlugins
|
||||
module GuestUbuntu
|
||||
module Cap
|
||||
class ChangeHostName < VagrantPlugins::GuestDebian::Cap::ChangeHostName
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
super
|
||||
end
|
||||
comm = machine.communicate
|
||||
|
||||
def update_etc_hostname
|
||||
return super unless systemd?
|
||||
sudo("hostnamectl set-hostname '#{short_hostname}'")
|
||||
end
|
||||
if !comm.test("hostname -f | grep -w '#{name}'")
|
||||
basename = name.split(".", 2)[0]
|
||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||
# Set the hostname
|
||||
echo '#{name}' > /etc/hostname
|
||||
hostname -F /etc/hostname
|
||||
|
||||
def refresh_hostname_service
|
||||
if hardy?
|
||||
# hostname.sh returns 1, so use `true` to get a 0 exitcode
|
||||
sudo("/etc/init.d/hostname.sh start; true")
|
||||
elsif systemd?
|
||||
# Service runs via hostnamectl
|
||||
else
|
||||
sudo("service hostname start")
|
||||
end
|
||||
end
|
||||
if command -v hostnamectl; then
|
||||
hostnamectl set-hostname '#{name}'
|
||||
fi
|
||||
|
||||
def hardy?
|
||||
os_version("hardy")
|
||||
end
|
||||
# Remove comments and blank lines from /etc/hosts
|
||||
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
|
||||
|
||||
def renew_dhcp
|
||||
sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
|
||||
end
|
||||
# Prepend ourselves to /etc/hosts
|
||||
grep -w '#{name}' /etc/hosts || {
|
||||
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
|
||||
}
|
||||
|
||||
private
|
||||
# Update mailname
|
||||
echo '#{name}' > /etc/mailname
|
||||
|
||||
def init_package
|
||||
machine.communicate.execute('cat /proc/1/comm') do |type, data|
|
||||
return data.chomp if type == :stdout
|
||||
end
|
||||
end
|
||||
# Restart networking and force new DHCP
|
||||
if [ test -f /etc/init.d/hostname ]; then
|
||||
/etc/init.d/hostname start || true
|
||||
fi
|
||||
|
||||
def os_version(name)
|
||||
machine.communicate.test("[ `lsb_release -c -s` = #{name} ]")
|
||||
end
|
||||
if [ test -f /etc/init.d/hostname.sh ]; then
|
||||
/etc/init.d/hostname.sh start || true
|
||||
fi
|
||||
|
||||
def systemd?
|
||||
init_package == 'systemd'
|
||||
if [ test -f /etc/init.d/networking ]; then
|
||||
/etc/init.d/networking force-reload
|
||||
fi
|
||||
|
||||
if [ test -f /etc/init.d/network-manager ]; then
|
||||
/etc/init.d/network-manager force-reload
|
||||
fi
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module GuestUbuntu
|
||||
class Guest < Vagrant.plugin("2", :guest)
|
||||
|
|
|
@ -7,13 +7,11 @@ module VagrantPlugins
|
|||
description "Ubuntu guest support."
|
||||
|
||||
guest("ubuntu", "debian") do
|
||||
require File.expand_path("../guest", __FILE__)
|
||||
require_relative "guest"
|
||||
Guest
|
||||
end
|
||||
|
||||
guest_capability("ubuntu", "change_host_name") do
|
||||
# ubuntu is just just a specialization of the debian code for this capability
|
||||
require_relative "../debian/cap/change_host_name"
|
||||
require_relative "cap/change_host_name"
|
||||
Cap::ChangeHostName
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
auto eth<%= options[:interface] %>
|
||||
iface eth<%= options[:interface] %> inet dhcp
|
||||
auto <%= options[:device] %>
|
||||
iface <%= options[:device] %> inet dhcp
|
||||
<% if !options[:use_dhcp_assigned_default_route] %>
|
||||
post-up route del default dev $IFACE || true
|
||||
<% else %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
auto eth<%= options[:interface] %>
|
||||
iface eth<%= options[:interface] %> inet static
|
||||
auto <%= options[:device] %>
|
||||
iface <%= options[:device] %> inet static
|
||||
address <%= options[:ip] %>
|
||||
netmask <%= options[:netmask] %>
|
||||
<% if options[:gateway] %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#VAGRANT-BEGIN
|
||||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
auto eth<%= options[:interface] %>
|
||||
iface eth<%= options[:interface] %> inet6 static
|
||||
auto <%= options[:device] %>
|
||||
iface <%= options[:device] %> inet6 static
|
||||
address <%= options[:ip] %>
|
||||
netmask <%= options[:netmask] %>
|
||||
<% if options[:gateway] %>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#VAGRANT-BEGIN
|
||||
ifconfig_<%= ifname %>="DHCP"
|
||||
ifconfig_<%= options[:device] %>="DHCP"
|
||||
synchronous_dhclient="YES"
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#VAGRANT-BEGIN
|
||||
ifconfig_<%= ifname %>="inet <%= options[:ip] %> netmask <%= options[:netmask] %>"
|
||||
ifconfig_<%= options[:device] %>="inet <%= options[:ip] %> netmask <%= options[:netmask] %>"
|
||||
<% if options[:gateway] %>
|
||||
default_router="<%= options[:gateway] %>"
|
||||
<% end %>
|
||||
|
|
|
@ -1,23 +1,11 @@
|
|||
IPADDR[0]=""
|
||||
NETMASK[0]=""
|
||||
USE_DHCP[0]="yes"
|
||||
DHCP_HOSTNAME[0]=""
|
||||
#VAGRANT-BEGIN
|
||||
# Config for eth<%= i %>
|
||||
USE_DHCP[<%= i %>]="yes"
|
||||
DHCP_HOSTNAME[<%= i %>]=""
|
||||
|
||||
IPADDR[1]=""
|
||||
NETMASK[1]=""
|
||||
USE_DHCP[1]="yes"
|
||||
DHCP_HOSTNAME[1]=""
|
||||
|
||||
IPADDR[2]=""
|
||||
NETMASK[2]=""
|
||||
USE_DHCP[2]=""
|
||||
DHCP_HOSTNAME[2]=""
|
||||
|
||||
IPADDR[3]=""
|
||||
NETMASK[3]=""
|
||||
USE_DHCP[3]=""
|
||||
DHCP_HOSTNAME[3]=""
|
||||
|
||||
GATEWAY=""
|
||||
<% if options[:gateway] -%>
|
||||
GATEWAY="<%= options[:gateway] %>"
|
||||
<% end -%>
|
||||
|
||||
DEBUG_ETH_UP="no"
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -1,25 +1,13 @@
|
|||
IPADDR[0]=""
|
||||
NETMASK[0]=""
|
||||
USE_DHCP[0]="yes"
|
||||
DHCP_HOSTNAME[0]=""
|
||||
#VAGRANT-BEGIN
|
||||
# Config for eth<%= i %>
|
||||
IPADDR[<%= i %>]="<%= options[:ip] %>"
|
||||
NETMASK[<%= i %>]="<%= options[:ip] %>"
|
||||
USE_DHCP[<%= i %>]=""
|
||||
DHCP_HOSTNAME[<%= i %>]=""
|
||||
|
||||
IPADDR[1]="<%= options[:ip] %>"
|
||||
NETMASK[1]=""
|
||||
USE_DHCP[1]=""
|
||||
DHCP_HOSTNAME[1]=""
|
||||
|
||||
IPADDR[2]=""
|
||||
NETMASK[2]=""
|
||||
USE_DHCP[2]=""
|
||||
DHCP_HOSTNAME[2]=""
|
||||
|
||||
IPADDR[3]=""
|
||||
NETMASK[3]=""
|
||||
USE_DHCP[3]=""
|
||||
DHCP_HOSTNAME[3]=""
|
||||
|
||||
<% if options[:gateway] %>
|
||||
<% if options[:gateway] -%>
|
||||
GATEWAY="<%= options[:gateway] %>"
|
||||
<% end %>
|
||||
<% end -%>
|
||||
|
||||
DEBUG_ETH_UP="no"
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||
BOOTPROTO='dhcp'
|
||||
STARTMODE='auto'
|
||||
DEVICE='eth<%= options[:interface] %>'
|
||||
DEVICE='<%= options[:device] %>'
|
||||
#VAGRANT-END
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
BOOTPROTO='static'
|
||||
IPADDR='<%= options[:ip] %>'
|
||||
NETMASK='<%= options[:netmask] %>'
|
||||
DEVICE='eth<%= options[:interface] %>'
|
||||
<% if options[:gateway] %>
|
||||
DEVICE='<%= options[:device] %>'
|
||||
<% if options[:gateway] -%>
|
||||
GATEWAY='<%= options[:gateway] %>'
|
||||
<% end %>
|
||||
<% end -%>
|
||||
PEERDNS='no'
|
||||
STARTMODE='auto'
|
||||
USERCONTROL='no'
|
||||
|
|
|
@ -9,29 +9,30 @@ describe "VagrantPlugins::GuestArch::Cap::ChangeHostName" do
|
|||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
let(:hostname) { "example.com" }
|
||||
let(:hostname) { "banana-rama.example.com" }
|
||||
|
||||
it "sets the hostname" do
|
||||
communicator.stub_command("sudo hostname | grep '#{hostname}'", exit_code: 1)
|
||||
communicator.expect_command("hostnamectl set-hostname #{hostname}")
|
||||
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 1)
|
||||
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{hostname}'/)
|
||||
end
|
||||
|
||||
it "does not change the hostname if already set" do
|
||||
communicator.stub_command("sudo hostname | grep '#{hostname}'", exit_code: 0)
|
||||
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 0)
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(communicator.received_commands.size).to eq(1)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,16 +9,16 @@ describe "VagrantPlugins::GuestArch::Cap::ConfigureNetworks" do
|
|||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
communicator.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
|
||||
stdout: "eth1\neth2")
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".configure_networks" do
|
||||
|
@ -40,9 +40,16 @@ describe "VagrantPlugins::GuestArch::Cap::ConfigureNetworks" do
|
|||
end
|
||||
|
||||
it "creates and starts the networks" do
|
||||
communicator.expect_command("ip link set eth1 down && netctl restart eth1 && netctl enable eth1")
|
||||
communicator.expect_command("ip link set eth2 down && netctl restart eth2 && netctl enable eth2")
|
||||
described_class.configure_networks(machine, [network_1, network_2])
|
||||
expect(comm.received_commands[1]).to match(/mv (.+) '\/etc\/netctl\/eth1'/)
|
||||
expect(comm.received_commands[1]).to match(/ip link set 'eth1' down/)
|
||||
expect(comm.received_commands[1]).to match(/netctl restart 'eth1'/)
|
||||
expect(comm.received_commands[1]).to match(/netctl enable 'eth1'/)
|
||||
|
||||
expect(comm.received_commands[1]).to match(/mv (.+) '\/etc\/netctl\/eth2'/)
|
||||
expect(comm.received_commands[1]).to match(/ip link set 'eth2' down/)
|
||||
expect(comm.received_commands[1]).to match(/netctl restart 'eth2'/)
|
||||
expect(comm.received_commands[1]).to match(/netctl enable 'eth2'/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestAtomic::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestAtomic::Plugin
|
||||
.components
|
||||
.guest_capabilities[:atomic]
|
||||
.get(:change_host_name)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
let(:hostname) { "banana-rama.example.com" }
|
||||
|
||||
it "sets the hostname" do
|
||||
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 1)
|
||||
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{hostname}'/)
|
||||
end
|
||||
|
||||
it "does not change the hostname if already set" do
|
||||
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 0)
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,28 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestAtomic::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestAtomic::Plugin
|
||||
.components
|
||||
.guest_capabilities[:atomic]
|
||||
.get(:docker_daemon_running)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".docker_daemon_running" do
|
||||
it "checks /run/docker/sock" do
|
||||
described_class.docker_daemon_running(machine)
|
||||
expect(comm.received_commands[0]).to eq("test -S /run/docker.sock")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,29 +9,29 @@ describe "VagrantPlugins::GuestCoreOS::Cap::ChangeHostName" do
|
|||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
let(:hostname) { "example.com" }
|
||||
let(:hostname) { "banana-rama.example.com" }
|
||||
|
||||
it "sets the hostname" do
|
||||
communicator.stub_command("sudo hostname --fqdn | grep '#{hostname}'", exit_code: 1)
|
||||
communicator.expect_command("hostname example")
|
||||
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 1)
|
||||
comm.expect_command("hostname 'banana-rama'")
|
||||
described_class.change_host_name(machine, hostname)
|
||||
end
|
||||
|
||||
it "does not change the hostname if already set" do
|
||||
communicator.stub_command("sudo hostname --fqdn | grep '#{hostname}'", exit_code: 0)
|
||||
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 0)
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(communicator.received_commands.size).to eq(1)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestCoreOS::Cap::ConfigureNetworks" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestCoreOS::Plugin
|
||||
.components
|
||||
.guest_capabilities[:coreos]
|
||||
.get(:configure_networks)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
let(:env) do
|
||||
double("env", machine: machine, active_machines: [machine])
|
||||
end
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
allow(machine).to receive(:env).and_return(env)
|
||||
|
||||
allow(described_class).to receive(:get_ip).and_return("1.2.3.4")
|
||||
|
||||
comm.stub_command("ifconfig | grep '(e[n,t][h,s,p][[:digit:]]([a-z][[:digit:]])?' | cut -f1 -d:",
|
||||
stdout: "eth1\neth2")
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".configure_networks" do
|
||||
let(:network_1) do
|
||||
{
|
||||
interface: 0,
|
||||
type: "dhcp",
|
||||
}
|
||||
end
|
||||
|
||||
let(:network_2) do
|
||||
{
|
||||
interface: 1,
|
||||
type: "static",
|
||||
ip: "33.33.33.10",
|
||||
netmask: "255.255.0.0",
|
||||
gateway: "33.33.0.1",
|
||||
}
|
||||
end
|
||||
|
||||
it "creates and starts the networks" do
|
||||
described_class.configure_networks(machine, [network_1, network_2])
|
||||
expect(comm.received_commands[1]).to match(/systemctl stop etcd/)
|
||||
expect(comm.received_commands[1]).to match(/ifconfig eth1 netmask/)
|
||||
expect(comm.received_commands[1]).to match(/ifconfig eth2 33.33.33.10 netmask 255.255.0.0/)
|
||||
expect(comm.received_commands[1]).to match(/systemctl restart local-enable.service/)
|
||||
expect(comm.received_commands[1]).to match(/systemctl start etcd/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,28 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestCoreOS::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestCoreOS::Plugin
|
||||
.components
|
||||
.guest_capabilities[:coreos]
|
||||
.get(:docker_daemon_running)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".docker_daemon_running" do
|
||||
it "checks /run/docker/sock" do
|
||||
described_class.docker_daemon_running(machine)
|
||||
expect(comm.received_commands[0]).to eq("test -S /run/docker.sock")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestDarwin::Plugin
|
||||
.components
|
||||
.guest_capabilities[:darwin]
|
||||
.get(:change_host_name)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
let(:hostname) { "banana-rama.example.com" }
|
||||
|
||||
it "sets the hostname" do
|
||||
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 1)
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(comm.received_commands[1]).to match(/scutil --set ComputerName 'banana-rama.example.com'/)
|
||||
expect(comm.received_commands[1]).to match(/scutil --set HostName 'banana-rama.example.com'/)
|
||||
expect(comm.received_commands[1]).to match(/scutil --set LocalHostName 'banana-rama'/)
|
||||
expect(comm.received_commands[1]).to match(/hostname 'banana-rama.example.com'/)
|
||||
end
|
||||
|
||||
it "does not change the hostname if already set" do
|
||||
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 0)
|
||||
described_class.change_host_name(machine, hostname)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestDarwin::Plugin
|
||||
.components
|
||||
.guest_capabilities[:darwin]
|
||||
.get(:choose_addressable_ip_addr)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".choose_addressable_ip_addr" do
|
||||
let(:possible) { ["1.2.3.4", "5.6.7.8"] }
|
||||
|
||||
it "retrieves the value" do
|
||||
comm.stub_command("ping -c1 -t1 5.6.7.8", exit_code: 0)
|
||||
result = described_class.choose_addressable_ip_addr(machine, possible)
|
||||
expect(result).to eq("5.6.7.8")
|
||||
end
|
||||
|
||||
it "returns nil if no ips are found" do
|
||||
result = described_class.choose_addressable_ip_addr(machine, [])
|
||||
expect(result).to be(nil)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,38 +1,41 @@
|
|||
require_relative "../../../../base"
|
||||
require_relative "../../support/shared/debian_like_host_name_examples"
|
||||
|
||||
describe "VagrantPlugins::GuestDebian::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
let(:caps) do
|
||||
VagrantPlugins::GuestDebian::Plugin
|
||||
.components
|
||||
.guest_capabilities[:debian]
|
||||
.get(:change_host_name)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:old_hostname) { 'oldhostname.olddomain.tld' }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
communicator.stub_command('hostname -f', stdout: old_hostname)
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
it_behaves_like "a debian-like host name change"
|
||||
let(:cap) { caps.get(:change_host_name) }
|
||||
|
||||
it "refreshes the hostname service with the hostname command" do
|
||||
communicator.expect_command(%q(hostname -F /etc/hostname))
|
||||
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
|
||||
let(:name) { 'banana-rama.example.com' }
|
||||
|
||||
it "sets the hostname if not set" do
|
||||
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
|
||||
cap.change_host_name(machine, name)
|
||||
expect(comm.received_commands[1]).to match(/hostname -F \/etc\/hostname/)
|
||||
expect(comm.received_commands[1]).to match(/invoke-rc.d hostname.sh start/)
|
||||
expect(comm.received_commands[1]).to match(/invoke-rc.d networking force-reload/)
|
||||
expect(comm.received_commands[1]).to match(/invoke-rc.d network-manager force-reload/)
|
||||
end
|
||||
|
||||
it "renews dhcp on the system with the new hostname" do
|
||||
communicator.expect_command(%q(ifdown -a; ifup -a; ifup eth0))
|
||||
described_class.change_host_name(machine, 'newhostname.newdomain.tld')
|
||||
it "does not set the hostname if unset" do
|
||||
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
|
||||
cap.change_host_name(machine, name)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
||||
let(:described_class) do
|
||||
let(:caps) do
|
||||
VagrantPlugins::GuestDebian::Plugin
|
||||
.components
|
||||
.guest_capabilities[:debian]
|
||||
.get(:configure_networks)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
|
||||
stdout: "eth1\neth2")
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".configure_networks" do
|
||||
let(:cap) { caps.get(:configure_networks) }
|
||||
|
||||
let(:network_0) do
|
||||
{
|
||||
interface: 0,
|
||||
|
@ -38,13 +41,14 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
|
|||
end
|
||||
|
||||
it "creates and starts the networks" do
|
||||
communicator.expect_command("/sbin/ifdown eth0 2> /dev/null || true")
|
||||
communicator.expect_command("/sbin/ip addr flush dev eth0 2> /dev/null")
|
||||
communicator.expect_command("/sbin/ifdown eth1 2> /dev/null || true")
|
||||
communicator.expect_command("/sbin/ip addr flush dev eth1 2> /dev/null")
|
||||
communicator.expect_command("/sbin/ifup eth0")
|
||||
communicator.expect_command("/sbin/ifup eth1")
|
||||
described_class.configure_networks(machine, [network_0, network_1])
|
||||
cap.configure_networks(machine, [network_0, network_1])
|
||||
|
||||
expect(comm.received_commands[1]).to match("/sbin/ifdown 'eth1' || true")
|
||||
expect(comm.received_commands[1]).to match("/sbin/ip addr flush dev 'eth1'")
|
||||
expect(comm.received_commands[1]).to match("/sbin/ifdown 'eth2' || true")
|
||||
expect(comm.received_commands[1]).to match("/sbin/ip addr flush dev 'eth2'")
|
||||
expect(comm.received_commands[1]).to match("/sbin/ifup 'eth1'")
|
||||
expect(comm.received_commands[1]).to match("/sbin/ifup 'eth2'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDebian::Cap::NFSClient" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestDebian::Plugin
|
||||
.components
|
||||
.guest_capabilities[:debian]
|
||||
.get(:nfs_client_install)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".nfs_client_install" do
|
||||
it "installs nfs client utilities" do
|
||||
described_class.nfs_client_install(machine)
|
||||
|
||||
expect(comm.received_commands[0]).to match(/apt-get -yqq update/)
|
||||
expect(comm.received_commands[0]).to match(/apt-get -yqq install nfs-common portmap/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,38 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDebian::Cap:RSync" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestDebian::Plugin
|
||||
.components
|
||||
.guest_capabilities[:debian]
|
||||
.get(:rsync_install)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".rsync_install" do
|
||||
it "installs rsync when not installed" do
|
||||
comm.stub_command("command -v rsync", exit_code: 1)
|
||||
described_class.rsync_install(machine)
|
||||
|
||||
expect(comm.received_commands[1]).to match(/apt-get -yqq update/)
|
||||
expect(comm.received_commands[1]).to match(/apt-get -yqq install rsync/)
|
||||
end
|
||||
|
||||
it "does not install rsync when installed" do
|
||||
comm.stub_command("command -v rsync", exit_code: 0)
|
||||
described_class.rsync_install(machine)
|
||||
|
||||
expect(comm.received_commands.join("")).to_not match(/update/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,38 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestDebian::Cap::SMB" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestDebian::Plugin
|
||||
.components
|
||||
.guest_capabilities[:debian]
|
||||
.get(:smb_install)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".smb_install" do
|
||||
it "installs smb when /sbin/mount.cifs does not exist" do
|
||||
comm.stub_command("test -f /sbin/mount.cifs", exit_code: 1)
|
||||
described_class.smb_install(machine)
|
||||
|
||||
expect(comm.received_commands[1]).to match(/apt-get -yqq update/)
|
||||
expect(comm.received_commands[1]).to match(/apt-get -yqq install cifs-utils/)
|
||||
end
|
||||
|
||||
it "does not install smb when /sbin/mount.cifs exists" do
|
||||
comm.stub_command("test -f /sbin/mount.cifs", exit_code: 0)
|
||||
described_class.smb_install(machine)
|
||||
|
||||
expect(comm.received_commands.join("")).to_not match(/update/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,40 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestFreeBSD::Cap::ChangeHostName" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestFreeBSD::Plugin
|
||||
.components
|
||||
.guest_capabilities[:freebsd]
|
||||
.get(:change_host_name)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
let(:name) { "banana-rama.example.com" }
|
||||
|
||||
it "sets the hostname and /etc/hosts" do
|
||||
comm.stub_command("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", exit_code: 1)
|
||||
described_class.change_host_name(machine, name)
|
||||
|
||||
expect(comm.received_commands[1]).to match(/hostname '#{name}'/)
|
||||
expect(comm.received_commands[1]).to match(/grep -w '#{name}' \/etc\/hosts/)
|
||||
expect(comm.received_commands[1]).to match(/echo -e '127.0.0.1\\t#{name}\\tbanana-rama'/)
|
||||
end
|
||||
|
||||
it "does nothing if the hostname is already set" do
|
||||
comm.stub_command("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", exit_code: 0)
|
||||
described_class.change_host_name(machine, name)
|
||||
expect(comm.received_commands.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestFreeBSD::Cap::ConfigureNetworks" do
|
||||
let(:described_class) do
|
||||
VagrantPlugins::GuestFreeBSD::Plugin
|
||||
.components
|
||||
.guest_capabilities[:freebsd]
|
||||
.get(:configure_networks)
|
||||
end
|
||||
|
||||
let(:machine) { double("machine") }
|
||||
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
allow(machine).to receive(:communicate).and_return(comm)
|
||||
comm.stub_command("ifconfig -a | grep -o ^[0-9a-z]* | grep -v '^lo'",
|
||||
stdout: "em1\nem2")
|
||||
end
|
||||
|
||||
after do
|
||||
comm.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".configure_networks" do
|
||||
let(:network_1) do
|
||||
{
|
||||
interface: 0,
|
||||
type: "dhcp",
|
||||
}
|
||||
end
|
||||
|
||||
let(:network_2) do
|
||||
{
|
||||
interface: 1,
|
||||
type: "static",
|
||||
ip: "33.33.33.10",
|
||||
netmask: "255.255.0.0",
|
||||
gateway: "33.33.0.1",
|
||||
}
|
||||
end
|
||||
|
||||
it "creates and starts the networks" do
|
||||
described_class.configure_networks(machine, [network_1, network_2])
|
||||
expect(comm.received_commands[1]).to match(/dhclient 'em1'/)
|
||||
expect(comm.received_commands[1]).to match(/\/etc\/rc.d\/netif restart 'em1'/)
|
||||
|
||||
expect(comm.received_commands[1]).to_not match(/dhclient 'em2'/)
|
||||
expect(comm.received_commands[1]).to match(/\/etc\/rc.d\/netif restart 'em2'/)
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue