Integrate new action runner/registry into Vagrant::Environment
This commit is contained in:
parent
daf711fd80
commit
bbb8f0ac2c
|
@ -51,5 +51,4 @@ require 'vagrant/command'
|
|||
require 'vagrant/provisioners'
|
||||
require 'vagrant/systems'
|
||||
require 'vagrant/version'
|
||||
Vagrant::Action.builtin!
|
||||
Vagrant::Plugin.load!
|
||||
|
|
|
@ -1,117 +1,140 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
# Registers the builtin actions. These are locked away in a
|
||||
# method so that their definition can be deferred until after
|
||||
# all the necessary Vagrant libraries are loaded. Hopefully
|
||||
# in the future this will no longer be necessary with autoloading.
|
||||
def self.builtin!
|
||||
return
|
||||
# Registers the builtin actions with a specific registry.
|
||||
#
|
||||
# These are the pre-built action sequences that are shipped with
|
||||
# Vagrant itself.
|
||||
def self.builtin!(registry)
|
||||
# provision - Provisions a running VM
|
||||
register(:provision, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Provision
|
||||
end)
|
||||
registry.register(:provision) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Provision
|
||||
end
|
||||
end
|
||||
|
||||
# start - Starts a VM, assuming it already exists on the
|
||||
# environment.
|
||||
register(:start, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::CleanMachineFolder
|
||||
use VM::ClearForwardedPorts
|
||||
use VM::ForwardPorts
|
||||
use VM::Provision
|
||||
use VM::NFS
|
||||
use VM::ClearSharedFolders
|
||||
use VM::ShareFolders
|
||||
use VM::HostName
|
||||
use VM::Network
|
||||
use VM::Customize
|
||||
use VM::Modify
|
||||
use VM::Boot
|
||||
end)
|
||||
registry.register(:start) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::CleanMachineFolder
|
||||
use VM::ClearForwardedPorts
|
||||
use VM::ForwardPorts
|
||||
use VM::Provision
|
||||
use VM::NFS
|
||||
use VM::ClearSharedFolders
|
||||
use VM::ShareFolders
|
||||
use VM::HostName
|
||||
use VM::Network
|
||||
use VM::Customize
|
||||
use VM::Modify
|
||||
use VM::Boot
|
||||
end
|
||||
end
|
||||
|
||||
# halt - Halts the VM, attempting gracefully but then forcing
|
||||
# a restart if fails.
|
||||
register(:halt, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::DiscardState
|
||||
use VM::Halt
|
||||
end)
|
||||
registry.register(:halt) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::DiscardState
|
||||
use VM::Halt
|
||||
end
|
||||
end
|
||||
|
||||
# suspend - Suspends the VM
|
||||
register(:suspend, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Suspend
|
||||
end)
|
||||
registry.register(:suspend) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Suspend
|
||||
end
|
||||
end
|
||||
|
||||
# resume - Resume a VM
|
||||
register(:resume, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Resume
|
||||
end)
|
||||
registry.register(:resume) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::Resume
|
||||
end
|
||||
end
|
||||
|
||||
# reload - Halts then restarts the VM
|
||||
register(:reload, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt]
|
||||
use Action[:start]
|
||||
end)
|
||||
registry.register(:reload) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt]
|
||||
use Action[:start]
|
||||
end
|
||||
end
|
||||
|
||||
# up - Imports, prepares, then starts a fresh VM.
|
||||
register(:up, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::CheckBox
|
||||
use VM::Import
|
||||
use VM::MatchMACAddress
|
||||
use VM::CheckGuestAdditions
|
||||
use Action[:start]
|
||||
end)
|
||||
registry.register(:up) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use VM::CheckBox
|
||||
use VM::Import
|
||||
use VM::MatchMACAddress
|
||||
use VM::CheckGuestAdditions
|
||||
use Action[:start]
|
||||
end
|
||||
end
|
||||
|
||||
# destroy - Halts, cleans up, and destroys an existing VM
|
||||
register(:destroy, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt], :force => true
|
||||
use VM::ProvisionerCleanup
|
||||
use VM::ClearNFSExports
|
||||
use VM::Destroy
|
||||
use VM::CleanMachineFolder
|
||||
use VM::DestroyUnusedNetworkInterfaces
|
||||
end)
|
||||
registry.register(:destroy) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt], :force => true
|
||||
use VM::ProvisionerCleanup
|
||||
use VM::ClearNFSExports
|
||||
use VM::Destroy
|
||||
use VM::CleanMachineFolder
|
||||
use VM::DestroyUnusedNetworkInterfaces
|
||||
end
|
||||
end
|
||||
|
||||
# package - Export and package the VM
|
||||
register(:package, Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt]
|
||||
use VM::ClearForwardedPorts
|
||||
use VM::ClearSharedFolders
|
||||
use VM::Modify
|
||||
use VM::Export
|
||||
use VM::PackageVagrantfile
|
||||
use VM::Package
|
||||
end)
|
||||
registry.register(:package) do
|
||||
Builder.new do
|
||||
use VM::CheckAccessible
|
||||
use Action[:halt]
|
||||
use VM::ClearForwardedPorts
|
||||
use VM::ClearSharedFolders
|
||||
use VM::Modify
|
||||
use VM::Export
|
||||
use VM::PackageVagrantfile
|
||||
use VM::Package
|
||||
end
|
||||
end
|
||||
|
||||
# box_add - Download and add a box.
|
||||
register(:box_add, Builder.new do
|
||||
use Box::Download
|
||||
use Box::Unpackage
|
||||
use Box::Verify
|
||||
end)
|
||||
registry.register(:box_add) do
|
||||
Builder.new do
|
||||
use Box::Download
|
||||
use Box::Unpackage
|
||||
use Box::Verify
|
||||
end
|
||||
end
|
||||
|
||||
# box_remove - Removes/deletes a box.
|
||||
register(:box_remove, Builder.new do
|
||||
use Box::Destroy
|
||||
end)
|
||||
registry.register(:box_remove) do
|
||||
Builder.new do
|
||||
use Box::Destroy
|
||||
end
|
||||
end
|
||||
|
||||
# box_repackage - Repackages a box.
|
||||
register(:box_repackage, Builder.new do
|
||||
use Box::Package
|
||||
end)
|
||||
registry.register(:box_repackage) do
|
||||
Builder.new do
|
||||
use Box::Package
|
||||
end
|
||||
end
|
||||
|
||||
# Other callbacks. There will be more of these in the future. For
|
||||
# now, these are limited to what are needed internally.
|
||||
register(:before_action_run, Builder.new do
|
||||
# registry.register(:before_action_run, Builder.new do
|
||||
# use General::Validate
|
||||
end)
|
||||
# end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
require 'vagrant/util/hash_with_indifferent_access'
|
||||
|
||||
module Vagrant
|
||||
class Action
|
||||
# Represents an action environment which is what is passed
|
||||
# to the `call` method of each action. This environment contains
|
||||
# some helper methods for accessing the environment as well
|
||||
# as being a hash, to store any additional options.
|
||||
class Environment < Hash
|
||||
class Environment < Util::HashWithIndifferentAccess
|
||||
def initialize
|
||||
@interrupted = false
|
||||
end
|
||||
|
|
|
@ -216,7 +216,13 @@ module Vagrant
|
|||
#
|
||||
# @return [Action::Registry]
|
||||
def action_registry
|
||||
@action_registry ||= Action::Registry.new
|
||||
return @action_registry if defined?(@action_registry)
|
||||
|
||||
# The action registry hasn't been loaded yet, so load it
|
||||
# and setup the built-in actions with it.
|
||||
@action_registry = Action::Registry.new
|
||||
Vagrant::Action.builtin!(@action_registry)
|
||||
@action_registry
|
||||
end
|
||||
|
||||
# Loads on initial access and reads data from the global data store.
|
||||
|
|
|
@ -9,6 +9,11 @@ describe Vagrant::Action::Environment do
|
|||
instance["foo"].should == "bar"
|
||||
end
|
||||
|
||||
it "should be a hash accessible by string or symbol" do
|
||||
instance["foo"] = "bar"
|
||||
instance[:foo].should == "bar"
|
||||
end
|
||||
|
||||
it "should keep track of interrupted state" do
|
||||
instance.should_not be_interrupted
|
||||
instance.interrupt!
|
||||
|
|
|
@ -44,6 +44,18 @@ describe Vagrant::Environment do
|
|||
collection.directory.should == instance.boxes_path
|
||||
end
|
||||
|
||||
it "has an action runner" do
|
||||
instance.action_runner.should be_kind_of(Vagrant::Action::Runner)
|
||||
end
|
||||
|
||||
it "has an action registry" do
|
||||
instance.action_registry.should be_kind_of(Vagrant::Action::Registry)
|
||||
end
|
||||
|
||||
it "should have the built-in actions in the registry" do
|
||||
instance.action_registry.get(:provision).should_not be_nil
|
||||
end
|
||||
|
||||
describe "loading configuration" do
|
||||
it "should load global configuration" do
|
||||
environment = isolated_environment do |env|
|
||||
|
|
Loading…
Reference in New Issue