core: provisioners are defined differently now
This commit is contained in:
parent
9d8c85e966
commit
97f9948fce
|
@ -15,7 +15,7 @@ module Vagrant
|
|||
# Get all the configured provisioners
|
||||
@_provisioner_instances = env[:machine].config.vm.provisioners.map do |provisioner|
|
||||
# Instantiate the provisioner
|
||||
klass = Vagrant.plugin("2").manager.provisioners[provisioner.name]
|
||||
klass = Vagrant.plugin("2").manager.provisioners[provisioner.type]
|
||||
|
||||
# This can happen in the case the configuration isn't validated.
|
||||
next nil if !klass
|
||||
|
@ -23,12 +23,12 @@ module Vagrant
|
|||
result = klass.new(env[:machine], provisioner.config)
|
||||
|
||||
# Store in the type map so that --provision-with works properly
|
||||
@_provisioner_types[result] = provisioner.name
|
||||
@_provisioner_types[result] = provisioner.type
|
||||
|
||||
# Build up the options
|
||||
options = {
|
||||
id: provisioner.id,
|
||||
run: provisioner.run,
|
||||
name: provisioner.name,
|
||||
run: provisioner.run,
|
||||
}
|
||||
|
||||
# Return the result
|
||||
|
|
|
@ -104,7 +104,7 @@ module Vagrant
|
|||
type_name = type_map[p]
|
||||
next if env[:provision_types] && \
|
||||
!env[:provision_types].include?(type_name) && \
|
||||
!env[:provision_types].include?(options[:id]) &&
|
||||
!env[:provision_types].include?(options[:name])
|
||||
|
||||
# Don't run if sentinel is around and we're not always running
|
||||
next if !provision_enabled && options[:run] != :always
|
||||
|
|
|
@ -132,8 +132,8 @@ module VagrantPlugins
|
|||
new_provs = []
|
||||
other_provs = other.provisioners.dup
|
||||
@provisioners.each do |p|
|
||||
if p.id
|
||||
other_p = other_provs.find { |o| p.id == o.id }
|
||||
if p.name
|
||||
other_p = other_provs.find { |o| p.name == o.name }
|
||||
if other_p
|
||||
# There is an override. Take it.
|
||||
other_p.config = p.config.merge(other_p.config)
|
||||
|
@ -278,15 +278,29 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def provision(name, **options, &block)
|
||||
id = options.delete(:id).to_s if options.has_key?(:id)
|
||||
type = name
|
||||
if options.has_key?(:type)
|
||||
type = options.delete(:type)
|
||||
else
|
||||
name = nil
|
||||
end
|
||||
|
||||
if options.has_key?(:id)
|
||||
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
|
||||
|
||||
prov = nil
|
||||
if id
|
||||
prov = @provisioners.find { |p| p.id == id }
|
||||
if name
|
||||
prov = @provisioners.find { |p| p.name == name }
|
||||
end
|
||||
|
||||
if !prov
|
||||
prov = VagrantConfigProvisioner.new(id, name.to_sym)
|
||||
prov = VagrantConfigProvisioner.new(name, type.to_sym)
|
||||
@provisioners << prov
|
||||
end
|
||||
|
||||
|
|
|
@ -4,16 +4,16 @@ module VagrantPlugins
|
|||
module Kernel_V2
|
||||
# Represents a single configured provisioner for a VM.
|
||||
class VagrantConfigProvisioner
|
||||
# Unique ID name for this provisioner
|
||||
# Unique name for this provisioner
|
||||
#
|
||||
# @return [String]
|
||||
attr_reader :id
|
||||
attr_reader :name
|
||||
|
||||
# The name of the provisioner that should be registered
|
||||
# The type of the provisioner that should be registered
|
||||
# as a plugin.
|
||||
#
|
||||
# @return [Symbol]
|
||||
attr_reader :name
|
||||
attr_reader :type
|
||||
|
||||
# The configuration associated with the provisioner, if there is any.
|
||||
#
|
||||
|
@ -31,30 +31,30 @@ module VagrantPlugins
|
|||
# @return [Boolean]
|
||||
attr_accessor :preserve_order
|
||||
|
||||
def initialize(id, name)
|
||||
def initialize(name, type)
|
||||
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
||||
@logger.debug("Provisioner defined: #{name}")
|
||||
|
||||
@config = nil
|
||||
@id = id
|
||||
@invalid = false
|
||||
@name = name
|
||||
@preserve_order = false
|
||||
@run = nil
|
||||
@type = type
|
||||
|
||||
# Attempt to find the provisioner...
|
||||
if !Vagrant.plugin("2").manager.provisioners[name]
|
||||
@logger.warn("Provisioner '#{name}' not found.")
|
||||
if !Vagrant.plugin("2").manager.provisioners[type]
|
||||
@logger.warn("Provisioner '#{type}' not found.")
|
||||
@invalid = true
|
||||
end
|
||||
|
||||
# Attempt to find the configuration class for this provider
|
||||
# if it exists and load the configuration.
|
||||
@config_class = Vagrant.plugin("2").manager.
|
||||
provisioner_configs[@name]
|
||||
provisioner_configs[@type]
|
||||
if !@config_class
|
||||
@logger.info(
|
||||
"Provisioner config for '#{@name}' not found. Ignoring config.")
|
||||
"Provisioner config for '#{@type}' not found. Ignoring config.")
|
||||
@config_class = Vagrant::Config::V2::DummyConfig
|
||||
end
|
||||
end
|
||||
|
|
|
@ -341,8 +341,8 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
|||
end
|
||||
|
||||
it "allows provisioner settings to be overriden" do
|
||||
subject.provision("shell", path: "foo", id: "s") { |s| s.inline = "foo" }
|
||||
subject.provision("shell", inline: "bar", id: "s") { |s| s.args = "bar" }
|
||||
subject.provision("s", path: "foo", type: "shell") { |s| s.inline = "foo" }
|
||||
subject.provision("s", inline: "bar", type: "shell") { |s| s.args = "bar" }
|
||||
subject.finalize!
|
||||
|
||||
r = subject.provisioners
|
||||
|
@ -412,12 +412,12 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
|||
end
|
||||
|
||||
it "uses the proper order when merging overrides" do
|
||||
subject.provision("shell", inline: "foo", id: "original")
|
||||
subject.provision("shell", inline: "other", id: "other")
|
||||
subject.provision("original", inline: "foo", type: "shell")
|
||||
subject.provision("other", inline: "other", type: "shell")
|
||||
|
||||
other = described_class.new
|
||||
other.provision("shell", inline: "bar")
|
||||
other.provision("shell", inline: "foo-overload", id: "original")
|
||||
other.provision("original", inline: "foo-overload", type: "shell")
|
||||
|
||||
merged = subject.merge(other)
|
||||
merged_provs = merged.provisioners
|
||||
|
@ -432,13 +432,13 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
|||
end
|
||||
|
||||
it "can preserve order for overrides" do
|
||||
subject.provision("shell", inline: "foo", id: "original")
|
||||
subject.provision("shell", inline: "other", id: "other")
|
||||
subject.provision("original", inline: "foo", type: "shell")
|
||||
subject.provision("other", inline: "other", type: "shell")
|
||||
|
||||
other = described_class.new
|
||||
other.provision("shell", inline: "bar")
|
||||
other.provision(
|
||||
"shell", inline: "foo-overload", id: "original",
|
||||
"original", inline: "foo-overload", type: "shell",
|
||||
preserve_order: true)
|
||||
|
||||
merged = subject.merge(other)
|
||||
|
|
Loading…
Reference in New Issue