2012-11-07 05:28:44 +00:00
|
|
|
require 'log4r'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Kernel_V2
|
|
|
|
# Represents a single configured provisioner for a VM.
|
|
|
|
class VagrantConfigProvisioner
|
2014-02-03 15:56:39 +00:00
|
|
|
# Unique ID name for this provisioner
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_reader :id
|
|
|
|
|
2013-01-14 00:02:48 +00:00
|
|
|
# The name of the provisioner that should be registered
|
|
|
|
# as a plugin.
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
# The configuration associated with the provisioner, if there is any.
|
|
|
|
#
|
|
|
|
# @return [Object]
|
2014-02-03 20:30:01 +00:00
|
|
|
attr_accessor :config
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2014-02-03 21:03:20 +00:00
|
|
|
# Whether or not to preserve the order when merging this with a
|
|
|
|
# parent scope.
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :preserve_order
|
|
|
|
|
2014-02-03 15:56:39 +00:00
|
|
|
def initialize(id, name)
|
2012-11-07 05:28:44 +00:00
|
|
|
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
2013-01-14 00:02:48 +00:00
|
|
|
@logger.debug("Provisioner defined: #{name}")
|
|
|
|
|
2013-03-28 22:38:32 +00:00
|
|
|
@config = nil
|
2014-02-03 15:56:39 +00:00
|
|
|
@id = id
|
2013-03-28 22:38:32 +00:00
|
|
|
@invalid = false
|
|
|
|
@name = name
|
2014-02-03 21:03:20 +00:00
|
|
|
@preserve_order = false
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2013-03-30 21:39:29 +00:00
|
|
|
# Attempt to find the provisioner...
|
|
|
|
if !Vagrant.plugin("2").manager.provisioners[name]
|
|
|
|
@logger.warn("Provisioner '#{name}' not found.")
|
|
|
|
@invalid = true
|
|
|
|
end
|
|
|
|
|
2013-01-14 00:02:48 +00:00
|
|
|
# Attempt to find the configuration class for this provider
|
|
|
|
# if it exists and load the configuration.
|
2014-02-03 15:56:39 +00:00
|
|
|
@config_class = Vagrant.plugin("2").manager.
|
|
|
|
provisioner_configs[@name]
|
|
|
|
if !@config_class
|
|
|
|
@logger.info(
|
|
|
|
"Provisioner config for '#{@name}' not found. Ignoring config.")
|
2014-03-18 18:36:40 +00:00
|
|
|
@config_class = Vagrant::Config::V2::DummyConfig
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
2014-02-03 15:56:39 +00:00
|
|
|
end
|
|
|
|
|
2014-02-03 20:30:01 +00:00
|
|
|
def initialize_copy(orig)
|
|
|
|
super
|
|
|
|
@config = @config.dup if @config
|
|
|
|
end
|
|
|
|
|
2014-02-03 15:56:39 +00:00
|
|
|
def add_config(**options, &block)
|
|
|
|
return if invalid?
|
|
|
|
|
|
|
|
current = @config_class.new
|
|
|
|
current.set_options(options) if options
|
2014-02-04 03:41:11 +00:00
|
|
|
block.call(current) if block
|
2014-02-03 15:56:39 +00:00
|
|
|
current = @config.merge(current) if @config
|
|
|
|
@config = current
|
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
return if invalid?
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2013-01-14 00:02:48 +00:00
|
|
|
@config.finalize!
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
2013-03-28 22:38:32 +00:00
|
|
|
|
|
|
|
# Returns whether the provisioner used was invalid or not. A provisioner
|
|
|
|
# is invalid if it can't be found.
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def invalid?
|
|
|
|
@invalid
|
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|