Somewhat ghetto callback system in place to handle validations now. This will definitely get looked at again in the near future.
This commit is contained in:
parent
82d73ebe3c
commit
f1a3c75bcb
|
@ -90,14 +90,18 @@ module Vagrant
|
||||||
# Any options given are injected into the environment hash.
|
# Any options given are injected into the environment hash.
|
||||||
#
|
#
|
||||||
# @param [Object] callable An object which responds to `call`.
|
# @param [Object] callable An object which responds to `call`.
|
||||||
def run(callable, options=nil)
|
def run(callable_id, options=nil)
|
||||||
callable = Builder.new.use(callable) if callable.kind_of?(Class)
|
callable = callable_id
|
||||||
callable = self.class.actions[callable] if callable.kind_of?(Symbol)
|
callable = Builder.new.use(callable_id) if callable_id.kind_of?(Class)
|
||||||
raise ArgumentError.new("Argument to run must be a callable object or registered action.") if !callable
|
callable = self.class.actions[callable_id] if callable_id.kind_of?(Symbol)
|
||||||
|
raise ArgumentError.new("Argument to run must be a callable object or registered action.") if !callable || !callable.respond_to?(:call)
|
||||||
|
|
||||||
action_environment = Action::Environment.new(env)
|
action_environment = Action::Environment.new(env)
|
||||||
action_environment.merge!(options || {})
|
action_environment.merge!(options || {})
|
||||||
|
|
||||||
|
# Run the before action run callback, if we're not doing that already
|
||||||
|
run(:before_action_run) if callable_id != :before_action_run
|
||||||
|
|
||||||
# Run the action chain in a busy block, marking the environment as
|
# Run the action chain in a busy block, marking the environment as
|
||||||
# interrupted if a SIGINT occurs, and exiting cleanly once the
|
# interrupted if a SIGINT occurs, and exiting cleanly once the
|
||||||
# chain has been run.
|
# chain has been run.
|
||||||
|
|
|
@ -6,15 +6,13 @@ module Vagrant
|
||||||
# in the future this will no longer be necessary with autoloading.
|
# in the future this will no longer be necessary with autoloading.
|
||||||
def self.builtin!
|
def self.builtin!
|
||||||
# provision - Provisions a running VM
|
# provision - Provisions a running VM
|
||||||
provision = Builder.new do
|
register(:provision, Builder.new do
|
||||||
use VM::Provision
|
use VM::Provision
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :provision, provision
|
|
||||||
|
|
||||||
# start - Starts a VM, assuming it already exists on the
|
# start - Starts a VM, assuming it already exists on the
|
||||||
# environment.
|
# environment.
|
||||||
start = Builder.new do
|
register(:start, Builder.new do
|
||||||
use VM::CleanMachineFolder
|
use VM::CleanMachineFolder
|
||||||
use VM::Customize
|
use VM::Customize
|
||||||
use VM::ClearForwardedPorts
|
use VM::ClearForwardedPorts
|
||||||
|
@ -25,104 +23,83 @@ module Vagrant
|
||||||
use VM::ShareFolders
|
use VM::ShareFolders
|
||||||
use VM::Network
|
use VM::Network
|
||||||
use VM::Boot
|
use VM::Boot
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :start, start
|
|
||||||
|
|
||||||
# halt - Halts the VM, attempting gracefully but then forcing
|
# halt - Halts the VM, attempting gracefully but then forcing
|
||||||
# a restart if fails.
|
# a restart if fails.
|
||||||
halt = Builder.new do
|
register(:halt, Builder.new do
|
||||||
use VM::DiscardState
|
use VM::DiscardState
|
||||||
use VM::Halt
|
use VM::Halt
|
||||||
use VM::DisableNetworks
|
use VM::DisableNetworks
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :halt, halt
|
|
||||||
|
|
||||||
# suspend - Suspends the VM
|
# suspend - Suspends the VM
|
||||||
suspend = Builder.new do
|
register(:suspend, Builder.new do
|
||||||
use VM::Suspend
|
use VM::Suspend
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :suspend, suspend
|
|
||||||
|
|
||||||
# resume - Resume a VM
|
# resume - Resume a VM
|
||||||
resume = Builder.new do
|
register(:resume, Builder.new do
|
||||||
use VM::Resume
|
use VM::Resume
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :resume, resume
|
|
||||||
|
|
||||||
# reload - Halts then restarts the VM
|
# reload - Halts then restarts the VM
|
||||||
reload = Builder.new do
|
register(:reload, Builder.new do
|
||||||
use Action[:halt]
|
use Action[:halt]
|
||||||
use Action[:start]
|
use Action[:start]
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :reload, reload
|
|
||||||
|
|
||||||
# up - Imports, prepares, then starts a fresh VM.
|
# up - Imports, prepares, then starts a fresh VM.
|
||||||
up = Builder.new do
|
register(:up, Builder.new do
|
||||||
use VM::CheckBox
|
use VM::CheckBox
|
||||||
use VM::Import
|
use VM::Import
|
||||||
use VM::MatchMACAddress
|
use VM::MatchMACAddress
|
||||||
use VM::CheckGuestAdditions
|
use VM::CheckGuestAdditions
|
||||||
use Action[:start]
|
use Action[:start]
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :up, up
|
|
||||||
|
|
||||||
# destroy - Halts, cleans up, and destroys an existing VM
|
# destroy - Halts, cleans up, and destroys an existing VM
|
||||||
destroy = Builder.new do
|
register(:destroy, Builder.new do
|
||||||
use Action[:halt], :force => true
|
use Action[:halt], :force => true
|
||||||
use VM::ClearNFSExports
|
use VM::ClearNFSExports
|
||||||
use VM::DestroyUnusedNetworkInterfaces
|
use VM::DestroyUnusedNetworkInterfaces
|
||||||
use VM::Destroy
|
use VM::Destroy
|
||||||
use VM::CleanMachineFolder
|
use VM::CleanMachineFolder
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :destroy, destroy
|
|
||||||
|
|
||||||
# package - Export and package the VM
|
# package - Export and package the VM
|
||||||
package = Builder.new do
|
register(:package, Builder.new do
|
||||||
use Action[:halt]
|
use Action[:halt]
|
||||||
use VM::ClearForwardedPorts
|
use VM::ClearForwardedPorts
|
||||||
use VM::ClearSharedFolders
|
use VM::ClearSharedFolders
|
||||||
use VM::Export
|
use VM::Export
|
||||||
use VM::PackageVagrantfile
|
use VM::PackageVagrantfile
|
||||||
use VM::Package
|
use VM::Package
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :package, package
|
|
||||||
|
|
||||||
# box_add - Download and add a box.
|
# box_add - Download and add a box.
|
||||||
box_add = Builder.new do
|
register(:box_add, Builder.new do
|
||||||
use Box::Download
|
use Box::Download
|
||||||
use Box::Unpackage
|
use Box::Unpackage
|
||||||
use Box::Verify
|
use Box::Verify
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :box_add, box_add
|
|
||||||
|
|
||||||
# box_remove - Removes/deletes a box.
|
# box_remove - Removes/deletes a box.
|
||||||
box_remove = Builder.new do
|
register(:box_remove, Builder.new do
|
||||||
use Box::Destroy
|
use Box::Destroy
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :box_remove, box_remove
|
|
||||||
|
|
||||||
# box_repackage - Repackages a box.
|
# box_repackage - Repackages a box.
|
||||||
box_repackage = Builder.new do
|
register(:box_repackage, Builder.new do
|
||||||
use Box::Package
|
use Box::Package
|
||||||
end
|
end)
|
||||||
|
|
||||||
register :box_repackage, box_repackage
|
# Other callbacks. There will be more of these in the future. For
|
||||||
|
# now, these are limited to what are needed internally.
|
||||||
# post_load - Called after environment is loaded
|
register :environment_load, Builder.new
|
||||||
environment_load = Builder.new do
|
register(:before_action_run, Builder.new do
|
||||||
end
|
use General::Validate
|
||||||
|
end)
|
||||||
register :environment_load, environment_load
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue