2014-02-15 23:29:16 +00:00
|
|
|
require "pathname"
|
2014-02-15 23:38:11 +00:00
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
require "vagrant/action/builder"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module HyperV
|
|
|
|
module Action
|
|
|
|
# Include the built-in modules so we can use them as top-level things.
|
|
|
|
include Vagrant::Action::Builtin
|
|
|
|
|
|
|
|
def self.action_reload
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
2014-02-15 23:29:16 +00:00
|
|
|
next
|
|
|
|
end
|
2014-02-26 23:54:53 +00:00
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
b2.use action_halt
|
2014-02-26 23:54:53 +00:00
|
|
|
b2.use action_start
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-16 19:31:33 +00:00
|
|
|
def self.action_destroy
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env1, b1|
|
|
|
|
if env1[:result]
|
|
|
|
b1.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
2014-02-16 19:31:33 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-02-16 19:42:20 +00:00
|
|
|
b1.use Call, DestroyConfirm do |env2, b2|
|
2014-02-16 19:31:33 +00:00
|
|
|
if !env2[:result]
|
2014-02-16 19:42:20 +00:00
|
|
|
b2.use MessageWillNotDestroy
|
2014-02-16 19:31:33 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-02-16 19:42:20 +00:00
|
|
|
b2.use ConfigValidate
|
|
|
|
b2.use StopInstance
|
|
|
|
b2.use DeleteVM
|
2014-02-16 19:31:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
def self.action_halt
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
2014-02-15 23:29:16 +00:00
|
|
|
next
|
|
|
|
end
|
2014-02-26 23:54:53 +00:00
|
|
|
|
|
|
|
b2.use Call, GracefulHalt, :off, :running do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
b3.use StopInstance
|
|
|
|
end
|
|
|
|
end
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-27 01:41:02 +00:00
|
|
|
def self.action_resume
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use HandleBox
|
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env1[:result]
|
2014-02-27 01:41:02 +00:00
|
|
|
b1.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b1.use ResumeVM
|
|
|
|
b1.use WaitForIPAddress
|
|
|
|
b1.use WaitForCommunicator, [:running]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
def self.action_start
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-02-27 01:41:02 +00:00
|
|
|
b.use Call, IsState, :running do |env1, b1|
|
|
|
|
if env1[:result]
|
|
|
|
b1.use Message, I18n.t("vagrant_hyperv.message_already_running")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b1.use Call, IsState, :paused do |env2, b2|
|
|
|
|
if env2[:result]
|
|
|
|
b2.use action_resume
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Provision
|
|
|
|
b2.use StartInstance
|
|
|
|
b2.use WaitForIPAddress
|
|
|
|
b2.use WaitForCommunicator, [:running]
|
|
|
|
b2.use SyncedFolders
|
2014-02-28 17:58:41 +00:00
|
|
|
b2.use SetHostname
|
2014-02-27 01:41:02 +00:00
|
|
|
end
|
|
|
|
end
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_up
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-02-26 18:46:30 +00:00
|
|
|
b.use HandleBox
|
2014-02-15 23:29:16 +00:00
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env1, b1|
|
|
|
|
if env1[:result]
|
2014-02-15 23:29:16 +00:00
|
|
|
b1.use Import
|
|
|
|
end
|
2014-02-26 23:54:53 +00:00
|
|
|
|
|
|
|
b1.use action_start
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_read_state
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
|
|
|
b.use ReadState
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_ssh
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
2014-02-15 23:29:16 +00:00
|
|
|
next
|
|
|
|
end
|
2014-02-27 01:52:38 +00:00
|
|
|
|
|
|
|
b2.use Call, IsState, :running do |env1, b3|
|
|
|
|
if !env1[:result]
|
|
|
|
b3.use Message, I18n.t("vagrant_hyperv.message_not_running")
|
|
|
|
next
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
2014-02-27 01:52:38 +00:00
|
|
|
|
|
|
|
b3.use SSHExec
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-27 01:41:02 +00:00
|
|
|
def self.action_suspend
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-02-27 01:52:38 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
|
2014-02-27 01:41:02 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use SuspendVM
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-15 23:29:16 +00:00
|
|
|
def self.action_read_guest_ip
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
|
|
|
b.use ReadGuestIP
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# The autoload farm
|
|
|
|
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
2014-02-16 19:42:20 +00:00
|
|
|
autoload :DeleteVM, action_root.join("delete_vm")
|
2014-02-15 23:29:16 +00:00
|
|
|
autoload :Import, action_root.join("import")
|
2014-02-27 01:41:02 +00:00
|
|
|
autoload :ReadState, action_root.join("read_state")
|
|
|
|
autoload :ResumeVM, action_root.join("resume_vm")
|
2014-02-15 23:29:16 +00:00
|
|
|
autoload :StartInstance, action_root.join('start_instance')
|
|
|
|
autoload :StopInstance, action_root.join('stop_instance')
|
2014-02-27 01:41:02 +00:00
|
|
|
autoload :SuspendVM, action_root.join("suspend_vm")
|
2014-02-15 23:29:16 +00:00
|
|
|
autoload :ReadGuestIP, action_root.join('read_guest_ip')
|
2014-02-26 19:12:24 +00:00
|
|
|
autoload :WaitForIPAddress, action_root.join("wait_for_ip_address")
|
2014-02-15 23:29:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|