lib/vagrant-skytap/action.rb in vagrant-skytap-0.1.6 vs lib/vagrant-skytap/action.rb in vagrant-skytap-0.1.7
- old
+ new
@@ -166,10 +166,15 @@
end
end
end
end
+ # Note: Provision and SyncedFolders perform actions before and after
+ # calling the next middleware in the sequence. Both require that
+ # the machine be booted before those calls return. This requirement
+ # can be satisfied by putting the WaitForCommunicator middleware
+ # later in the sequence.
def self.action_prepare_boot
Vagrant::Action::Builder.new.tap do |b|
b.use PrepareNFSSettings
b.use PrepareNFSValidIds
b.use Provision
@@ -178,16 +183,32 @@
end
end
def self.action_resume
Vagrant::Action::Builder.new.tap do |b|
- b.use action_up
+ Vagrant::Action::Builder.new.tap do |b|
+ b.use InitializeAPIClient
+ b.use FetchEnvironment
+ b.use Call, IsSuspended do |env, b1|
+ if env[:result]
+ b1.use MessageResuming
+ b1.use RunVm
+ b1.use WaitForCommunicator
+ end
+ end
+ end
end
end
- # This action is called to bring the box up from nothing.
- def self.action_up
+ # The Skytap provider has a modified "vagrant up" command which
+ # takes advantage of parallel runstate operations on Skytap
+ # environments. The create and update_hardware actions are
+ # separated from the run_vm action, so we can pass in the ids
+ # and initial states for all machines to be run, potentially
+ # with a single REST call.
+
+ def self.action_create
Vagrant::Action::Builder.new.tap do |b|
b.use HandleBox
b.use ConfigValidate
b.use InitializeAPIClient
b.use FetchEnvironment
@@ -202,42 +223,76 @@
next
end
b1.use StoreExtraData
b1.use SetUpVm
end
- b.use Call, IsRunning do |env, b1|
+ end
+ end
+
+ def self.action_update_hardware
+ Vagrant::Action::Builder.new.tap do |b|
+ b.use InitializeAPIClient
+ b.use FetchEnvironment
+ b.use Call, IsStopped do |env, b1|
if env[:result]
+ b1.use UpdateHardware
+ b1.use SetHostname
+ end
+ end
+ end
+ end
+
+ def self.action_run_vm
+ Vagrant::Action::Builder.new.tap do |b|
+ b.use InitializeAPIClient
+ b.use FetchEnvironment
+
+ # The "up" command stores the pre-run states to
+ # avoid a race condition when running multiple
+ # VMs in parallel -- we need to know which VMs
+ # are actually being powered on and need to
+ # have folders synced and provisioning run.
+ b.use Call, InitialState do |env, b1|
+ case env[:result]
+ when :running
b1.use MessageAlreadyRunning
next
+ when :suspended
+ b1.use MessageResuming
+ else
+ b1.use action_prepare_boot
end
-
- b1.use Call, IsStopped do |env2, b2|
+ b1.use Call, IsParallelized do |env2, b2|
if env2[:result]
- b2.use UpdateHardware
- b2.use SetHostname
- b2.use action_prepare_boot
+ # Note: RunEnvironment is a no-op after
+ # the first invocation.
+ b2.use RunEnvironment
+ else
+ b2.use RunVm
end
-
- b2.use RunVm
- b2.use WaitForCommunicator
end
end
+ b.use WaitForCommunicator
end
end
def self.action_reload
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use InitializeAPIClient
b.use FetchEnvironment
- b.use Call, ExistenceCheck do |env, b2|
+ b.use Call, ExistenceCheck do |env, b1|
case env[:result]
when :missing_environment, :missing_vm, :no_vms
- b2.use MessageNotCreated
+ b1.use MessageNotCreated
else
- b2.use action_halt
- b2.use action_up
+ b1.use action_halt
+ b1.use action_update_hardware
+ # We don't need to store the initial states
+ # before calling run_vm, because the default
+ # behavior is to treat the VMs as powered off.
+ b1.use action_run_vm
end
end
end
end
@@ -249,16 +304,19 @@
autoload :DeleteEnvironment, action_root.join("delete_environment")
autoload :DeleteVm, action_root.join("delete_vm")
autoload :ExistenceCheck, action_root.join("existence_check")
autoload :FetchEnvironment, action_root.join("fetch_environment")
autoload :InitializeAPIClient, action_root.join("initialize_api_client")
+ autoload :InitialState, action_root.join("initial_state")
+ autoload :IsParallelized, action_root.join("is_parallelized")
autoload :IsRunning, action_root.join("is_running")
autoload :IsStopped, action_root.join("is_stopped")
autoload :IsSuspended, action_root.join("is_suspended")
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
autoload :MessageAlreadyRunning, action_root.join("message_already_running")
autoload :MessageNotCreated, action_root.join("message_not_created")
autoload :MessageEnvironmentUrl, action_root.join("message_environment_url")
+ autoload :MessageResuming, action_root.join("message_resuming")
autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
autoload :ReadState, action_root.join("read_state")