VBoxManage customizations can run at different events [GH-1247]
This commit is contained in:
parent
a786bb53d0
commit
5f34a694f5
|
@ -5,6 +5,9 @@ FEATURES:
|
|||
- `vagrant help <command>` now works. [GH-1578]
|
||||
- Added `config.vm.box_download_insecure` to allor the box_url setting
|
||||
to point to an https site that won't be validated. [GH-1712]
|
||||
- VirtualBox VBoxManage customizations can now be specified to run
|
||||
pre-boot (the default and existing functionality, pre-import,
|
||||
or post-boot. [GH-1247]
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
|
|
|
@ -69,8 +69,9 @@ module VagrantPlugins
|
|||
b.use ForwardPorts
|
||||
b.use SetHostname
|
||||
b.use SaneDefaults
|
||||
b.use Customize
|
||||
b.use Customize, "pre-boot"
|
||||
b.use Boot
|
||||
b.use Customize, "post-boot"
|
||||
b.use CheckGuestAdditions
|
||||
end
|
||||
end
|
||||
|
@ -308,6 +309,7 @@ module VagrantPlugins
|
|||
# If the VM is NOT created yet, then do the setup steps
|
||||
if !env[:result]
|
||||
b2.use CheckAccessible
|
||||
b2.use Customize, "pre-import"
|
||||
b2.use Import
|
||||
b2.use MatchMACAddress
|
||||
end
|
||||
|
|
|
@ -2,14 +2,21 @@ module VagrantPlugins
|
|||
module ProviderVirtualBox
|
||||
module Action
|
||||
class Customize
|
||||
def initialize(app, env)
|
||||
def initialize(app, env, event)
|
||||
@app = app
|
||||
@event = event
|
||||
end
|
||||
|
||||
def call(env)
|
||||
customizations = env[:machine].provider_config.customizations
|
||||
customizations = []
|
||||
env[:machine].provider_config.customizations.each do |event, command|
|
||||
if event == @event
|
||||
customizations << command
|
||||
end
|
||||
end
|
||||
|
||||
if !customizations.empty?
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.customize.running")
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)
|
||||
|
||||
# Execute each customization command.
|
||||
customizations.each do |command|
|
||||
|
|
|
@ -52,8 +52,10 @@ module VagrantPlugins
|
|||
#
|
||||
# @param [Array] command An array of arguments to pass to
|
||||
# VBoxManage.
|
||||
def customize(command)
|
||||
@customizations << command
|
||||
def customize(*command)
|
||||
event = command.first.is_a?(String) ? command.shift : "pre-boot"
|
||||
command = command[0]
|
||||
@customizations << [event, command]
|
||||
end
|
||||
|
||||
# This defines a network adapter that will be added to the VirtualBox
|
||||
|
@ -78,6 +80,22 @@ module VagrantPlugins
|
|||
@name = nil if @name == UNSET_VALUE
|
||||
end
|
||||
|
||||
def validate(machine)
|
||||
errors = []
|
||||
|
||||
valid_events = ["pre-import", "pre-boot", "post-boot"]
|
||||
@customizations.each do |event, _|
|
||||
if !valid_events.include?(event)
|
||||
errors << I18n.t(
|
||||
"vagrant.virtualbox.config.invalid_event",
|
||||
event: event.to_s,
|
||||
valid_events: valid_events.join(", "))
|
||||
end
|
||||
end
|
||||
|
||||
{ "VitualBox Provider" => errors }
|
||||
end
|
||||
|
||||
def to_s
|
||||
"VirtualBox"
|
||||
end
|
||||
|
|
|
@ -40,6 +40,12 @@ en:
|
|||
run_file_not_found: |-
|
||||
The 'run_file' specified could not be found.
|
||||
|
||||
virtualbox:
|
||||
config:
|
||||
invalid_event: |-
|
||||
%{event} is not a valid event for customization. Valid events
|
||||
are: %{valid_events}
|
||||
|
||||
general:
|
||||
batch_unexpected_error: |-
|
||||
An unexpected error ocurred when executing the action on the
|
||||
|
@ -862,7 +868,7 @@ en:
|
|||
%{error}
|
||||
|
||||
Please fix this customization and try again.
|
||||
running: Running any VM customizations...
|
||||
running: Running '%{event}' VM customizations...
|
||||
destroy:
|
||||
destroying: Destroying VM and associated drives...
|
||||
destroy_network:
|
||||
|
|
Loading…
Reference in New Issue