2013-03-27 00:55:30 +01:00
|
|
|
require 'vagrant/action/builder'
|
2014-01-23 13:46:44 -05:00
|
|
|
require 'log4r'
|
2013-03-27 00:55:30 +01:00
|
|
|
|
|
|
|
|
module VagrantPlugins
|
2013-07-31 09:20:43 +09:00
|
|
|
module ProviderLibvirt
|
2013-03-27 00:55:30 +01:00
|
|
|
module Action
|
|
|
|
|
# Include the built-in modules so we can use them as top-level things.
|
|
|
|
|
include Vagrant::Action::Builtin
|
2015-04-04 22:29:21 +02:00
|
|
|
@logger = Log4r::Logger.new('vagrant_libvirt::action')
|
2013-03-27 00:55:30 +01:00
|
|
|
|
2019-02-11 20:18:02 -05:00
|
|
|
# remove image from Libvirt storage pool
|
2015-05-01 17:48:43 +02:00
|
|
|
def self.remove_libvirt_image
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use RemoveLibvirtImage
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-27 00:55:30 +01:00
|
|
|
# This action is called to bring the box up from nothing.
|
|
|
|
|
def self.action_up
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use ConfigValidate
|
2018-01-12 12:05:04 +01:00
|
|
|
b.use BoxCheckOutdated
|
2013-03-27 00:55:30 +01:00
|
|
|
b.use Call, IsCreated do |env, b2|
|
2013-04-01 17:10:35 +02:00
|
|
|
# Create VM if not yet created.
|
|
|
|
|
if !env[:result]
|
|
|
|
|
b2.use SetNameOfDomain
|
2015-10-06 01:07:25 +02:00
|
|
|
if !env[:machine].config.vm.box
|
2015-08-10 17:10:23 +02:00
|
|
|
b2.use CreateDomain
|
|
|
|
|
b2.use CreateNetworks
|
|
|
|
|
b2.use CreateNetworkInterfaces
|
2015-08-11 00:39:53 +02:00
|
|
|
b2.use SetBootOrder
|
2015-08-10 17:10:23 +02:00
|
|
|
b2.use StartDomain
|
|
|
|
|
else
|
|
|
|
|
b2.use HandleStoragePool
|
|
|
|
|
b2.use HandleBox
|
|
|
|
|
b2.use HandleBoxImage
|
|
|
|
|
b2.use CreateDomainVolume
|
|
|
|
|
b2.use CreateDomain
|
|
|
|
|
|
|
|
|
|
b2.use Provision
|
|
|
|
|
b2.use PrepareNFSValidIds
|
|
|
|
|
b2.use SyncedFolderCleanup
|
|
|
|
|
b2.use SyncedFolders
|
|
|
|
|
b2.use PrepareNFSSettings
|
|
|
|
|
b2.use ShareFolders
|
|
|
|
|
b2.use CreateNetworks
|
|
|
|
|
b2.use CreateNetworkInterfaces
|
2015-08-11 00:39:53 +02:00
|
|
|
b2.use SetBootOrder
|
2015-08-10 17:10:23 +02:00
|
|
|
|
|
|
|
|
b2.use StartDomain
|
|
|
|
|
b2.use WaitTillUp
|
|
|
|
|
|
|
|
|
|
b2.use ForwardPorts
|
|
|
|
|
b2.use SetHostname
|
|
|
|
|
# b2.use SyncFolders
|
|
|
|
|
end
|
2013-04-01 17:10:35 +02:00
|
|
|
else
|
2017-06-06 23:50:03 +06:00
|
|
|
env[:halt_on_error] = true
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use action_start
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Assuming VM is created, just start it. This action is not called
|
|
|
|
|
# directly by any subcommand. VM can be suspended, already running or in
|
|
|
|
|
# poweroff state.
|
|
|
|
|
def self.action_start
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use ConfigValidate
|
|
|
|
|
b.use Call, IsRunning do |env, b2|
|
2017-03-01 13:54:38 +00:00
|
|
|
# If the VM is running, run the necessary provisioners
|
|
|
|
|
if env[:result]
|
|
|
|
|
b2.use action_provision
|
|
|
|
|
next
|
|
|
|
|
end
|
2013-04-01 17:10:35 +02:00
|
|
|
|
|
|
|
|
b2.use Call, IsSuspended do |env2, b3|
|
2014-01-18 13:03:34 -06:00
|
|
|
# if vm is suspended resume it then exit
|
2013-04-01 17:10:35 +02:00
|
|
|
if env2[:result]
|
2017-04-13 13:25:19 -07:00
|
|
|
b3.use CreateNetworks
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use ResumeDomain
|
|
|
|
|
next
|
2013-03-30 13:42:59 +01:00
|
|
|
end
|
2013-04-01 17:10:35 +02:00
|
|
|
|
2015-10-06 01:07:25 +02:00
|
|
|
if !env[:machine].config.vm.box
|
2015-08-10 17:10:23 +02:00
|
|
|
# With no box, we just care about network creation and starting it
|
|
|
|
|
b3.use CreateNetworks
|
2015-08-11 00:39:53 +02:00
|
|
|
b3.use SetBootOrder
|
2015-08-10 17:10:23 +02:00
|
|
|
b3.use StartDomain
|
|
|
|
|
else
|
|
|
|
|
# VM is not running or suspended.
|
2014-01-18 13:03:34 -06:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
b3.use Provision
|
2014-09-24 08:36:03 -04:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
# Ensure networks are created and active
|
|
|
|
|
b3.use CreateNetworks
|
2015-08-11 00:39:53 +02:00
|
|
|
b3.use SetBootOrder
|
2014-01-18 13:03:34 -06:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
b3.use PrepareNFSValidIds
|
|
|
|
|
b3.use SyncedFolderCleanup
|
|
|
|
|
b3.use SyncedFolders
|
2014-03-16 02:13:52 +01:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
# Start it..
|
|
|
|
|
b3.use StartDomain
|
2014-01-23 13:46:44 -05:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
# Machine should gain IP address when comming up,
|
|
|
|
|
# so wait for dhcp lease and store IP into machines data_dir.
|
|
|
|
|
b3.use WaitTillUp
|
2014-01-23 13:46:44 -05:00
|
|
|
|
2015-08-10 17:10:23 +02:00
|
|
|
b3.use ForwardPorts
|
|
|
|
|
b3.use PrepareNFSSettings
|
|
|
|
|
b3.use ShareFolders
|
2016-12-13 15:36:05 +01:00
|
|
|
end
|
2013-04-01 17:10:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for halting the
|
|
|
|
|
# virtual machine.
|
|
|
|
|
def self.action_halt
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use ConfigValidate
|
2014-01-23 15:35:11 -08:00
|
|
|
b.use ClearForwardedPorts
|
2013-04-01 17:10:35 +02:00
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use MessageNotCreated
|
2013-03-27 00:55:30 +01:00
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use Call, IsSuspended do |env2, b3|
|
2017-04-13 13:25:19 -07:00
|
|
|
b3.use CreateNetworks if env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use ResumeDomain if env2[:result]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
next unless env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
|
2013-05-10 14:56:53 +02:00
|
|
|
# VM is running, halt it.
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use HaltDomain
|
|
|
|
|
end
|
2013-04-01 02:17:05 +02:00
|
|
|
end
|
2013-03-27 00:55:30 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-10-18 18:34:30 -05:00
|
|
|
# This is the action implements the reload command
|
|
|
|
|
# It uses the halt and start actions
|
|
|
|
|
def self.action_reload
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-10-18 18:34:30 -05:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b2.use ConfigValidate
|
|
|
|
|
b2.use action_halt
|
|
|
|
|
b2.use action_start
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-04 22:29:21 +02:00
|
|
|
# not implemented and looks like not require
|
|
|
|
|
def self.action_package
|
2015-05-16 17:35:00 +02:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use ConfigValidate
|
|
|
|
|
b.use PackageDomain
|
2015-04-04 22:29:21 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-27 00:55:30 +01: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 ConfigValidate
|
|
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2015-05-23 21:49:51 +02:00
|
|
|
# Try to remove stale volumes anyway
|
|
|
|
|
b2.use SetNameOfDomain
|
2016-12-06 23:20:29 +01:00
|
|
|
b2.use RemoveStaleVolume if env[:machine].config.vm.box
|
|
|
|
|
b2.use MessageNotCreated unless env[:result]
|
2015-05-23 21:49:51 +02:00
|
|
|
|
2013-03-27 00:55:30 +01:00
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2017-10-28 22:56:12 +02:00
|
|
|
b2.use Call, DestroyConfirm do |env2, b3|
|
|
|
|
|
if env2[:result]
|
|
|
|
|
b3.use ClearForwardedPorts
|
|
|
|
|
# b3.use PruneNFSExports
|
|
|
|
|
b3.use DestroyDomain
|
|
|
|
|
b3.use DestroyNetworks
|
|
|
|
|
b3.use ProvisionerCleanup
|
|
|
|
|
else
|
|
|
|
|
b3.use MessageWillNotDestroy
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-03-27 00:55:30 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 02:17:05 +02:00
|
|
|
# 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 Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-04-01 02:17:05 +02:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use MessageNotRunning
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b3.use SSHExec
|
|
|
|
|
end
|
2013-04-01 02:17:05 +02:00
|
|
|
end
|
|
|
|
|
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 Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-04-01 02:17:05 +02:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use MessageNotRunning
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b3.use Provision
|
2014-03-16 02:13:52 +01:00
|
|
|
# b3.use SyncFolders
|
2013-04-01 17:10:35 +02:00
|
|
|
end
|
2013-04-01 02:17:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 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 ConfigValidate
|
|
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-04-01 02:17:05 +02:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use MessageNotRunning
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
b3.use SuspendDomain
|
|
|
|
|
end
|
2013-04-01 02:17:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 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 ConfigValidate
|
|
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-04-01 02:17:05 +02:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-01 17:10:35 +02:00
|
|
|
b2.use Call, IsSuspended do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env2[:result]
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use MessageNotSuspended
|
|
|
|
|
next
|
|
|
|
|
end
|
2017-04-13 13:25:19 -07:00
|
|
|
b3.use CreateNetworks
|
2013-04-01 17:10:35 +02:00
|
|
|
b3.use ResumeDomain
|
|
|
|
|
end
|
2013-04-01 02:17:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-13 04:13:12 -05:00
|
|
|
def self.action_read_mac_addresses
|
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
|
b.use ConfigValidate
|
|
|
|
|
b.use ReadMacAddresses
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-05-05 16:21:43 +02: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 ConfigValidate
|
|
|
|
|
b.use Call, IsCreated do |env, b2|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env[:result]
|
2013-05-05 16:21:43 +02:00
|
|
|
b2.use MessageNotCreated
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2016-12-06 23:20:29 +01:00
|
|
|
unless env2[:result]
|
2013-05-05 16:21:43 +02:00
|
|
|
b3.use MessageNotRunning
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
b3.use SSHRun
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-09-24 20:32:03 +02:00
|
|
|
action_root = Pathname.new(File.expand_path('../action', __FILE__))
|
2015-05-16 17:35:00 +02:00
|
|
|
autoload :PackageDomain, action_root.join('package_domain')
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :CreateDomain, action_root.join('create_domain')
|
|
|
|
|
autoload :CreateDomainVolume, action_root.join('create_domain_volume')
|
|
|
|
|
autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
|
|
|
|
|
autoload :CreateNetworks, action_root.join('create_networks')
|
|
|
|
|
autoload :DestroyDomain, action_root.join('destroy_domain')
|
|
|
|
|
autoload :DestroyNetworks, action_root.join('destroy_networks')
|
2014-01-23 15:35:11 -08:00
|
|
|
autoload :ForwardPorts, action_root.join('forward_ports')
|
|
|
|
|
autoload :ClearForwardedPorts, action_root.join('forward_ports')
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :HaltDomain, action_root.join('halt_domain')
|
|
|
|
|
autoload :HandleBoxImage, action_root.join('handle_box_image')
|
|
|
|
|
autoload :HandleStoragePool, action_root.join('handle_storage_pool')
|
2015-05-01 17:48:43 +02:00
|
|
|
autoload :RemoveLibvirtImage, action_root.join('remove_libvirt_image')
|
2013-09-24 20:32:03 +02:00
|
|
|
autoload :IsCreated, action_root.join('is_created')
|
|
|
|
|
autoload :IsRunning, action_root.join('is_running')
|
|
|
|
|
autoload :IsSuspended, action_root.join('is_suspended')
|
|
|
|
|
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
|
|
|
|
|
autoload :MessageNotCreated, action_root.join('message_not_created')
|
|
|
|
|
autoload :MessageNotRunning, action_root.join('message_not_running')
|
|
|
|
|
autoload :MessageNotSuspended, action_root.join('message_not_suspended')
|
2017-10-28 22:56:12 +02:00
|
|
|
autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
|
2014-03-16 11:38:21 +01:00
|
|
|
|
2015-05-23 21:49:51 +02:00
|
|
|
autoload :RemoveStaleVolume, action_root.join('remove_stale_volume')
|
|
|
|
|
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
|
2014-03-16 11:38:21 +01:00
|
|
|
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
2014-03-16 11:38:21 +01:00
|
|
|
|
2015-04-13 04:13:12 -05:00
|
|
|
autoload :ReadMacAddresses, action_root.join('read_mac_addresses')
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :ResumeDomain, action_root.join('resume_domain')
|
2013-09-24 20:32:03 +02:00
|
|
|
autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
|
2015-08-11 00:39:53 +02:00
|
|
|
autoload :SetBootOrder, action_root.join('set_boot_order')
|
2015-04-04 22:29:21 +02:00
|
|
|
|
|
|
|
|
# I don't think we need it anymore
|
2013-10-17 00:42:35 -05:00
|
|
|
autoload :ShareFolders, action_root.join('share_folders')
|
2013-09-24 20:32:03 +02:00
|
|
|
autoload :StartDomain, action_root.join('start_domain')
|
|
|
|
|
autoload :SuspendDomain, action_root.join('suspend_domain')
|
2014-03-16 02:13:52 +01:00
|
|
|
autoload :TimedProvision, action_root.join('timed_provision')
|
2014-03-16 11:38:21 +01:00
|
|
|
|
2013-09-24 20:32:03 +02:00
|
|
|
autoload :WaitTillUp, action_root.join('wait_till_up')
|
2014-03-16 02:13:52 +01:00
|
|
|
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
|
2014-05-02 21:28:47 -05:00
|
|
|
autoload :HandleBox, 'vagrant/action/builtin/handle_box'
|
2014-02-05 10:52:14 -06:00
|
|
|
autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders'
|
|
|
|
|
autoload :SyncedFolderCleanup, 'vagrant/action/builtin/synced_folder_cleanup'
|
2015-07-31 20:47:20 +01:00
|
|
|
autoload :ProvisionerCleanup, 'vagrant/action/builtin/provisioner_cleanup'
|
2013-03-27 00:55:30 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|