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-10-24 01:40:14 +00:00
|
|
|
# Unique name for this provisioner
|
2014-02-03 15:56:39 +00:00
|
|
|
#
|
|
|
|
# @return [String]
|
2014-10-24 01:40:14 +00:00
|
|
|
attr_reader :name
|
2014-02-03 15:56:39 +00:00
|
|
|
|
2017-06-13 18:26:12 +00:00
|
|
|
# Internal unique name for this provisioner
|
|
|
|
# Set to the given :name if exists, otherwise
|
|
|
|
# it's set as a UUID.
|
|
|
|
#
|
|
|
|
# Note: This is for internal use only.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_reader :id
|
|
|
|
|
2014-10-24 01:40:14 +00:00
|
|
|
# The type of the provisioner that should be registered
|
2013-01-14 00:02:48 +00:00
|
|
|
# as a plugin.
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
2014-10-24 01:40:14 +00:00
|
|
|
attr_reader :type
|
2013-01-14 00:02:48 +00:00
|
|
|
|
|
|
|
# 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-04-09 22:28:44 +00:00
|
|
|
# When to run this provisioner. Either "once" or "always"
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :run
|
|
|
|
|
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-10-24 01:40:14 +00:00
|
|
|
def initialize(name, type)
|
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}")
|
|
|
|
|
2017-06-13 18:26:12 +00:00
|
|
|
@id = name || SecureRandom.uuid
|
2013-03-28 22:38:32 +00:00
|
|
|
@config = nil
|
|
|
|
@invalid = false
|
|
|
|
@name = name
|
2014-02-03 21:03:20 +00:00
|
|
|
@preserve_order = false
|
2014-04-09 22:28:44 +00:00
|
|
|
@run = nil
|
2014-10-24 01:40:14 +00:00
|
|
|
@type = type
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2013-03-30 21:39:29 +00:00
|
|
|
# Attempt to find the provisioner...
|
2014-10-24 01:40:14 +00:00
|
|
|
if !Vagrant.plugin("2").manager.provisioners[type]
|
|
|
|
@logger.warn("Provisioner '#{type}' not found.")
|
2013-03-30 21:39:29 +00:00
|
|
|
@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.
|
2014-10-24 01:40:14 +00:00
|
|
|
provisioner_configs[@type]
|
2014-02-03 15:56:39 +00:00
|
|
|
if !@config_class
|
|
|
|
@logger.info(
|
2014-10-24 01:40:14 +00:00
|
|
|
"Provisioner config for '#{@type}' 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
|