Change middleware internals to make plugin lives easier [GH-684]

This commit is contained in:
Mitchell Hashimoto 2012-01-28 17:12:30 -08:00
parent fb89a6c0a5
commit 88ba3a3619
5 changed files with 146 additions and 128 deletions

View File

@ -1,5 +1,7 @@
## 0.9.4 (unreleased) ## 0.9.4 (unreleased)
- Important internal changes to middlewares that make plugin developer's
lives much easier. [GH-684]
- Match VM names that have parens, brackets, etc. - Match VM names that have parens, brackets, etc.
- Detect when the VirtualBox kernel module is not loaded and error. [GH-677] - Detect when the VirtualBox kernel module is not loaded and error. [GH-677]
- Set `:auto_config` to false on any networking option to not automatically - Set `:auto_config` to false on any networking option to not automatically

View File

@ -74,6 +74,12 @@ module Vagrant
autoload :Util, 'vagrant/util' autoload :Util, 'vagrant/util'
autoload :VM, 'vagrant/vm' autoload :VM, 'vagrant/vm'
# Returns a `Vagrant::Registry` object that contains all the built-in
# middleware stacks.
def self.actions
@actions ||= Vagrant::Action::Builtin.new
end
# The source root is the path to the root directory of # The source root is the path to the root directory of
# the Vagrant gem. # the Vagrant gem.
def self.source_root def self.source_root

View File

@ -1,8 +1,8 @@
require 'vagrant/action/builder' require 'vagrant/action/builder'
require 'vagrant/action/builtin'
module Vagrant module Vagrant
module Action module Action
autoload :Builtin, 'vagrant/action/builtin'
autoload :Environment, 'vagrant/action/environment' autoload :Environment, 'vagrant/action/environment'
autoload :Runner, 'vagrant/action/runner' autoload :Runner, 'vagrant/action/runner'
autoload :Warden, 'vagrant/action/warden' autoload :Warden, 'vagrant/action/warden'

View File

@ -1,12 +1,24 @@
module Vagrant module Vagrant
module Action module Action
# Registers the builtin actions with a specific registry. # A registry object containing the built-in middleware stacks.
# class Builtin < Registry
# These are the pre-built action sequences that are shipped with def initialize
# Vagrant itself. # Properly initialize the registry object
def self.builtin!(registry) super
# Register all the built-in stacks
register_builtin!
end
protected
def register_builtin!
# We do this so that the blocks below have a variable to access the
# outer registry.
registry = self
# provision - Provisions a running VM # provision - Provisions a running VM
registry.register(:provision) do register(:provision) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -16,7 +28,7 @@ module Vagrant
# start - Starts a VM, assuming it already exists on the # start - Starts a VM, assuming it already exists on the
# environment. # environment.
registry.register(:start) do register(:start) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -39,7 +51,7 @@ module Vagrant
# 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.
registry.register(:halt) do register(:halt) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -49,7 +61,7 @@ module Vagrant
end end
# suspend - Suspends the VM # suspend - Suspends the VM
registry.register(:suspend) do register(:suspend) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -58,7 +70,7 @@ module Vagrant
end end
# resume - Resume a VM # resume - Resume a VM
registry.register(:resume) do register(:resume) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -68,7 +80,7 @@ module Vagrant
end end
# reload - Halts then restarts the VM # reload - Halts then restarts the VM
registry.register(:reload) do register(:reload) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -78,7 +90,7 @@ module Vagrant
end end
# up - Imports, prepares, then starts a fresh VM. # up - Imports, prepares, then starts a fresh VM.
registry.register(:up) do register(:up) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -92,7 +104,7 @@ module Vagrant
end end
# destroy - Halts, cleans up, and destroys an existing VM # destroy - Halts, cleans up, and destroys an existing VM
registry.register(:destroy) do register(:destroy) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::CheckAccessible use VM::CheckAccessible
@ -106,7 +118,7 @@ module Vagrant
end end
# package - Export and package the VM # package - Export and package the VM
registry.register(:package) do register(:package) do
Builder.new do Builder.new do
use General::Validate use General::Validate
use VM::SetupPackageFiles use VM::SetupPackageFiles
@ -121,7 +133,7 @@ module Vagrant
end end
# box_add - Download and add a box. # box_add - Download and add a box.
registry.register(:box_add) do register(:box_add) do
Builder.new do Builder.new do
use Box::Download use Box::Download
use Box::Unpackage use Box::Unpackage
@ -130,18 +142,19 @@ module Vagrant
end end
# box_remove - Removes/deletes a box. # box_remove - Removes/deletes a box.
registry.register(:box_remove) do register(:box_remove) do
Builder.new do Builder.new do
use Box::Destroy use Box::Destroy
end end
end end
# box_repackage - Repackages a box. # box_repackage - Repackages a box.
registry.register(:box_repackage) do register(:box_repackage) do
Builder.new do Builder.new do
use Box::Package use Box::Package
end end
end end
end end
end end
end
end end

View File

@ -197,13 +197,10 @@ module Vagrant
# #
# @return [Registry] # @return [Registry]
def action_registry def action_registry
return @action_registry if defined?(@action_registry) # For now we return the global built-in actions registry. In the future
# we may want to create an isolated registry that inherits from this
# The action registry hasn't been loaded yet, so load it # global one, but for now there isn't a use case that calls for it.
# and setup the built-in actions with it. Vagrant.actions
@action_registry = Registry.new
Vagrant::Action.builtin!(@action_registry)
@action_registry
end end
# Loads on initial access and reads data from the global data store. # Loads on initial access and reads data from the global data store.