Class: Vagrant::Config::VMConfig::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/config/vm/provisioner.rb

Overview

Represents a single configured provisioner for a VM.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shortcut, options = nil, &block) ⇒ Provisioner

Returns a new instance of Provisioner.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant/config/vm/provisioner.rb', line 12

def initialize(shortcut, options=nil, &block)
  @logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
  @logger.debug("Provisioner config: #{shortcut}")
  @shortcut = shortcut
  @provisioner = shortcut
  @provisioner = Vagrant.provisioners.get(shortcut) if shortcut.is_a?(Symbol)
  @config = nil

  @logger.info("Provisioner class: #{provisioner}")
  configure(options, &block) if @provisioner
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/vagrant/config/vm/provisioner.rb', line 10

def config
  @config
end

#provisionerObject (readonly)

Returns the value of attribute provisioner.



9
10
11
# File 'lib/vagrant/config/vm/provisioner.rb', line 9

def provisioner
  @provisioner
end

#shortcutObject (readonly)

Returns the value of attribute shortcut.



8
9
10
# File 'lib/vagrant/config/vm/provisioner.rb', line 8

def shortcut
  @shortcut
end

Instance Method Details

#configure(options = nil, &block) ⇒ Object

Configures the provisioner if it can (if it is valid).



25
26
27
28
29
30
31
32
33
# File 'lib/vagrant/config/vm/provisioner.rb', line 25

def configure(options=nil, &block)
  config_class = @provisioner.config_class
  return if !config_class

  @logger.debug("Configuring provisioner with: #{config_class}")
  @config = config_class.new
  @config.set_options(options) if options
  block.call(@config) if block
end

#validate(env, errors) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant/config/vm/provisioner.rb', line 35

def validate(env, errors)
  if !provisioner
    # If we don't have a provisioner then the whole thing is invalid.
    errors.add(I18n.t("vagrant.config.vm.provisioner_not_found", :shortcut => shortcut))
    return
  end

  if !(provisioner <= Provisioners::Base)
    errors.add(I18n.t("vagrant.config.vm.provisioner_invalid_class", :shortcut => shortcut))
  end

  # Pass on validation to the provisioner config
  config.validate(env, errors) if config
end