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
|
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]
|
2012-11-07 05:28:44 +00:00
|
|
|
attr_reader :config
|
|
|
|
|
2013-01-14 00:02:48 +00:00
|
|
|
def initialize(name, options=nil, &block)
|
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
|
|
|
|
@invalid = false
|
|
|
|
@name = name
|
2012-11-07 05:28:44 +00:00
|
|
|
|
2013-01-14 00:02:48 +00:00
|
|
|
# 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]
|
|
|
|
if !config_class
|
2013-03-28 22:38:32 +00:00
|
|
|
@invalid = true
|
2013-01-14 00:02:48 +00:00
|
|
|
@logger.info("Provisioner config for '#{@name}' not found. Ignoring config.")
|
|
|
|
return
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@config = config_class.new
|
|
|
|
@config.set_options(options) if options
|
|
|
|
block.call(@config) if block
|
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
|