Returns the configuration for a single machine.
When loading a box Vagrantfile, it will be
prepended to the key order specified when initializing this class.
Sub-machine and provider-specific overrides are appended at the end. The
actual order is:
The return value is a hash with the following keys (symbols) and values:
- box: the {Box} backing the machine
- config: the actual configuration
- config_errors: list of errors, if any
- config_warnings: list of warnings, if any
- provider_cls: class of the provider backing the machine
- provider_options: options for the provider
@param [Symbol] name Name of the machine. @param [Symbol] provider The
provider the machine should
be backed by (required for provider overrides).
@param [BoxCollection] boxes BoxCollection
to look up the
box Vagrantfile.
@return [Hash<Symbol, Object>] Various configuration parameters for a
machine. See the main documentation body for more info.
def machine_config(name, provider, boxes)
keys = @keys.dup
sub_machine = @config.vm.defined_vms[name]
if !sub_machine
raise Errors::MachineNotFound,
:name => name, :provider => provider
end
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
if !provider_plugin
raise Errors::ProviderNotFound,
:machine => name, :provider => provider
end
provider_cls = provider_plugin[0]
provider_options = provider_plugin[1]
box_formats = provider_options[:box_format] || provider
vm_config_key = "#{object_id}_machine_#{name}"
@loader.set(vm_config_key, sub_machine.config_procs)
keys << vm_config_key
config, config_warnings, config_errors = @loader.load(keys)
box = nil
original_box = config.vm.box
load_box_proc = lambda do
local_keys = keys.dup
if config.vm.box
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
if box
box_vagrantfile = find_vagrantfile(box.directory)
if box_vagrantfile
box_config_key =
"#{boxes.object_id}_#{box.name}_#{box.provider}".to_sym
@loader.set(box_config_key, box_vagrantfile)
local_keys.unshift(box_config_key)
config, config_warnings, config_errors = @loader.load(local_keys)
end
end
end
provider_overrides = config.vm.get_provider_overrides(provider)
if !provider_overrides.empty?
config_key =
"#{object_id}_vm_#{name}_#{config.vm.box}_#{provider}".to_sym
@loader.set(config_key, provider_overrides)
local_keys << config_key
config, config_warnings, config_errors = @loader.load(local_keys)
end
if original_box != config.vm.box
original_box = config.vm.box
load_box_proc.call
end
end
load_box_proc.call
return {
box: box,
provider_cls: provider_cls,
provider_options: provider_options,
config: config,
config_warnings: config_warnings,
config_errors: config_errors,
}
end