2013-03-03 05:24:05 +00:00
|
|
|
require 'vagrant-lxc/action/boot'
|
|
|
|
require 'vagrant-lxc/action/check_created'
|
|
|
|
require 'vagrant-lxc/action/check_running'
|
2013-03-27 00:47:28 +00:00
|
|
|
require 'vagrant-lxc/action/clear_forwarded_ports'
|
2013-03-03 05:24:05 +00:00
|
|
|
require 'vagrant-lxc/action/create'
|
|
|
|
require 'vagrant-lxc/action/created'
|
|
|
|
require 'vagrant-lxc/action/destroy'
|
2013-04-18 06:11:36 +00:00
|
|
|
require 'vagrant-lxc/action/destroy_confirm'
|
2013-04-10 04:36:53 +00:00
|
|
|
require 'vagrant-lxc/action/disconnect'
|
2013-03-30 22:19:38 +00:00
|
|
|
require 'vagrant-lxc/action/compress_rootfs'
|
2013-03-11 03:08:28 +00:00
|
|
|
require 'vagrant-lxc/action/forced_halt'
|
2013-03-26 23:01:10 +00:00
|
|
|
require 'vagrant-lxc/action/forward_ports'
|
2013-03-02 15:17:04 +00:00
|
|
|
require 'vagrant-lxc/action/handle_box_metadata'
|
2013-03-03 05:24:05 +00:00
|
|
|
require 'vagrant-lxc/action/is_running'
|
2013-04-13 01:08:37 +00:00
|
|
|
require 'vagrant-lxc/action/message'
|
2013-05-08 23:13:17 +00:00
|
|
|
require 'vagrant-lxc/action/remove_temporary_files'
|
2013-03-30 22:19:38 +00:00
|
|
|
require 'vagrant-lxc/action/setup_package_files'
|
2013-03-04 01:42:18 +00:00
|
|
|
require 'vagrant-lxc/action/share_folders'
|
2013-02-28 03:21:59 +00:00
|
|
|
|
|
|
|
module Vagrant
|
|
|
|
module LXC
|
2013-03-02 06:57:03 +00:00
|
|
|
module Action
|
2013-02-28 03:21:59 +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 Vagrant::Action::Builtin::Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
2013-04-13 01:31:18 +00:00
|
|
|
b2.use Message, :not_created
|
2013-02-28 03:21:59 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Vagrant::Action::Builtin::ConfigValidate
|
|
|
|
b2.use action_halt
|
|
|
|
b2.use action_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 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 Vagrant::Action::Builtin::Provision
|
|
|
|
b.use Vagrant::Action::Builtin::EnvSet, :port_collision_repair => true
|
2013-07-28 05:39:08 +00:00
|
|
|
b.use Vagrant::Action::Builtin::HandleForwardedPortCollisions
|
2013-02-28 03:21:59 +00:00
|
|
|
b.use ShareFolders
|
2013-03-11 03:09:36 +00:00
|
|
|
b.use Vagrant::Action::Builtin::SetHostname
|
2013-03-26 23:01:10 +00:00
|
|
|
b.use ForwardPorts
|
2013-02-28 03:21:59 +00:00
|
|
|
b.use Boot
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-04 04:10:09 +00:00
|
|
|
# This action just runs the provisioners on the machine.
|
|
|
|
def self.action_provision
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Vagrant::Action::Builtin::ConfigValidate
|
|
|
|
b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
2013-04-13 01:31:18 +00:00
|
|
|
b2.use Message, :not_created
|
2013-03-04 04:10:09 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Vagrant::Action::Builtin::Call, IsRunning do |env2, b3|
|
|
|
|
if !env2[:result]
|
2013-04-13 01:31:18 +00:00
|
|
|
b3.use Message, :not_running
|
2013-03-04 04:10:09 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use Vagrant::Action::Builtin::Provision
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-28 03:21:59 +00:00
|
|
|
# This action starts a container, assuming it is already created and exists.
|
|
|
|
# A precondition of this action is that the container exists.
|
|
|
|
def self.action_start
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Vagrant::Action::Builtin::ConfigValidate
|
|
|
|
b.use Vagrant::Action::Builtin::Call, IsRunning do |env, b2|
|
|
|
|
# If the VM is running, then our work here is done, exit
|
|
|
|
next if env[:result]
|
|
|
|
# TODO: Check if has been saved / frozen and resume
|
|
|
|
b2.use action_boot
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This action brings the machine up from nothing, including creating the
|
|
|
|
# container, configuring metadata, and booting.
|
|
|
|
def self.action_up
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Vagrant::Action::Builtin::ConfigValidate
|
|
|
|
b.use Vagrant::Action::Builtin::Call, Created do |env, b2|
|
|
|
|
# If the VM is NOT created yet, then do the setup steps
|
|
|
|
if !env[:result]
|
2013-03-04 22:35:50 +00:00
|
|
|
b2.use Vagrant::Action::Builtin::HandleBoxUrl
|
2013-03-02 15:17:04 +00:00
|
|
|
b2.use HandleBoxMetadata
|
2013-02-28 03:21:59 +00:00
|
|
|
b2.use Create
|
|
|
|
end
|
|
|
|
end
|
|
|
|
b.use action_start
|
|
|
|
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 Vagrant::Action::Builtin::Call, Created do |env, b2|
|
|
|
|
if env[:result]
|
2013-05-08 23:13:17 +00:00
|
|
|
# TODO: Remove this on / after 0.4
|
2013-04-10 04:36:53 +00:00
|
|
|
b2.use Disconnect
|
2013-03-27 00:47:28 +00:00
|
|
|
b2.use ClearForwardedPorts
|
2013-05-08 23:13:17 +00:00
|
|
|
b2.use RemoveTemporaryFiles
|
2013-03-03 06:22:44 +00:00
|
|
|
b2.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :stopped, :running do |env2, b3|
|
2013-04-08 23:07:06 +00:00
|
|
|
if !env2[:result]
|
2013-03-11 03:08:28 +00:00
|
|
|
b3.use ForcedHalt
|
2013-03-03 06:22:44 +00:00
|
|
|
end
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
else
|
2013-04-13 01:31:18 +00:00
|
|
|
b2.use Message, :not_created
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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 Vagrant::Action::Builtin::Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
2013-04-13 01:31:18 +00:00
|
|
|
b2.use Message, :not_created
|
2013-02-28 03:21:59 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-04-18 06:11:36 +00:00
|
|
|
b2.use Vagrant::Action::Builtin::Call, DestroyConfirm do |env2, b3|
|
2013-02-28 03:21:59 +00:00
|
|
|
if env2[:result]
|
|
|
|
b3.use Vagrant::Action::Builtin::ConfigValidate
|
|
|
|
b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
|
|
|
|
b3.use action_halt
|
|
|
|
b3.use Destroy
|
|
|
|
else
|
2013-04-13 01:31:18 +00:00
|
|
|
b3.use Message, :will_not_destroy
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-30 22:19:38 +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 Vagrant::Action::Builtin::Call, Created do |env1, b2|
|
|
|
|
if !env1[:result]
|
2013-04-13 01:31:18 +00:00
|
|
|
b2.use Message, :not_created
|
2013-03-30 22:19:38 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use action_halt
|
|
|
|
b2.use CompressRootFS
|
|
|
|
b2.use SetupPackageFiles
|
|
|
|
b2.use Vagrant::Action::General::Package
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-02 19:48:15 +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 CheckCreated
|
|
|
|
b.use CheckRunning
|
|
|
|
b.use Vagrant::Action::Builtin::SSHExec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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 CheckCreated
|
|
|
|
b.use CheckRunning
|
|
|
|
b.use Vagrant::Action::Builtin::SSHRun
|
|
|
|
end
|
|
|
|
end
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|