2012-07-27 05:39:27 +00:00
|
|
|
require "vagrant/action/builder"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
2012-08-14 03:03:35 +00:00
|
|
|
autoload :Boot, File.expand_path("../action/boot", __FILE__)
|
2012-07-27 05:39:27 +00:00
|
|
|
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
2012-08-05 20:45:24 +00:00
|
|
|
autoload :CheckCreated, File.expand_path("../action/check_created", __FILE__)
|
2012-08-15 05:38:41 +00:00
|
|
|
autoload :CheckGuestAdditions, File.expand_path("../action/check_guest_additions", __FILE__)
|
2012-08-05 20:45:24 +00:00
|
|
|
autoload :CheckRunning, File.expand_path("../action/check_running", __FILE__)
|
2012-07-27 05:39:27 +00:00
|
|
|
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
|
2012-08-14 06:31:12 +00:00
|
|
|
autoload :CleanMachineFolder, File.expand_path("../action/clean_machine_folder", __FILE__)
|
2012-08-15 04:12:41 +00:00
|
|
|
autoload :ClearForwardedPorts, File.expand_path("../action/clear_forwarded_ports", __FILE__)
|
|
|
|
autoload :ClearNetworkInterfaces, File.expand_path("../action/clear_network_interfaces", __FILE__)
|
2012-07-27 06:56:47 +00:00
|
|
|
autoload :Created, File.expand_path("../action/created", __FILE__)
|
2012-08-15 04:12:41 +00:00
|
|
|
autoload :Customize, File.expand_path("../action/customize", __FILE__)
|
2012-08-14 06:31:12 +00:00
|
|
|
autoload :Destroy, File.expand_path("../action/destroy", __FILE__)
|
|
|
|
autoload :DestroyUnusedNetworkInterfaces, File.expand_path("../action/destroy_unused_network_interfaces", __FILE__)
|
2012-08-04 18:16:31 +00:00
|
|
|
autoload :DiscardState, File.expand_path("../action/discard_state", __FILE__)
|
2012-08-16 04:04:37 +00:00
|
|
|
autoload :Export, File.expand_path("../action/export", __FILE__)
|
2013-01-22 20:07:37 +00:00
|
|
|
autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__)
|
2013-01-11 22:51:49 +00:00
|
|
|
autoload :ForwardPorts, File.expand_path("../action/forward_ports", __FILE__)
|
2012-08-15 05:38:41 +00:00
|
|
|
autoload :Import, File.expand_path("../action/import", __FILE__)
|
2013-01-31 06:47:45 +00:00
|
|
|
autoload :IsPaused, File.expand_path("../action/is_paused", __FILE__)
|
2012-08-15 04:21:31 +00:00
|
|
|
autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
|
2012-08-15 05:38:41 +00:00
|
|
|
autoload :IsSaved, File.expand_path("../action/is_saved", __FILE__)
|
|
|
|
autoload :MatchMACAddress, File.expand_path("../action/match_mac_address", __FILE__)
|
2013-04-08 16:09:23 +00:00
|
|
|
autoload :MessageAlreadyRunning, File.expand_path("../action/message_already_running", __FILE__)
|
2012-07-28 17:43:16 +00:00
|
|
|
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
|
2012-08-15 04:21:31 +00:00
|
|
|
autoload :MessageNotRunning, File.expand_path("../action/message_not_running", __FILE__)
|
2012-07-29 02:58:10 +00:00
|
|
|
autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __FILE__)
|
2012-08-15 04:12:41 +00:00
|
|
|
autoload :Network, File.expand_path("../action/network", __FILE__)
|
2012-08-16 04:04:37 +00:00
|
|
|
autoload :Package, File.expand_path("../action/package", __FILE__)
|
|
|
|
autoload :PackageVagrantfile, File.expand_path("../action/package_vagrantfile", __FILE__)
|
2013-02-08 23:34:04 +00:00
|
|
|
autoload :PrepareNFSSettings, File.expand_path("../action/prepare_nfs_settings", __FILE__)
|
2013-12-14 06:03:14 +00:00
|
|
|
autoload :PrepareNFSValidIds, File.expand_path("../action/prepare_nfs_valid_ids", __FILE__)
|
2013-02-26 21:38:00 +00:00
|
|
|
autoload :PrepareForwardedPortCollisionParams, File.expand_path("../action/prepare_forwarded_port_collision_params", __FILE__)
|
2012-08-14 03:03:35 +00:00
|
|
|
autoload :Resume, File.expand_path("../action/resume", __FILE__)
|
2012-08-15 04:12:41 +00:00
|
|
|
autoload :SaneDefaults, File.expand_path("../action/sane_defaults", __FILE__)
|
2013-01-31 07:03:21 +00:00
|
|
|
autoload :SetName, File.expand_path("../action/set_name", __FILE__)
|
2012-08-16 04:04:37 +00:00
|
|
|
autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
|
2012-08-14 02:30:41 +00:00
|
|
|
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
|
2012-07-27 06:56:47 +00:00
|
|
|
|
|
|
|
# Include the built-in modules so that we can use them as top-level
|
|
|
|
# things.
|
|
|
|
include Vagrant::Action::Builtin
|
2012-07-27 05:39:27 +00:00
|
|
|
|
2012-08-15 05:38:41 +00:00
|
|
|
# This action boots the VM, assuming the VM is in a state that requires
|
|
|
|
# a bootup (i.e. not saved).
|
|
|
|
def self.action_boot
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckAccessible
|
|
|
|
b.use CleanMachineFolder
|
2013-01-31 19:26:45 +00:00
|
|
|
b.use SetName
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use ClearForwardedPorts
|
|
|
|
b.use Provision
|
2013-02-26 21:38:00 +00:00
|
|
|
b.use EnvSet, :port_collision_repair => true
|
|
|
|
b.use PrepareForwardedPortCollisionParams
|
|
|
|
b.use HandleForwardedPortCollisions
|
2013-12-14 06:03:14 +00:00
|
|
|
b.use PrepareNFSValidIds
|
2013-12-02 10:19:09 +00:00
|
|
|
b.use SyncedFolderCleanup
|
2013-11-23 00:21:14 +00:00
|
|
|
b.use SyncedFolders
|
2013-11-23 01:29:35 +00:00
|
|
|
b.use PrepareNFSSettings
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use ClearNetworkInterfaces
|
2013-01-11 22:16:00 +00:00
|
|
|
b.use Network
|
2013-01-11 22:51:49 +00:00
|
|
|
b.use ForwardPorts
|
2013-02-28 05:28:09 +00:00
|
|
|
b.use SetHostname
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use SaneDefaults
|
2013-07-23 19:56:40 +00:00
|
|
|
b.use Customize, "pre-boot"
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use Boot
|
2013-07-23 19:56:40 +00:00
|
|
|
b.use Customize, "post-boot"
|
2013-08-29 23:44:20 +00:00
|
|
|
b.use WaitForCommunicator, [:starting, :running]
|
2013-03-21 20:59:13 +00:00
|
|
|
b.use CheckGuestAdditions
|
2012-08-15 05:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-27 05:39:27 +00:00
|
|
|
# This is the action that is primarily responsible for completely
|
|
|
|
# freeing the resources of the underlying virtual machine.
|
|
|
|
def self.action_destroy
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
2012-07-28 02:34:46 +00:00
|
|
|
b.use Call, Created do |env1, b2|
|
2012-07-28 17:43:16 +00:00
|
|
|
if !env1[:result]
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2012-07-29 02:58:10 +00:00
|
|
|
b2.use Call, DestroyConfirm do |env2, b3|
|
2012-07-28 17:43:16 +00:00
|
|
|
if env2[:result]
|
2013-01-18 21:29:20 +00:00
|
|
|
b3.use ConfigValidate
|
2012-07-28 17:43:16 +00:00
|
|
|
b3.use CheckAccessible
|
2013-01-22 21:37:44 +00:00
|
|
|
b3.use EnvSet, :force_halt => true
|
2012-08-14 06:18:50 +00:00
|
|
|
b3.use action_halt
|
2012-08-14 06:31:12 +00:00
|
|
|
b3.use Destroy
|
|
|
|
b3.use CleanMachineFolder
|
|
|
|
b3.use DestroyUnusedNetworkInterfaces
|
2013-08-29 18:13:43 +00:00
|
|
|
b3.use ProvisionerCleanup
|
2013-12-14 06:03:14 +00:00
|
|
|
b3.use PrepareNFSValidIds
|
2013-12-04 02:44:37 +00:00
|
|
|
b3.use SyncedFolderCleanup
|
2012-07-28 17:43:16 +00:00
|
|
|
else
|
2012-07-29 02:58:10 +00:00
|
|
|
b3.use MessageWillNotDestroy
|
2012-07-28 02:29:40 +00:00
|
|
|
end
|
2012-07-28 17:43:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for halting
|
|
|
|
# the virtual machine, gracefully or by force.
|
|
|
|
def self.action_halt
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use Call, Created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use CheckAccessible
|
|
|
|
b2.use DiscardState
|
2013-01-31 06:47:45 +00:00
|
|
|
|
|
|
|
b2.use Call, IsPaused do |env2, b3|
|
|
|
|
next if !env2[:result]
|
|
|
|
b3.use Resume
|
|
|
|
end
|
|
|
|
|
2013-01-22 20:07:37 +00:00
|
|
|
b2.use Call, GracefulHalt, :poweroff, :running do |env2, b3|
|
2013-01-22 21:35:52 +00:00
|
|
|
if !env2[:result]
|
2013-01-22 20:07:37 +00:00
|
|
|
b3.use ForcedHalt
|
|
|
|
end
|
|
|
|
end
|
2012-07-28 02:29:40 +00:00
|
|
|
else
|
2012-07-28 17:43:16 +00:00
|
|
|
b2.use MessageNotCreated
|
2012-07-27 06:56:47 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-27 05:39:27 +00:00
|
|
|
end
|
|
|
|
end
|
2012-08-05 20:45:24 +00:00
|
|
|
|
2012-08-16 04:04:37 +00:00
|
|
|
# This action packages the virtual machine into a single box file.
|
|
|
|
def self.action_package
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use SetupPackageFiles
|
|
|
|
b2.use CheckAccessible
|
|
|
|
b2.use action_halt
|
|
|
|
b2.use ClearForwardedPorts
|
2013-12-14 06:03:14 +00:00
|
|
|
b2.use PrepareNFSValidIds
|
2013-12-04 11:22:01 +00:00
|
|
|
b2.use SyncedFolderCleanup
|
2013-12-31 16:45:30 +00:00
|
|
|
b2.use Package
|
2012-08-16 04:04:37 +00:00
|
|
|
b2.use Export
|
|
|
|
b2.use PackageVagrantfile
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-15 04:21:31 +00:00
|
|
|
# This action just runs the provisioners on the machine.
|
|
|
|
def self.action_provision
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
2013-01-18 21:29:20 +00:00
|
|
|
b.use ConfigValidate
|
2012-08-15 04:21:31 +00:00
|
|
|
b.use Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
b3.use MessageNotRunning
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use CheckAccessible
|
|
|
|
b3.use Provision
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-15 04:12:41 +00:00
|
|
|
# This action is responsible for reloading the machine, which
|
|
|
|
# brings it down, sucks in new configuration, and brings the
|
|
|
|
# machine back up with the new configuration.
|
|
|
|
def self.action_reload
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-01-18 21:29:20 +00:00
|
|
|
b2.use ConfigValidate
|
2012-08-15 04:12:41 +00:00
|
|
|
b2.use action_halt
|
|
|
|
b2.use action_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-14 03:03:35 +00:00
|
|
|
# This is the action that is primarily responsible for resuming
|
|
|
|
# suspended machines.
|
|
|
|
def self.action_resume
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use Call, Created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use CheckAccessible
|
2013-02-26 21:38:00 +00:00
|
|
|
b2.use EnvSet, :port_collision_repair => false
|
|
|
|
b2.use PrepareForwardedPortCollisionParams
|
|
|
|
b2.use HandleForwardedPortCollisions
|
2012-08-14 03:03:35 +00:00
|
|
|
b2.use Resume
|
2013-12-06 21:21:07 +00:00
|
|
|
b2.use WaitForCommunicator, [:restoring, :running]
|
2012-08-14 03:03:35 +00:00
|
|
|
else
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-05 20:45:24 +00:00
|
|
|
# This is the action that will exec into an SSH shell.
|
|
|
|
def self.action_ssh
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use CheckCreated
|
|
|
|
b.use CheckAccessible
|
|
|
|
b.use CheckRunning
|
|
|
|
b.use SSHExec
|
|
|
|
end
|
|
|
|
end
|
2012-08-10 07:57:23 +00:00
|
|
|
|
|
|
|
# This is the action that will run a single SSH command.
|
|
|
|
def self.action_ssh_run
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use CheckCreated
|
|
|
|
b.use CheckAccessible
|
|
|
|
b.use CheckRunning
|
|
|
|
b.use SSHRun
|
|
|
|
end
|
|
|
|
end
|
2012-08-14 02:30:41 +00:00
|
|
|
|
2012-08-15 04:12:41 +00:00
|
|
|
# This action starts a VM, assuming it is already imported and exists.
|
|
|
|
# A precondition of this action is that the VM exists.
|
|
|
|
def self.action_start
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
2013-01-18 21:29:20 +00:00
|
|
|
b.use ConfigValidate
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use Call, IsRunning do |env, b2|
|
|
|
|
# If the VM is running, then our work here is done, exit
|
2013-04-08 16:09:23 +00:00
|
|
|
if env[:result]
|
|
|
|
b2.use MessageAlreadyRunning
|
|
|
|
next
|
|
|
|
end
|
2012-08-15 05:38:41 +00:00
|
|
|
|
|
|
|
b2.use Call, IsSaved do |env2, b3|
|
|
|
|
if env2[:result]
|
|
|
|
# The VM is saved, so just resume it
|
|
|
|
b3.use action_resume
|
2013-01-31 06:47:45 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use Call, IsPaused do |env3, b4|
|
|
|
|
if env3[:result]
|
|
|
|
b4.use Resume
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2012-08-15 05:38:41 +00:00
|
|
|
# The VM is not saved, so we must have to boot it up
|
|
|
|
# like normal. Boot!
|
2013-01-31 06:47:45 +00:00
|
|
|
b4.use action_boot
|
2012-08-15 05:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-15 04:12:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-14 02:30:41 +00:00
|
|
|
# This is the action that is primarily responsible for suspending
|
|
|
|
# the virtual machine.
|
|
|
|
def self.action_suspend
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
|
|
|
b.use Call, Created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use CheckAccessible
|
|
|
|
b2.use Suspend
|
|
|
|
else
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-15 05:38:41 +00:00
|
|
|
|
|
|
|
# This action brings the machine up from nothing, including importing
|
|
|
|
# the box, configuring metadata, and booting.
|
|
|
|
def self.action_up
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
2013-07-11 03:10:33 +00:00
|
|
|
|
|
|
|
# Handle box_url downloading early so that if the Vagrantfile
|
|
|
|
# references any files in the box or something it all just
|
|
|
|
# works fine.
|
|
|
|
b.use Call, Created do |env, b2|
|
|
|
|
if !env[:result]
|
|
|
|
b2.use HandleBoxUrl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-18 21:29:20 +00:00
|
|
|
b.use ConfigValidate
|
2012-08-15 05:38:41 +00:00
|
|
|
b.use Call, Created do |env, b2|
|
|
|
|
# If the VM is NOT created yet, then do the setup steps
|
|
|
|
if !env[:result]
|
|
|
|
b2.use CheckAccessible
|
2013-07-23 19:56:40 +00:00
|
|
|
b2.use Customize, "pre-import"
|
2012-08-15 05:38:41 +00:00
|
|
|
b2.use Import
|
|
|
|
b2.use MatchMACAddress
|
|
|
|
end
|
|
|
|
end
|
|
|
|
b.use action_start
|
|
|
|
end
|
|
|
|
end
|
2012-07-27 05:39:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|