vagrant/plugins/kernel_v2/config/vm_provisioner.rb

79 lines
2.0 KiB
Ruby
Raw Normal View History

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
# Unique ID name for this provisioner
#
# @return [String]
attr_reader :id
# 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
def initialize(id, name)
2012-11-07 05:28:44 +00:00
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
@logger.debug("Provisioner defined: #{name}")
@config = nil
@id = id
@invalid = false
@name = name
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
# 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
@logger.info(
"Provisioner config for '#{@name}' not found. Ignoring config.")
2012-11-07 05:28:44 +00:00
end
end
2014-02-03 20:30:01 +00:00
def initialize_copy(orig)
super
@config = @config.dup if @config
end
def add_config(**options, &block)
return if invalid?
current = @config_class.new
current.set_options(options) if options
current.call(@config) if block
current = @config.merge(current) if @config
@config = current
end
def finalize!
return if invalid?
2012-11-07 05:28:44 +00:00
@config.finalize!
2012-11-07 05:28:44 +00:00
end
# 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