2012-11-07 05:28:44 +00:00
|
|
|
require "pathname"
|
2013-03-02 00:31:54 +00:00
|
|
|
require "securerandom"
|
2013-03-16 05:11:49 +00:00
|
|
|
require "set"
|
2012-11-07 05:28:44 +00:00
|
|
|
|
|
|
|
require "vagrant"
|
2018-06-30 16:58:19 +00:00
|
|
|
require "vagrant/action/builtin/mixin_synced_folders"
|
2013-01-18 20:56:19 +00:00
|
|
|
require "vagrant/config/v2/util"
|
2013-07-20 04:38:58 +00:00
|
|
|
require "vagrant/util/platform"
|
2016-06-18 18:46:46 +00:00
|
|
|
require "vagrant/util/presence"
|
2012-11-07 05:28:44 +00:00
|
|
|
|
|
|
|
require File.expand_path("../vm_provisioner", __FILE__)
|
|
|
|
require File.expand_path("../vm_subvm", __FILE__)
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Kernel_V2
|
|
|
|
class VMConfig < Vagrant.plugin("2", :config)
|
2016-06-18 18:46:46 +00:00
|
|
|
include Vagrant::Util::Presence
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
DEFAULT_VM_NAME = :default
|
|
|
|
|
2014-12-17 04:35:01 +00:00
|
|
|
attr_accessor :allowed_synced_folder_types
|
2012-11-07 05:28:44 +00:00
|
|
|
attr_accessor :base_mac
|
2013-08-29 23:41:36 +00:00
|
|
|
attr_accessor :boot_timeout
|
2012-11-15 03:59:18 +00:00
|
|
|
attr_accessor :box
|
2018-09-26 17:31:41 +00:00
|
|
|
attr_accessor :ignore_box_vagrantfile
|
2014-01-24 23:27:01 +00:00
|
|
|
attr_accessor :box_check_update
|
2012-11-15 03:59:18 +00:00
|
|
|
attr_accessor :box_url
|
2014-08-01 12:31:06 +00:00
|
|
|
attr_accessor :box_server_url
|
2014-01-24 17:16:37 +00:00
|
|
|
attr_accessor :box_version
|
2013-11-27 03:34:41 +00:00
|
|
|
attr_accessor :box_download_ca_cert
|
2014-05-19 15:41:13 +00:00
|
|
|
attr_accessor :box_download_ca_path
|
2013-12-02 06:45:08 +00:00
|
|
|
attr_accessor :box_download_checksum
|
|
|
|
attr_accessor :box_download_checksum_type
|
2013-11-26 00:51:22 +00:00
|
|
|
attr_accessor :box_download_client_cert
|
2013-07-20 04:18:02 +00:00
|
|
|
attr_accessor :box_download_insecure
|
2014-09-01 09:23:37 +00:00
|
|
|
attr_accessor :box_download_location_trusted
|
2014-03-11 05:59:25 +00:00
|
|
|
attr_accessor :communicator
|
2013-08-29 23:38:02 +00:00
|
|
|
attr_accessor :graceful_halt_timeout
|
2012-11-15 03:59:18 +00:00
|
|
|
attr_accessor :guest
|
2013-02-28 05:29:11 +00:00
|
|
|
attr_accessor :hostname
|
2014-04-09 21:57:16 +00:00
|
|
|
attr_accessor :post_up_message
|
2013-01-11 22:44:27 +00:00
|
|
|
attr_accessor :usable_port_range
|
2012-11-07 05:28:44 +00:00
|
|
|
attr_reader :provisioners
|
|
|
|
|
2015-10-08 15:50:06 +00:00
|
|
|
# This is an experimental feature that isn't public yet.
|
|
|
|
attr_accessor :clone
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
def initialize
|
2014-10-25 13:01:21 +00:00
|
|
|
@logger = Log4r::Logger.new("vagrant::config::vm")
|
|
|
|
|
2015-07-09 21:05:52 +00:00
|
|
|
@allowed_synced_folder_types = UNSET_VALUE
|
2014-09-01 09:23:37 +00:00
|
|
|
@base_mac = UNSET_VALUE
|
|
|
|
@boot_timeout = UNSET_VALUE
|
|
|
|
@box = UNSET_VALUE
|
2018-09-26 17:31:41 +00:00
|
|
|
@ignore_box_vagrantfile = UNSET_VALUE
|
2014-09-01 09:23:37 +00:00
|
|
|
@box_check_update = UNSET_VALUE
|
|
|
|
@box_download_ca_cert = UNSET_VALUE
|
|
|
|
@box_download_ca_path = UNSET_VALUE
|
|
|
|
@box_download_checksum = UNSET_VALUE
|
|
|
|
@box_download_checksum_type = UNSET_VALUE
|
|
|
|
@box_download_client_cert = UNSET_VALUE
|
|
|
|
@box_download_insecure = UNSET_VALUE
|
|
|
|
@box_download_location_trusted = UNSET_VALUE
|
|
|
|
@box_url = UNSET_VALUE
|
|
|
|
@box_version = UNSET_VALUE
|
2015-10-08 15:37:35 +00:00
|
|
|
@clone = UNSET_VALUE
|
2014-09-01 09:23:37 +00:00
|
|
|
@communicator = UNSET_VALUE
|
|
|
|
@graceful_halt_timeout = UNSET_VALUE
|
|
|
|
@guest = UNSET_VALUE
|
|
|
|
@hostname = UNSET_VALUE
|
|
|
|
@post_up_message = UNSET_VALUE
|
|
|
|
@provisioners = []
|
|
|
|
@usable_port_range = UNSET_VALUE
|
2012-12-23 19:02:51 +00:00
|
|
|
|
2013-02-05 20:22:00 +00:00
|
|
|
# Internal state
|
2013-04-10 17:44:53 +00:00
|
|
|
@__compiled_provider_configs = {}
|
|
|
|
@__defined_vm_keys = []
|
|
|
|
@__defined_vms = {}
|
|
|
|
@__finalized = false
|
|
|
|
@__networks = {}
|
|
|
|
@__providers = {}
|
2014-10-23 22:32:54 +00:00
|
|
|
@__provider_order = []
|
2013-04-20 05:16:09 +00:00
|
|
|
@__provider_overrides = {}
|
2013-04-10 17:44:53 +00:00
|
|
|
@__synced_folders = {}
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-08-29 00:17:07 +00:00
|
|
|
# This was from V1, but we just kept it here as an alias for hostname
|
|
|
|
# because too many people mess this up.
|
|
|
|
def host_name=(value)
|
|
|
|
@hostname = value
|
|
|
|
end
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
# Custom merge method since some keys here are merged differently.
|
|
|
|
def merge(other)
|
2013-02-05 20:22:00 +00:00
|
|
|
super.tap do |result|
|
2013-03-02 01:07:31 +00:00
|
|
|
other_networks = other.instance_variable_get(:@__networks)
|
|
|
|
|
|
|
|
result.instance_variable_set(:@__networks, @__networks.merge(other_networks))
|
2013-02-05 20:22:00 +00:00
|
|
|
|
2013-03-09 05:23:04 +00:00
|
|
|
# Merge defined VMs by first merging the defined VM keys,
|
|
|
|
# preserving the order in which they were defined.
|
|
|
|
other_defined_vm_keys = other.instance_variable_get(:@__defined_vm_keys)
|
|
|
|
other_defined_vm_keys -= @__defined_vm_keys
|
|
|
|
new_defined_vm_keys = @__defined_vm_keys + other_defined_vm_keys
|
|
|
|
|
|
|
|
# Merge the actual defined VMs.
|
|
|
|
other_defined_vms = other.instance_variable_get(:@__defined_vms)
|
|
|
|
new_defined_vms = {}
|
|
|
|
|
|
|
|
@__defined_vms.each do |key, subvm|
|
|
|
|
new_defined_vms[key] = subvm.clone
|
|
|
|
end
|
|
|
|
|
|
|
|
other_defined_vms.each do |key, subvm|
|
2015-01-05 23:29:01 +00:00
|
|
|
if !new_defined_vms.key?(key)
|
2013-03-09 05:23:04 +00:00
|
|
|
new_defined_vms[key] = subvm.clone
|
|
|
|
else
|
|
|
|
new_defined_vms[key].config_procs.concat(subvm.config_procs)
|
|
|
|
new_defined_vms[key].options.merge!(subvm.options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 20:22:00 +00:00
|
|
|
# Merge the providers by prepending any configuration blocks we
|
|
|
|
# have for providers onto the new configuration.
|
|
|
|
other_providers = other.instance_variable_get(:@__providers)
|
|
|
|
new_providers = @__providers.dup
|
|
|
|
other_providers.each do |key, blocks|
|
|
|
|
new_providers[key] ||= []
|
|
|
|
new_providers[key] += blocks
|
|
|
|
end
|
|
|
|
|
2014-10-23 22:32:54 +00:00
|
|
|
# Merge the provider ordering. Anything defined in our CURRENT
|
|
|
|
# scope is before anything else.
|
|
|
|
other_order = other.instance_variable_get(:@__provider_order)
|
|
|
|
new_order = @__provider_order.dup
|
|
|
|
new_order = (new_order + other_order).uniq
|
|
|
|
|
2013-04-20 05:16:09 +00:00
|
|
|
# Merge the provider overrides by appending them...
|
|
|
|
other_overrides = other.instance_variable_get(:@__provider_overrides)
|
|
|
|
new_overrides = @__provider_overrides.dup
|
|
|
|
other_overrides.each do |key, blocks|
|
|
|
|
new_overrides[key] ||= []
|
|
|
|
new_overrides[key] += blocks
|
|
|
|
end
|
|
|
|
|
2014-02-03 20:30:01 +00:00
|
|
|
# Merge provisioners. First we deal with overrides and making
|
|
|
|
# sure the ordering is good there. Then we merge them.
|
2014-02-03 21:03:20 +00:00
|
|
|
new_provs = []
|
|
|
|
other_provs = other.provisioners.dup
|
2014-02-03 20:30:01 +00:00
|
|
|
@provisioners.each do |p|
|
2017-06-13 18:26:12 +00:00
|
|
|
other_p = other_provs.find { |o| p.id == o.id }
|
|
|
|
if other_p
|
|
|
|
# There is an override. Take it.
|
|
|
|
other_p.config = p.config.merge(other_p.config)
|
|
|
|
other_p.run ||= p.run
|
|
|
|
next if !other_p.preserve_order
|
|
|
|
|
|
|
|
# We're preserving order, delete from other
|
|
|
|
p = other_p
|
|
|
|
other_provs.delete(other_p)
|
2014-02-03 20:30:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# There is an override, merge it into the
|
|
|
|
new_provs << p.dup
|
|
|
|
end
|
2014-02-03 21:03:20 +00:00
|
|
|
other_provs.each do |p|
|
2014-02-03 20:30:01 +00:00
|
|
|
new_provs << p.dup
|
|
|
|
end
|
|
|
|
result.instance_variable_set(:@provisioners, new_provs)
|
|
|
|
|
2013-04-10 17:44:53 +00:00
|
|
|
# Merge synced folders.
|
|
|
|
other_folders = other.instance_variable_get(:@__synced_folders)
|
2013-07-18 03:18:39 +00:00
|
|
|
new_folders = {}
|
|
|
|
@__synced_folders.each do |key, value|
|
|
|
|
new_folders[key] = value.dup
|
|
|
|
end
|
|
|
|
|
2013-04-10 17:44:53 +00:00
|
|
|
other_folders.each do |id, options|
|
|
|
|
new_folders[id] ||= {}
|
|
|
|
new_folders[id].merge!(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
result.instance_variable_set(:@__defined_vm_keys, new_defined_vm_keys)
|
|
|
|
result.instance_variable_set(:@__defined_vms, new_defined_vms)
|
2013-02-05 20:22:00 +00:00
|
|
|
result.instance_variable_set(:@__providers, new_providers)
|
2014-10-23 22:32:54 +00:00
|
|
|
result.instance_variable_set(:@__provider_order, new_order)
|
2013-04-20 05:16:09 +00:00
|
|
|
result.instance_variable_set(:@__provider_overrides, new_overrides)
|
2013-04-10 17:44:53 +00:00
|
|
|
result.instance_variable_set(:@__synced_folders, new_folders)
|
2013-02-05 20:22:00 +00:00
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-01-23 17:21:49 +00:00
|
|
|
# Defines a synced folder pair. This pair of folders will be synced
|
|
|
|
# to/from the machine. Note that if the machine you're using doesn't
|
|
|
|
# support multi-directional syncing (perhaps an rsync backed synced
|
|
|
|
# folder) then the host is always synced to the guest but guest data
|
|
|
|
# may not be synced back to the host.
|
|
|
|
#
|
|
|
|
# @param [String] hostpath Path to the host folder to share. If this
|
|
|
|
# is a relative path, it is relative to the location of the
|
|
|
|
# Vagrantfile.
|
|
|
|
# @param [String] guestpath Path on the guest to mount the shared
|
|
|
|
# folder.
|
|
|
|
# @param [Hash] options Additional options.
|
|
|
|
def synced_folder(hostpath, guestpath, options=nil)
|
2013-07-23 20:27:03 +00:00
|
|
|
if Vagrant::Util::Platform.windows?
|
|
|
|
# On Windows, Ruby just uses normal '/' for path seps, so
|
|
|
|
# just replace normal Windows style seps with Unix ones.
|
2013-07-28 05:21:37 +00:00
|
|
|
hostpath = hostpath.to_s.gsub("\\", "/")
|
2013-07-23 20:27:03 +00:00
|
|
|
end
|
|
|
|
|
2016-11-08 23:33:30 +00:00
|
|
|
if guestpath.is_a?(Hash)
|
|
|
|
options = guestpath
|
|
|
|
guestpath = nil
|
|
|
|
end
|
|
|
|
|
2013-01-23 17:21:49 +00:00
|
|
|
options ||= {}
|
2016-11-08 23:33:30 +00:00
|
|
|
|
|
|
|
if options.has_key?(:name)
|
|
|
|
synced_folder_name = options.delete(:name)
|
|
|
|
else
|
|
|
|
synced_folder_name = guestpath
|
|
|
|
end
|
|
|
|
|
2018-04-14 05:14:25 +00:00
|
|
|
options[:guestpath] = guestpath.to_s.gsub(/\/$/, '') if guestpath
|
2013-01-23 17:42:19 +00:00
|
|
|
options[:hostpath] = hostpath
|
2015-01-05 23:29:01 +00:00
|
|
|
options[:disabled] = false if !options.key?(:disabled)
|
2014-05-09 01:39:13 +00:00
|
|
|
options = (@__synced_folders[options[:guestpath]] || {}).
|
|
|
|
merge(options.dup)
|
|
|
|
|
2014-02-01 18:01:02 +00:00
|
|
|
# Make sure the type is a symbol
|
|
|
|
options[:type] = options[:type].to_sym if options[:type]
|
2013-01-23 17:21:49 +00:00
|
|
|
|
2016-11-08 23:33:30 +00:00
|
|
|
@__synced_folders[synced_folder_name] = options
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-01-05 01:48:54 +00:00
|
|
|
# Define a way to access the machine via a network. This exposes a
|
|
|
|
# high-level abstraction for networking that may not directly map
|
|
|
|
# 1-to-1 for every provider. For example, AWS has no equivalent to
|
|
|
|
# "port forwarding." But most providers will attempt to implement this
|
|
|
|
# in a way that behaves similarly.
|
|
|
|
#
|
|
|
|
# `type` can be one of:
|
|
|
|
#
|
|
|
|
# * `:forwarded_port` - A port that is accessible via localhost
|
|
|
|
# that forwards into the machine.
|
|
|
|
# * `:private_network` - The machine gets an IP that is not directly
|
|
|
|
# publicly accessible, but ideally accessible from this machine.
|
|
|
|
# * `:public_network` - The machine gets an IP on a shared network.
|
|
|
|
#
|
|
|
|
# @param [Symbol] type Type of network
|
2013-03-02 00:31:54 +00:00
|
|
|
# @param [Hash] options Options for the network.
|
2014-02-18 18:40:09 +00:00
|
|
|
def network(type, **options)
|
2013-09-05 21:26:53 +00:00
|
|
|
options = options.dup
|
2013-08-28 23:32:47 +00:00
|
|
|
options[:protocol] ||= "tcp"
|
2013-04-10 22:37:04 +00:00
|
|
|
|
2014-05-08 20:38:40 +00:00
|
|
|
# Convert to symbol to allow strings
|
|
|
|
type = type.to_sym
|
|
|
|
|
2013-04-10 22:37:04 +00:00
|
|
|
if !options[:id]
|
|
|
|
default_id = nil
|
|
|
|
|
|
|
|
if type == :forwarded_port
|
2016-02-14 11:16:24 +00:00
|
|
|
# For forwarded ports, set the default ID to be the
|
|
|
|
# concat of host_ip, proto and host_port. This would ensure Vagrant
|
|
|
|
# caters for port forwarding in an IP aliased environment where
|
|
|
|
# different host IP addresses are to be listened on the same port.
|
|
|
|
default_id = "#{options[:host_ip]}#{options[:protocol]}#{options[:host]}"
|
2013-04-10 22:37:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
options[:id] = default_id || SecureRandom.uuid
|
|
|
|
end
|
2013-03-02 01:02:53 +00:00
|
|
|
|
|
|
|
# Scope the ID by type so that different types can share IDs
|
2013-04-10 22:37:04 +00:00
|
|
|
id = options[:id]
|
2013-03-02 01:02:53 +00:00
|
|
|
id = "#{type}-#{id}"
|
|
|
|
|
|
|
|
# Merge in the previous settings if we have them.
|
2015-01-05 23:29:01 +00:00
|
|
|
if @__networks.key?(id)
|
2013-03-02 01:02:53 +00:00
|
|
|
options = @__networks[id][1].merge(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Merge in the latest settings and set the internal state
|
2013-03-16 05:14:04 +00:00
|
|
|
@__networks[id] = [type.to_sym, options]
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2012-11-08 04:38:41 +00:00
|
|
|
# Configures a provider for this VM.
|
|
|
|
#
|
|
|
|
# @param [Symbol] name The name of the provider.
|
2012-11-19 06:55:30 +00:00
|
|
|
def provider(name, &block)
|
2013-03-16 05:14:04 +00:00
|
|
|
name = name.to_sym
|
2013-02-05 20:22:00 +00:00
|
|
|
@__providers[name] ||= []
|
2013-04-20 05:16:09 +00:00
|
|
|
@__provider_overrides[name] ||= []
|
|
|
|
|
2014-10-23 22:32:54 +00:00
|
|
|
# Add the provider to the ordering list
|
|
|
|
@__provider_order << name
|
|
|
|
|
2013-04-20 05:16:09 +00:00
|
|
|
if block_given?
|
|
|
|
@__providers[name] << block if block_given?
|
|
|
|
|
|
|
|
# If this block takes two arguments, then we curry it and store
|
|
|
|
# the configuration override for use later.
|
|
|
|
if block.arity == 2
|
|
|
|
@__provider_overrides[name] << block.curry[Vagrant::Config::V2::DummyConfig.new]
|
|
|
|
end
|
|
|
|
end
|
2012-11-08 04:38:41 +00:00
|
|
|
end
|
|
|
|
|
2014-02-03 15:56:39 +00:00
|
|
|
def provision(name, **options, &block)
|
2014-10-24 01:40:14 +00:00
|
|
|
type = name
|
2015-01-05 23:29:01 +00:00
|
|
|
if options.key?(:type)
|
2014-10-24 01:40:14 +00:00
|
|
|
type = options.delete(:type)
|
|
|
|
else
|
|
|
|
name = nil
|
|
|
|
end
|
|
|
|
|
2015-01-05 23:29:01 +00:00
|
|
|
if options.key?(:id)
|
2014-10-24 01:40:14 +00:00
|
|
|
puts "Setting `id` on a provisioner is deprecated. Please use the"
|
|
|
|
puts "new syntax of `config.vm.provision \"name\", type: \"type\""
|
|
|
|
puts "where \"name\" is the replacement for `id`. This will be"
|
|
|
|
puts "fully removed in Vagrant 1.8."
|
|
|
|
|
|
|
|
name = id
|
|
|
|
end
|
2014-02-03 15:56:39 +00:00
|
|
|
|
|
|
|
prov = nil
|
2014-10-24 01:40:14 +00:00
|
|
|
if name
|
2014-10-24 01:47:03 +00:00
|
|
|
name = name.to_sym
|
2014-10-24 01:40:14 +00:00
|
|
|
prov = @provisioners.find { |p| p.name == name }
|
2014-02-03 15:56:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if !prov
|
2014-10-24 01:40:14 +00:00
|
|
|
prov = VagrantConfigProvisioner.new(name, type.to_sym)
|
2014-02-03 15:56:39 +00:00
|
|
|
@provisioners << prov
|
|
|
|
end
|
|
|
|
|
2014-04-09 22:30:29 +00:00
|
|
|
prov.preserve_order = !!options.delete(:preserve_order) if \
|
2015-01-05 23:29:01 +00:00
|
|
|
options.key?(:preserve_order)
|
|
|
|
prov.run = options.delete(:run) if options.key?(:run)
|
2014-02-03 15:56:39 +00:00
|
|
|
prov.add_config(options, &block)
|
|
|
|
nil
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def defined_vms
|
2013-03-09 05:23:04 +00:00
|
|
|
@__defined_vms
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# This returns the keys of the sub-vms in the order they were
|
|
|
|
# defined.
|
|
|
|
def defined_vm_keys
|
2013-03-09 05:23:04 +00:00
|
|
|
@__defined_vm_keys
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def define(name, options=nil, &block)
|
|
|
|
name = name.to_sym
|
|
|
|
options ||= {}
|
2013-09-05 21:26:53 +00:00
|
|
|
options = options.dup
|
2013-01-31 03:24:09 +00:00
|
|
|
options[:config_version] ||= "2"
|
2012-11-07 05:28:44 +00:00
|
|
|
|
|
|
|
# Add the name to the array of VM keys. This array is used to
|
|
|
|
# preserve the order in which VMs are defined.
|
2013-04-10 02:05:35 +00:00
|
|
|
@__defined_vm_keys << name if !@__defined_vm_keys.include?(name)
|
2012-11-07 05:28:44 +00:00
|
|
|
|
|
|
|
# Add the SubVM to the hash of defined VMs
|
2013-03-09 05:23:04 +00:00
|
|
|
if !@__defined_vms[name]
|
|
|
|
@__defined_vms[name] = VagrantConfigSubVM.new
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-03-09 05:23:04 +00:00
|
|
|
@__defined_vms[name].options.merge!(options)
|
|
|
|
@__defined_vms[name].config_procs << [options[:config_version], block] if block
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 20:22:00 +00:00
|
|
|
#-------------------------------------------------------------------
|
|
|
|
# Internal methods, don't call these.
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
def finalize!
|
2013-03-02 01:12:17 +00:00
|
|
|
# Defaults
|
2014-12-17 04:35:01 +00:00
|
|
|
@allowed_synced_folder_types = nil if @allowed_synced_folder_types == UNSET_VALUE
|
2014-02-05 23:35:37 +00:00
|
|
|
@base_mac = nil if @base_mac == UNSET_VALUE
|
2013-08-29 23:41:36 +00:00
|
|
|
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE
|
2014-04-10 02:53:57 +00:00
|
|
|
@box = nil if @box == UNSET_VALUE
|
2018-09-26 17:31:41 +00:00
|
|
|
@ignore_box_vagrantfile = false if @ignore_box_vagrantfile == UNSET_VALUE
|
2017-01-10 05:06:12 +00:00
|
|
|
|
2016-06-18 18:46:46 +00:00
|
|
|
if @box_check_update == UNSET_VALUE
|
|
|
|
@box_check_update = !present?(ENV["VAGRANT_BOX_UPDATE_CHECK_DISABLE"])
|
|
|
|
end
|
|
|
|
|
2013-11-27 03:34:41 +00:00
|
|
|
@box_download_ca_cert = nil if @box_download_ca_cert == UNSET_VALUE
|
2014-05-19 15:41:13 +00:00
|
|
|
@box_download_ca_path = nil if @box_download_ca_path == UNSET_VALUE
|
2013-12-02 06:45:08 +00:00
|
|
|
@box_download_checksum = nil if @box_download_checksum == UNSET_VALUE
|
|
|
|
@box_download_checksum_type = nil if @box_download_checksum_type == UNSET_VALUE
|
2013-11-26 00:51:22 +00:00
|
|
|
@box_download_client_cert = nil if @box_download_client_cert == UNSET_VALUE
|
2013-07-20 04:18:02 +00:00
|
|
|
@box_download_insecure = false if @box_download_insecure == UNSET_VALUE
|
2014-09-01 09:23:37 +00:00
|
|
|
@box_download_location_trusted = false if @box_download_location_trusted == UNSET_VALUE
|
2013-11-26 02:46:54 +00:00
|
|
|
@box_url = nil if @box_url == UNSET_VALUE
|
2014-04-03 02:45:49 +00:00
|
|
|
@box_version = nil if @box_version == UNSET_VALUE
|
2015-10-08 15:37:35 +00:00
|
|
|
@clone = nil if @clone == UNSET_VALUE
|
2014-03-11 05:59:25 +00:00
|
|
|
@communicator = nil if @communicator == UNSET_VALUE
|
2014-02-05 23:35:37 +00:00
|
|
|
@graceful_halt_timeout = 60 if @graceful_halt_timeout == UNSET_VALUE
|
2013-06-09 20:17:23 +00:00
|
|
|
@guest = nil if @guest == UNSET_VALUE
|
2013-03-02 01:12:17 +00:00
|
|
|
@hostname = nil if @hostname == UNSET_VALUE
|
2013-07-28 19:08:49 +00:00
|
|
|
@hostname = @hostname.to_s if @hostname
|
2014-04-09 21:57:16 +00:00
|
|
|
@post_up_message = "" if @post_up_message == UNSET_VALUE
|
2013-03-02 01:12:17 +00:00
|
|
|
|
2014-02-05 23:35:37 +00:00
|
|
|
if @usable_port_range == UNSET_VALUE
|
|
|
|
@usable_port_range = (2200..2250)
|
|
|
|
end
|
|
|
|
|
2014-12-17 19:49:04 +00:00
|
|
|
if @allowed_synced_folder_types
|
|
|
|
@allowed_synced_folder_types = Array(@allowed_synced_folder_types).map(&:to_sym)
|
|
|
|
end
|
|
|
|
|
2013-12-04 02:46:22 +00:00
|
|
|
# Make sure that the download checksum is a string and that
|
|
|
|
# the type is a symbol
|
|
|
|
@box_download_checksum = "" if !@box_download_checksum
|
2013-12-02 06:58:25 +00:00
|
|
|
if @box_download_checksum_type
|
|
|
|
@box_download_checksum_type = @box_download_checksum_type.to_sym
|
|
|
|
end
|
|
|
|
|
2013-11-26 05:57:20 +00:00
|
|
|
# Make sure the box URL is an array if it is set
|
2014-01-24 20:58:01 +00:00
|
|
|
@box_url = Array(@box_url) if @box_url
|
2013-11-26 05:57:20 +00:00
|
|
|
|
2014-04-21 03:53:29 +00:00
|
|
|
# Set the communicator properly
|
|
|
|
@communicator = @communicator.to_sym if @communicator
|
|
|
|
|
2013-06-09 20:17:23 +00:00
|
|
|
# Set the guest properly
|
|
|
|
@guest = @guest.to_sym if @guest
|
|
|
|
|
2012-11-07 05:28:44 +00:00
|
|
|
# If we haven't defined a single VM, then we need to define a
|
|
|
|
# default VM which just inherits the rest of the configuration.
|
|
|
|
define(DEFAULT_VM_NAME) if defined_vm_keys.empty?
|
2013-02-05 20:08:17 +00:00
|
|
|
|
2014-02-05 23:35:37 +00:00
|
|
|
# Make sure the SSH forwarding is added if it doesn't exist
|
2014-05-09 00:00:55 +00:00
|
|
|
if @communicator == :winrm
|
|
|
|
if !@__networks["forwarded_port-winrm"]
|
|
|
|
network :forwarded_port,
|
|
|
|
guest: 5985,
|
|
|
|
host: 55985,
|
|
|
|
host_ip: "127.0.0.1",
|
|
|
|
id: "winrm",
|
|
|
|
auto_correct: true
|
2015-11-23 17:51:12 +00:00
|
|
|
end
|
|
|
|
if !@__networks["forwarded_port-winrm-ssl"]
|
2014-12-11 18:55:49 +00:00
|
|
|
network :forwarded_port,
|
|
|
|
guest: 5986,
|
|
|
|
host: 55986,
|
|
|
|
host_ip: "127.0.0.1",
|
|
|
|
id: "winrm-ssl",
|
|
|
|
auto_correct: true
|
|
|
|
end
|
2016-05-04 00:04:25 +00:00
|
|
|
end
|
|
|
|
# forward SSH ports regardless of communicator
|
|
|
|
if !@__networks["forwarded_port-ssh"]
|
2014-02-05 23:35:37 +00:00
|
|
|
network :forwarded_port,
|
|
|
|
guest: 22,
|
|
|
|
host: 2222,
|
|
|
|
host_ip: "127.0.0.1",
|
|
|
|
id: "ssh",
|
|
|
|
auto_correct: true
|
|
|
|
end
|
|
|
|
|
2013-09-16 00:29:49 +00:00
|
|
|
# Clean up some network configurations
|
2014-02-05 23:35:37 +00:00
|
|
|
@__networks.values.each do |type, opts|
|
2013-09-16 00:29:49 +00:00
|
|
|
if type == :forwarded_port
|
|
|
|
opts[:guest] = opts[:guest].to_i if opts[:guest]
|
|
|
|
opts[:host] = opts[:host].to_i if opts[:host]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 20:08:17 +00:00
|
|
|
# Compile all the provider configurations
|
2013-02-05 20:22:00 +00:00
|
|
|
@__providers.each do |name, blocks|
|
2013-04-03 21:57:14 +00:00
|
|
|
# If we don't have any configuration blocks, then ignore it
|
|
|
|
next if blocks.empty?
|
|
|
|
|
2013-02-05 20:22:00 +00:00
|
|
|
# Find the configuration class for this provider
|
|
|
|
config_class = Vagrant.plugin("2").manager.provider_configs[name]
|
2013-04-03 21:57:14 +00:00
|
|
|
config_class ||= Vagrant::Config::V2::DummyConfig
|
2013-02-05 20:22:00 +00:00
|
|
|
|
|
|
|
# Load it up
|
2014-04-19 03:36:29 +00:00
|
|
|
config = config_class.new
|
2013-04-03 21:57:14 +00:00
|
|
|
|
2014-02-11 19:54:52 +00:00
|
|
|
begin
|
|
|
|
blocks.each do |b|
|
2014-04-19 03:36:29 +00:00
|
|
|
new_config = config_class.new
|
|
|
|
b.call(new_config, Vagrant::Config::V2::DummyConfig.new)
|
|
|
|
config = config.merge(new_config)
|
2014-02-11 19:54:52 +00:00
|
|
|
end
|
|
|
|
rescue Exception => e
|
2014-10-25 13:01:21 +00:00
|
|
|
@logger.error("Vagrantfile load error: #{e.message}")
|
2015-06-01 01:32:21 +00:00
|
|
|
@logger.error(e.inspect)
|
|
|
|
@logger.error(e.message)
|
2014-10-25 13:01:21 +00:00
|
|
|
@logger.error(e.backtrace.join("\n"))
|
|
|
|
|
2015-06-01 01:32:21 +00:00
|
|
|
line = "(unknown)"
|
|
|
|
if e.backtrace && e.backtrace[0]
|
|
|
|
line = e.backtrace[0].split(":")[1]
|
|
|
|
end
|
|
|
|
|
2014-02-11 19:54:52 +00:00
|
|
|
raise Vagrant::Errors::VagrantfileLoadError,
|
|
|
|
path: "<provider config: #{name}>",
|
2015-06-01 01:32:21 +00:00
|
|
|
line: line,
|
2014-10-25 13:01:21 +00:00
|
|
|
exception_class: e.class,
|
2014-02-11 19:54:52 +00:00
|
|
|
message: e.message
|
2013-04-03 21:57:14 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 20:08:17 +00:00
|
|
|
config.finalize!
|
2013-02-05 20:22:00 +00:00
|
|
|
|
|
|
|
# Store it for retrieval later
|
2013-04-03 21:57:14 +00:00
|
|
|
@__compiled_provider_configs[name] = config
|
2013-02-05 20:08:17 +00:00
|
|
|
end
|
2013-02-05 20:22:00 +00:00
|
|
|
|
2014-02-05 23:35:37 +00:00
|
|
|
# Finalize all the provisioners
|
2014-02-03 21:28:41 +00:00
|
|
|
@provisioners.each do |p|
|
|
|
|
p.config.finalize! if !p.invalid?
|
2014-04-09 22:28:44 +00:00
|
|
|
p.run = p.run.to_sym if p.run
|
2014-02-03 21:28:41 +00:00
|
|
|
end
|
|
|
|
|
2014-10-21 06:13:13 +00:00
|
|
|
current_dir_shared = false
|
2013-07-20 04:38:58 +00:00
|
|
|
@__synced_folders.each do |id, options|
|
2013-11-23 01:22:47 +00:00
|
|
|
if options[:nfs]
|
|
|
|
options[:type] = :nfs
|
|
|
|
end
|
|
|
|
|
2013-07-20 04:38:58 +00:00
|
|
|
# Ignore NFS on Windows
|
2013-11-23 01:22:47 +00:00
|
|
|
if options[:type] == :nfs && Vagrant::Util::Platform.windows?
|
|
|
|
options.delete(:type)
|
2013-07-20 04:38:58 +00:00
|
|
|
end
|
2014-10-21 06:13:13 +00:00
|
|
|
|
|
|
|
if options[:hostpath] == '.'
|
|
|
|
current_dir_shared = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if !current_dir_shared && !@__synced_folders["/vagrant"]
|
|
|
|
synced_folder(".", "/vagrant")
|
2013-07-20 04:38:58 +00:00
|
|
|
end
|
|
|
|
|
2013-02-05 20:22:00 +00:00
|
|
|
# Flag that we finalized
|
|
|
|
@__finalized = true
|
|
|
|
end
|
|
|
|
|
2018-03-14 14:41:04 +00:00
|
|
|
# This returns the compiled provider-specific configuration for the
|
2013-02-05 20:22:00 +00:00
|
|
|
# given provider.
|
|
|
|
#
|
|
|
|
# @param [Symbol] name Name of the provider.
|
|
|
|
def get_provider_config(name)
|
|
|
|
raise "Must finalize first." if !@__finalized
|
|
|
|
|
2013-02-06 05:33:00 +00:00
|
|
|
result = @__compiled_provider_configs[name]
|
|
|
|
|
|
|
|
# If no compiled configuration was found, then we try to just
|
|
|
|
# use the default configuration from the plugin.
|
|
|
|
if !result
|
|
|
|
config_class = Vagrant.plugin("2").manager.provider_configs[name]
|
|
|
|
if config_class
|
|
|
|
result = config_class.new
|
|
|
|
result.finalize!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2013-04-03 21:57:14 +00:00
|
|
|
# This returns a list of VM configurations that are overrides
|
|
|
|
# for this provider.
|
|
|
|
#
|
|
|
|
# @param [Symbol] name Name of the provider
|
|
|
|
# @return [Array<Proc>]
|
|
|
|
def get_provider_overrides(name)
|
2013-04-20 05:16:09 +00:00
|
|
|
(@__provider_overrides[name] || []).map do |p|
|
2013-04-03 21:57:14 +00:00
|
|
|
["2", p]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-19 01:10:32 +00:00
|
|
|
# This returns the list of networks configured.
|
|
|
|
def networks
|
2013-03-02 01:02:53 +00:00
|
|
|
@__networks.values
|
2013-02-19 01:10:32 +00:00
|
|
|
end
|
|
|
|
|
2013-04-10 17:44:53 +00:00
|
|
|
# This returns the list of synced folders
|
|
|
|
def synced_folders
|
|
|
|
@__synced_folders
|
|
|
|
end
|
|
|
|
|
2018-10-30 19:35:46 +00:00
|
|
|
def validate(machine, ignore_provider=nil)
|
2013-04-03 23:18:37 +00:00
|
|
|
errors = _detected_errors
|
2014-04-10 03:13:38 +00:00
|
|
|
|
2015-10-08 16:41:16 +00:00
|
|
|
if !box && !clone && !machine.provider_options[:box_optional]
|
2014-04-10 03:13:38 +00:00
|
|
|
errors << I18n.t("vagrant.config.vm.box_missing")
|
|
|
|
end
|
|
|
|
|
2015-10-08 15:37:35 +00:00
|
|
|
if box && clone
|
|
|
|
errors << I18n.t("vagrant.config.vm.clone_and_box")
|
|
|
|
end
|
|
|
|
|
2013-03-09 18:07:55 +00:00
|
|
|
errors << I18n.t("vagrant.config.vm.hostname_invalid_characters") if \
|
2014-05-08 16:10:13 +00:00
|
|
|
@hostname && @hostname !~ /^[a-z0-9][-.a-z0-9]*$/i
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2014-01-24 17:16:37 +00:00
|
|
|
if @box_version
|
2016-10-06 23:15:53 +00:00
|
|
|
@box_version.to_s.split(",").each do |v|
|
2014-01-24 17:16:37 +00:00
|
|
|
begin
|
|
|
|
Gem::Requirement.new(v.strip)
|
|
|
|
rescue Gem::Requirement::BadRequirementError
|
|
|
|
errors << I18n.t(
|
|
|
|
"vagrant.config.vm.bad_version", version: v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-27 05:10:33 +00:00
|
|
|
if box_download_ca_cert
|
|
|
|
path = Pathname.new(box_download_ca_cert).
|
|
|
|
expand_path(machine.env.root_path)
|
|
|
|
if !path.file?
|
|
|
|
errors << I18n.t(
|
|
|
|
"vagrant.config.vm.box_download_ca_cert_not_found",
|
|
|
|
path: box_download_ca_cert)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-19 15:41:13 +00:00
|
|
|
if box_download_ca_path
|
|
|
|
path = Pathname.new(box_download_ca_path).
|
|
|
|
expand_path(machine.env.root_path)
|
|
|
|
if !path.directory?
|
|
|
|
errors << I18n.t(
|
|
|
|
"vagrant.config.vm.box_download_ca_path_not_found",
|
|
|
|
path: box_download_ca_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-02 06:45:08 +00:00
|
|
|
if box_download_checksum_type
|
|
|
|
if box_download_checksum == ""
|
|
|
|
errors << I18n.t("vagrant.config.vm.box_download_checksum_blank")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if box_download_checksum != ""
|
|
|
|
errors << I18n.t("vagrant.config.vm.box_download_checksum_notblank")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-29 19:45:44 +00:00
|
|
|
used_guest_paths = Set.new
|
2013-04-10 17:44:53 +00:00
|
|
|
@__synced_folders.each do |id, options|
|
2013-03-29 19:45:44 +00:00
|
|
|
# If the shared folder is disabled then don't worry about validating it
|
|
|
|
next if options[:disabled]
|
|
|
|
|
2016-01-09 16:15:25 +00:00
|
|
|
guestpath = Pathname.new(options[:guestpath]) if options[:guestpath]
|
2013-03-29 19:45:44 +00:00
|
|
|
hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path)
|
|
|
|
|
2018-04-14 05:14:25 +00:00
|
|
|
if guestpath.to_s == "" && id.to_s == ""
|
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_requires_guestpath_or_name")
|
|
|
|
elsif guestpath.to_s != ""
|
2015-07-06 20:58:48 +00:00
|
|
|
if guestpath.relative? && guestpath.to_s !~ /^\w+:/
|
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_guestpath_relative",
|
2014-05-22 16:35:12 +00:00
|
|
|
path: options[:guestpath])
|
2015-07-06 20:58:48 +00:00
|
|
|
else
|
|
|
|
if used_guest_paths.include?(options[:guestpath])
|
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_guestpath_duplicate",
|
|
|
|
path: options[:guestpath])
|
|
|
|
end
|
2013-03-29 19:45:44 +00:00
|
|
|
|
2015-07-06 20:58:48 +00:00
|
|
|
used_guest_paths.add(options[:guestpath])
|
|
|
|
end
|
2013-03-29 19:45:44 +00:00
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
|
|
|
|
if !hostpath.directory? && !options[:create]
|
2013-01-18 20:33:37 +00:00
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
|
2014-05-22 16:35:12 +00:00
|
|
|
path: options[:hostpath])
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
2015-07-06 17:19:32 +00:00
|
|
|
if options[:type] == :nfs && !options[:nfs__quiet]
|
2013-02-08 23:34:04 +00:00
|
|
|
if options[:owner] || options[:group]
|
|
|
|
# Owner/group don't work with NFS
|
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group",
|
2014-05-22 16:35:12 +00:00
|
|
|
path: options[:hostpath])
|
2013-02-08 23:34:04 +00:00
|
|
|
end
|
|
|
|
end
|
2013-09-01 19:25:21 +00:00
|
|
|
|
|
|
|
if options[:mount_options] && !options[:mount_options].is_a?(Array)
|
|
|
|
errors << I18n.t("vagrant.config.vm.shared_folder_mount_options_array")
|
|
|
|
end
|
2013-09-01 19:27:15 +00:00
|
|
|
|
|
|
|
# One day remove this probably.
|
|
|
|
if options[:extra]
|
|
|
|
errors << "The 'extra' flag on synced folders is now 'mount_options'"
|
|
|
|
end
|
2013-02-08 23:34:04 +00:00
|
|
|
end
|
|
|
|
|
2013-03-02 01:20:31 +00:00
|
|
|
# Validate networks
|
|
|
|
has_fp_port_error = false
|
2013-08-28 23:32:47 +00:00
|
|
|
fp_used = Set.new
|
2013-04-02 22:00:18 +00:00
|
|
|
valid_network_types = [:forwarded_port, :private_network, :public_network]
|
2013-03-16 05:11:49 +00:00
|
|
|
|
2014-03-13 15:31:59 +00:00
|
|
|
port_range=(1..65535)
|
2013-03-02 01:20:31 +00:00
|
|
|
networks.each do |type, options|
|
2013-04-02 22:00:18 +00:00
|
|
|
if !valid_network_types.include?(type)
|
|
|
|
errors << I18n.t("vagrant.config.vm.network_type_invalid",
|
2014-05-22 16:35:12 +00:00
|
|
|
type: type.to_s)
|
2013-04-02 22:00:18 +00:00
|
|
|
end
|
|
|
|
|
2013-03-02 01:20:31 +00:00
|
|
|
if type == :forwarded_port
|
|
|
|
if !has_fp_port_error && (!options[:guest] || !options[:host])
|
|
|
|
errors << I18n.t("vagrant.config.vm.network_fp_requires_ports")
|
|
|
|
has_fp_port_error = true
|
|
|
|
end
|
2013-03-16 05:11:49 +00:00
|
|
|
|
|
|
|
if options[:host]
|
2016-02-14 11:16:24 +00:00
|
|
|
key = "#{options[:host_ip]}#{options[:protocol]}#{options[:host]}"
|
2013-08-28 23:32:47 +00:00
|
|
|
if fp_used.include?(key)
|
2013-03-16 05:11:49 +00:00
|
|
|
errors << I18n.t("vagrant.config.vm.network_fp_host_not_unique",
|
2014-05-22 16:35:12 +00:00
|
|
|
host: options[:host].to_s,
|
|
|
|
protocol: options[:protocol].to_s)
|
2013-03-16 05:11:49 +00:00
|
|
|
end
|
|
|
|
|
2013-08-28 23:32:47 +00:00
|
|
|
fp_used.add(key)
|
2013-03-16 05:11:49 +00:00
|
|
|
end
|
2014-03-13 15:31:59 +00:00
|
|
|
|
|
|
|
if !port_range.include?(options[:host]) || !port_range.include?(options[:guest])
|
|
|
|
errors << I18n.t("vagrant.config.vm.network_fp_invalid_port")
|
|
|
|
end
|
2013-03-02 01:20:31 +00:00
|
|
|
end
|
2013-06-09 20:46:46 +00:00
|
|
|
|
|
|
|
if type == :private_network
|
2014-04-02 22:19:36 +00:00
|
|
|
if options[:type] && options[:type].to_sym != :dhcp
|
2013-06-09 20:46:46 +00:00
|
|
|
if !options[:ip]
|
|
|
|
errors << I18n.t("vagrant.config.vm.network_ip_required")
|
|
|
|
end
|
|
|
|
end
|
2013-07-20 04:43:42 +00:00
|
|
|
|
2015-12-24 20:38:14 +00:00
|
|
|
if options[:ip] && options[:ip].end_with?(".1") && (options[:type] || "").to_sym != :dhcp
|
2014-02-03 11:02:14 +00:00
|
|
|
machine.ui.warn(I18n.t(
|
|
|
|
"vagrant.config.vm.network_ip_ends_in_one"))
|
2013-07-20 04:43:42 +00:00
|
|
|
end
|
2013-06-09 20:46:46 +00:00
|
|
|
end
|
2013-03-02 01:20:31 +00:00
|
|
|
end
|
|
|
|
|
2013-01-18 20:56:19 +00:00
|
|
|
# We're done with VM level errors so prepare the section
|
|
|
|
errors = { "vm" => errors }
|
|
|
|
|
2013-01-18 21:33:02 +00:00
|
|
|
# Validate only the _active_ provider
|
|
|
|
if machine.provider_config
|
2018-10-30 19:35:46 +00:00
|
|
|
if !ignore_provider
|
|
|
|
provider_errors = machine.provider_config.validate(machine)
|
|
|
|
if provider_errors
|
|
|
|
errors = Vagrant::Config::V2::Util.merge_errors(errors, provider_errors)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
machine.ui.warn(I18n.t("vagrant.config.vm.ignore_provider_config"))
|
2013-01-18 21:36:12 +00:00
|
|
|
end
|
2013-01-18 20:56:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Validate provisioners
|
|
|
|
@provisioners.each do |vm_provisioner|
|
2013-03-28 22:38:32 +00:00
|
|
|
if vm_provisioner.invalid?
|
2015-07-08 23:50:36 +00:00
|
|
|
name = vm_provisioner.name.to_s
|
|
|
|
name = vm_provisioner.type.to_s if name.empty?
|
2013-03-28 22:38:32 +00:00
|
|
|
errors["vm"] << I18n.t("vagrant.config.vm.provisioner_not_found",
|
2015-07-08 23:50:36 +00:00
|
|
|
name: name)
|
2013-03-28 22:38:32 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-01-18 20:56:19 +00:00
|
|
|
if vm_provisioner.config
|
|
|
|
provisioner_errors = vm_provisioner.config.validate(machine)
|
2013-01-18 21:36:12 +00:00
|
|
|
if provisioner_errors
|
|
|
|
errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
|
|
|
|
end
|
2013-01-18 20:56:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-30 16:58:19 +00:00
|
|
|
# If running from the Windows Subsystem for Linux, validate that configured
|
|
|
|
# hostpaths for synced folders are on DrvFs file systems, or the synced
|
|
|
|
# folder implementation explicitly supports non-DrvFs file system types
|
|
|
|
# within the WSL
|
|
|
|
if Vagrant::Util::Platform.wsl?
|
|
|
|
# Create a helper that will with the synced folders mixin
|
|
|
|
# from the builtin action to get the correct implementation
|
|
|
|
# to be used for each folder
|
|
|
|
sf_helper = Class.new do
|
|
|
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
|
|
|
end.new
|
|
|
|
folders = sf_helper.synced_folders(machine, config: self)
|
|
|
|
folders.each do |impl_name, data|
|
|
|
|
data.each do |_, fs|
|
|
|
|
hostpath = File.expand_path(fs[:hostpath], machine.env.root_path)
|
|
|
|
if !Vagrant::Util::Platform.wsl_drvfs_path?(hostpath)
|
|
|
|
sf_klass = sf_helper.plugins[impl_name.to_sym].first
|
|
|
|
if sf_klass.respond_to?(:wsl_allow_non_drvfs?) && sf_klass.wsl_allow_non_drvfs?
|
|
|
|
next
|
|
|
|
end
|
|
|
|
errors["vm"] << I18n.t("vagrant.config.vm.shared_folder_wsl_not_drvfs",
|
|
|
|
path: fs[:hostpath])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-11 04:05:29 +00:00
|
|
|
# Validate sub-VMs if there are any
|
|
|
|
@__defined_vms.each do |name, _|
|
2014-08-11 16:21:31 +00:00
|
|
|
if name =~ /[\[\]\{\}\/]/
|
2014-08-11 04:05:29 +00:00
|
|
|
errors["vm"] << I18n.t(
|
|
|
|
"vagrant.config.vm.name_invalid",
|
|
|
|
name: name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-18 20:56:19 +00:00
|
|
|
errors
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
2014-10-23 22:32:54 +00:00
|
|
|
|
|
|
|
def __providers
|
|
|
|
@__provider_order
|
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|