2012-08-15 04:12:41 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
|
|
|
class Customize
|
2013-07-23 19:56:40 +00:00
|
|
|
def initialize(app, env, event)
|
2012-08-15 04:12:41 +00:00
|
|
|
@app = app
|
2013-07-23 19:56:40 +00:00
|
|
|
@event = event
|
2012-08-15 04:12:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2013-07-23 19:56:40 +00:00
|
|
|
customizations = []
|
|
|
|
env[:machine].provider_config.customizations.each do |event, command|
|
|
|
|
if event == @event
|
|
|
|
customizations << command
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-15 04:12:41 +00:00
|
|
|
if !customizations.empty?
|
2013-07-23 19:56:40 +00:00
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)
|
2012-08-15 04:12:41 +00:00
|
|
|
|
|
|
|
# Execute each customization command.
|
|
|
|
customizations.each do |command|
|
|
|
|
processed_command = command.collect do |arg|
|
|
|
|
arg = env[:machine].id if arg == :id
|
|
|
|
arg.to_s
|
|
|
|
end
|
|
|
|
|
2013-11-09 23:16:47 +00:00
|
|
|
begin
|
|
|
|
env[:machine].provider.driver.execute_command(processed_command + [:retryable => true])
|
|
|
|
rescue Vagrant::Errors::VBoxManageError => e
|
2012-12-23 06:47:06 +00:00
|
|
|
raise Vagrant::Errors::VMCustomizationFailed, {
|
2013-11-09 23:16:47 +00:00
|
|
|
:command => command,
|
|
|
|
:error => e.inspect
|
2012-08-15 04:12:41 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|