require "pathname" require "vagrant/action/builder" module VagrantPlugins module Skytap module Action include Vagrant::Action::Builtin # This action is called to halt the remote machine. def self.action_halt Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env1, b1| case result = env1[:result] when :missing_environment, :missing_vm, :no_vms b1.use MessageNotCreated else b1.use StopVm end end end end # This action is called to suspend the remote machine. def self.action_suspend Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env1, b1| case result = env1[:result] when :missing_environment, :missing_vm, :no_vms b1.use MessageNotCreated else b1.use SuspendVm end end end end # This action is called to terminate the remote machine. def self.action_destroy Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env, b1| case existence_state = env[:result] when :missing_environment, :no_vms b1.use MessageNotCreated b1.use DeleteEnvironment next when :missing_vm b1.use MessageNotCreated b1.use DeleteVm next end b1.use Call, DestroyConfirm do |env2, b2| if env2[:result] case existence_state when :one_of_many_vms b2.use DeleteVm else b2.use DeleteEnvironment end b2.use ProvisionerCleanup if defined?(ProvisionerCleanup) else b2.use MessageWillNotDestroy end end end b.use PrepareNFSValidIds b.use SyncedFolderCleanup end end # This action is called when `vagrant provision` is called. def self.action_provision Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env, b1| case result = env[:result] when :missing_environment, :missing_vm, :no_vms b1.use MessageNotCreated next end b1.use Call, IsStopped do |env2, b2| b2.use Call, IsRunning do |env3, b3| b3.use RunVm unless env3[:result] end was_stopped = env2[:result] if was_stopped b2.use PrepareNFSSettings b2.use PrepareNFSValidIds end b2.use Provision if was_stopped b2.use SyncedFolders end end end end end # This action is called to read the SSH info of the machine. The # resulting state is expected to be put into the `:machine_ssh_info` # key. def self.action_read_ssh_info Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use ReadSSHInfo end end # This action is called to read the state of the machine. The # resulting state is expected to be put into the `:machine_state_id` # key. def self.action_read_state Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment #TODO:NLA Can this whole action be removed? b.use ReadState end end # This action is called to SSH into the machine. def self.action_ssh Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env1, b1| case result = env1[:result] when :missing_environment, :missing_vm, :no_vms b1.use MessageNotCreated else b1.use SSHExec end end end end def self.action_ssh_run Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env1, b1| case result = env1[:result] when :missing_environment, :missing_vm, :no_vms b1.use MessageNotCreated else b1.use SSHRun end end end end def self.action_prepare_boot Vagrant::Action::Builder.new.tap do |b| b.use PrepareNFSSettings b.use PrepareNFSValidIds b.use Provision b.use SyncedFolderCleanup b.use SyncedFolders end end def self.action_resume Vagrant::Action::Builder.new.tap do |b| b.use action_up end end # This action is called to bring the box up from nothing. def self.action_up Vagrant::Action::Builder.new.tap do |b| b.use HandleBox b.use ConfigValidate b.use InitializeAPIClient b.use FetchEnvironment b.use Call, ExistenceCheck do |env, b1| case result = env[:result] when :missing_environment b1.use CreateEnvironment b1.use MessageEnvironmentUrl when :no_vms, :missing_vm b1.use AddVmToEnvironment else next end b1.use StoreExtraData b1.use SetUpVm end b.use Call, IsRunning do |env, b1| if env[:result] b1.use MessageAlreadyRunning next end b1.use Call, IsStopped do |env2, b2| if env2[:result] b2.use UpdateHardware b2.use SetHostname b2.use action_prepare_boot end b2.use RunVm end end 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| case env[:result] when :missing_environment, :missing_vm, :no_vms b2.use MessageNotCreated else b2.use action_halt b2.use action_up end end end end # The autoload farm action_root = Pathname.new(File.expand_path("../action", __FILE__)) autoload :StoreExtraData, action_root.join("store_extra_data") autoload :AddVmToEnvironment, action_root.join("add_vm_to_environment") autoload :CreateEnvironment, action_root.join("create_environment") 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 :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 :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") autoload :RunEnvironment, action_root.join("run_environment") autoload :RunVm, action_root.join("run_vm") autoload :SetHostname, action_root.join("set_hostname") autoload :SetUpVm, action_root.join("set_up_vm") autoload :StopVm, action_root.join("stop_vm") autoload :SuspendVm, action_root.join("suspend_vm") autoload :TimedProvision, action_root.join("timed_provision") # some plugins now expect this action to exist autoload :UpdateHardware, action_root.join("update_hardware") end end end