Class: Vagrant::Action::VM::Customize

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/customize.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Customize

Returns a new instance of Customize.



5
6
7
# File 'lib/vagrant/action/vm/customize.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant/action/vm/customize.rb', line 9

def call(env)
  customizations = env[:vm].config.vm.customizations
  if !customizations.empty?
    env[:ui].info I18n.t("vagrant.actions.vm.customize.running")

    # Execute each customization command.
    customizations.each do |command|
      processed_command = command.collect do |arg|
        arg = env[:vm].uuid if arg == :id
        arg.to_s
      end

      result = env[:vm].driver.execute_command(processed_command)
      if result.exit_code != 0
        raise Errors::VMCustomizationFailed, {
          :command => processed_command.inspect,
          :error   => result.stderr
        }
      end
    end
  end

  @app.call(env)
end