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