2013-03-03 05:24:05 +00:00
|
|
|
require 'vagrant-lxc/action/boot'
|
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/destroy'
|
2013-04-18 06:11:36 +00:00
|
|
|
require 'vagrant-lxc/action/destroy_confirm'
|
2013-03-30 22:19:38 +00:00
|
|
|
require 'vagrant-lxc/action/compress_rootfs'
|
2013-07-29 15:08:22 +00:00
|
|
|
require 'vagrant-lxc/action/fetch_ip_with_lxc_attach'
|
|
|
|
require 'vagrant-lxc/action/fetch_ip_from_dnsmasq_leases'
|
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'
|
2014-03-12 13:30:37 +00:00
|
|
|
require 'vagrant-lxc/action/prepare_nfs_settings'
|
|
|
|
require 'vagrant-lxc/action/prepare_nfs_valid_ids'
|
2014-06-09 03:48:52 +00:00
|
|
|
require 'vagrant-lxc/action/private_networks'
|
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-11-06 22:40:05 +00:00
|
|
|
require 'vagrant-lxc/action/warn_networks'
|
2013-02-28 03:21:59 +00:00
|
|
|
|
2014-03-11 23:37:47 +00:00
|
|
|
unless Vagrant::Backports.vagrant_1_3_or_later?
|
|
|
|
require 'vagrant-backports/action/wait_for_communicator'
|
2013-09-12 04:10:11 +00:00
|
|
|
end
|
2014-03-11 23:56:11 +00:00
|
|
|
unless Vagrant::Backports.vagrant_1_5_or_later?
|
2014-03-13 01:40:03 +00:00
|
|
|
require 'vagrant-backports/ui'
|
2014-03-11 23:56:11 +00:00
|
|
|
require 'vagrant-backports/action/handle_box'
|
2014-03-13 01:41:41 +00:00
|
|
|
require 'vagrant-backports/action/message'
|
2014-03-13 02:17:42 +00:00
|
|
|
require 'vagrant-backports/action/is_state'
|
2014-03-11 23:56:11 +00:00
|
|
|
end
|
2013-09-12 04:10:11 +00:00
|
|
|
|
2013-02-28 03:21:59 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
2013-03-02 06:57:03 +00:00
|
|
|
module Action
|
2013-09-28 04:05:10 +00:00
|
|
|
# Shortcuts
|
|
|
|
Builtin = Vagrant::Action::Builtin
|
|
|
|
Builder = Vagrant::Action::Builder
|
|
|
|
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
|
|
|
|
if env1[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
2013-02-28 03:21:59 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-09-28 04:05:10 +00:00
|
|
|
b2.use Builtin::ConfigValidate
|
2013-02-28 03:21:59 +00:00
|
|
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
|
|
|
b.use Builtin::Provision
|
|
|
|
b.use Builtin::EnvSet, :port_collision_repair => true
|
|
|
|
b.use Builtin::HandleForwardedPortCollisions
|
2014-03-12 13:30:37 +00:00
|
|
|
if Vagrant::Backports.vagrant_1_4_or_later?
|
|
|
|
b.use PrepareNFSValidIds
|
|
|
|
b.use Builtin::SyncedFolderCleanup
|
|
|
|
b.use Builtin::SyncedFolders
|
|
|
|
b.use PrepareNFSSettings
|
|
|
|
else
|
2014-03-12 13:32:25 +00:00
|
|
|
require 'vagrant-lxc/backports/action/share_folders'
|
2014-03-12 13:30:37 +00:00
|
|
|
b.use ShareFolders
|
|
|
|
end
|
2013-09-28 04:05:10 +00:00
|
|
|
b.use Builtin::SetHostname
|
2013-11-06 22:40:05 +00:00
|
|
|
b.use WarnNetworks
|
2013-03-26 23:01:10 +00:00
|
|
|
b.use ForwardPorts
|
2013-02-28 03:21:59 +00:00
|
|
|
b.use Boot
|
2013-09-28 04:05:10 +00:00
|
|
|
b.use Builtin::WaitForCommunicator
|
2014-06-09 03:48:52 +00:00
|
|
|
b.use PrivateNetworks
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-04 04:10:09 +00:00
|
|
|
# This action just runs the provisioners on the machine.
|
|
|
|
def self.action_provision
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
|
|
|
b.use Builtin::ConfigValidate
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
|
|
|
|
if env1[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
2013-03-04 04:10:09 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-13 02:34:16 +00:00
|
|
|
b2.use Builtin::Call, Builtin::IsState, :running do |env2, b3|
|
2013-03-04 04:10:09 +00:00
|
|
|
if !env2[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
2013-03-04 04:10:09 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-09-28 04:05:10 +00:00
|
|
|
b3.use Builtin::Provision
|
2013-03-04 04:10:09 +00:00
|
|
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
|
|
|
b.use Builtin::ConfigValidate
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :running do |env, b2|
|
2013-02-28 03:21:59 +00:00
|
|
|
# If the VM is running, then our work here is done, exit
|
|
|
|
next if env[:result]
|
|
|
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
|
|
|
b.use Builtin::ConfigValidate
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
|
2013-02-28 03:21:59 +00:00
|
|
|
# If the VM is NOT created yet, then do the setup steps
|
2014-03-13 02:34:16 +00:00
|
|
|
if env[:result]
|
2014-03-11 23:56:11 +00:00
|
|
|
b2.use Builtin::HandleBox
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
|
2013-02-28 03:21:59 +00:00
|
|
|
if env[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
2014-03-13 02:34:16 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use ClearForwardedPorts
|
|
|
|
b2.use RemoveTemporaryFiles
|
|
|
|
b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
b3.use ForcedHalt
|
|
|
|
end
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
|
|
|
|
if env1[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
2013-02-28 03:21:59 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-09-28 04:33:47 +00:00
|
|
|
# TODO: Use Vagrant's built in action once we drop support for vagrant 1.2
|
2013-09-28 04:05:10 +00:00
|
|
|
b2.use Builtin::Call, DestroyConfirm do |env2, b3|
|
2013-02-28 03:21:59 +00:00
|
|
|
if env2[:result]
|
2013-09-28 04:05:10 +00:00
|
|
|
b3.use Builtin::ConfigValidate
|
|
|
|
b3.use Builtin::EnvSet, :force_halt => true
|
2013-02-28 03:21:59 +00:00
|
|
|
b3.use action_halt
|
|
|
|
b3.use Destroy
|
2014-03-11 23:37:47 +00:00
|
|
|
if Vagrant::Backports.vagrant_1_3_or_later?
|
2013-09-28 04:05:10 +00:00
|
|
|
b3.use Builtin::ProvisionerCleanup
|
2013-09-12 00:51:18 +00:00
|
|
|
end
|
2013-02-28 03:21:59 +00:00
|
|
|
else
|
2014-03-13 01:41:41 +00:00
|
|
|
b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
|
|
|
|
if env1[:result]
|
2014-03-13 01:41:41 +00:00
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.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-07-29 15:08:22 +00:00
|
|
|
# This action is called to read the IP of the container. The IP found
|
|
|
|
# is expected to be put into the `:machine_ip` key.
|
|
|
|
def self.action_fetch_ip
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
|
|
|
b.use Builtin::ConfigValidate
|
2014-06-03 15:53:26 +00:00
|
|
|
b.use Builtin::Call, Builtin::IsState, :running do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use FetchIpWithLxcAttach if env[:machine].provider.driver.supports_attach?
|
|
|
|
b2.use FetchIpFromDnsmasqLeases
|
|
|
|
else
|
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
|
|
|
end
|
|
|
|
end
|
2013-07-29 15:08:22 +00:00
|
|
|
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
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::ConfigValidate
|
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Builtin::Call, Builtin::IsState, :running do |env1, b3|
|
|
|
|
if !env1[:result]
|
|
|
|
b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-13 12:42:39 +00:00
|
|
|
b3.use Builtin::SSHExec
|
2014-03-13 02:34:16 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-02 19:48:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that will run a single SSH command.
|
|
|
|
def self.action_ssh_run
|
2013-09-28 04:05:10 +00:00
|
|
|
Builder.new.tap do |b|
|
2014-03-13 02:34:16 +00:00
|
|
|
b.use Builtin::ConfigValidate
|
|
|
|
b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Builtin::Call, Builtin::IsState, :running do |env1, b3|
|
|
|
|
if !env1[:result]
|
2014-03-14 02:02:18 +00:00
|
|
|
raise Vagrant::Errors::VMNotRunningError
|
2014-03-13 02:34:16 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use Builtin::SSHRun
|
|
|
|
end
|
|
|
|
end
|
2013-03-02 19:48:15 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-28 03:21:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|