providers/hyperv: use IsState and Message built-ins everywhere

This commit is contained in:
Mitchell Hashimoto 2014-02-26 17:52:38 -08:00
parent c735e81e4d
commit af4bc18c14
7 changed files with 28 additions and 139 deletions

View File

@ -11,9 +11,9 @@ module VagrantPlugins
def self.action_reload def self.action_reload
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if !env[:result] if env[:result]
b2.use MessageNotCreated b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
@ -25,9 +25,9 @@ module VagrantPlugins
def self.action_destroy def self.action_destroy
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsCreated do |env1, b1| b.use Call, IsState, :not_created do |env1, b1|
if !env1[:result] if env1[:result]
b1.use MessageNotCreated b1.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
@ -48,9 +48,9 @@ module VagrantPlugins
def self.action_halt def self.action_halt
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if !env[:result] if env[:result]
b2.use MessageNotCreated b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
@ -67,8 +67,8 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use HandleBox b.use HandleBox
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env1, b1| b.use Call, IsState, :not_created do |env, b2|
if !env1[:result] if env1[:result]
b1.use Message, I18n.t("vagrant_hyperv.message_not_created") b1.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
@ -108,8 +108,8 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use HandleBox b.use HandleBox
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env1, b1| b.use Call, IsState, :not_created do |env1, b1|
if !env1[:result] if env1[:result]
b1.use Import b1.use Import
end end
@ -128,17 +128,19 @@ module VagrantPlugins
def self.action_ssh def self.action_ssh
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if !env[:result] if env[:result]
b2.use MessageNotCreated b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
b2.use Call, IsStopped do |env1, b3|
if env1[:result] b2.use Call, IsState, :running do |env1, b3|
b3.use MessageNotRunning if !env1[:result]
else b3.use Message, I18n.t("vagrant_hyperv.message_not_running")
b3.use SSHExec next
end end
b3.use SSHExec
end end
end end
end end
@ -147,9 +149,9 @@ module VagrantPlugins
def self.action_suspend def self.action_suspend
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsCreated do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if !env[:result] if env[:result]
b2.use MessageNotCreated b2.use Message, I18n.t("vagrant_hyperv.message_not_created")
next next
end end
@ -169,17 +171,12 @@ module VagrantPlugins
# The autoload farm # The autoload farm
action_root = Pathname.new(File.expand_path("../action", __FILE__)) action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :DeleteVM, action_root.join("delete_vm") autoload :DeleteVM, action_root.join("delete_vm")
autoload :IsCreated, action_root.join("is_created")
autoload :IsStopped, action_root.join("is_stopped")
autoload :Import, action_root.join("import") autoload :Import, action_root.join("import")
autoload :ReadState, action_root.join("read_state") autoload :ReadState, action_root.join("read_state")
autoload :ResumeVM, action_root.join("resume_vm") autoload :ResumeVM, action_root.join("resume_vm")
autoload :StartInstance, action_root.join('start_instance') autoload :StartInstance, action_root.join('start_instance')
autoload :StopInstance, action_root.join('stop_instance') autoload :StopInstance, action_root.join('stop_instance')
autoload :SuspendVM, action_root.join("suspend_vm") autoload :SuspendVM, action_root.join("suspend_vm")
autoload :MessageNotCreated, action_root.join('message_not_created')
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
autoload :MessageNotRunning, action_root.join('message_not_running')
autoload :ReadGuestIP, action_root.join('read_guest_ip') autoload :ReadGuestIP, action_root.join('read_guest_ip')
autoload :WaitForIPAddress, action_root.join("wait_for_ip_address") autoload :WaitForIPAddress, action_root.join("wait_for_ip_address")
end end

View File

@ -1,22 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require "log4r"
module VagrantPlugins
module HyperV
module Action
class IsCreated
def initialize(app, env)
@app = app
end
def call(env)
env[:result] = env[:machine].state.id != :not_created
@app.call(env)
end
end
end
end
end

View File

@ -1,22 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require "log4r"
module VagrantPlugins
module HyperV
module Action
class IsStopped
def initialize(app, env)
@app = app
end
def call(env)
env[:result] = env[:machine].state.id == :off
@app.call(env)
end
end
end
end
end

View File

@ -1,22 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require "log4r"
module VagrantPlugins
module HyperV
module Action
class MessageAlreadyCreated
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info("Machine already created")
@app.call(env)
end
end
end
end
end

View File

@ -1,22 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require "log4r"
module VagrantPlugins
module HyperV
module Action
class MessageNotCreated
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info("Machine not created")
@app.call(env)
end
end
end
end
end

View File

@ -1,22 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require "log4r"
module VagrantPlugins
module HyperV
module Action
class MessageNotRunning
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info("Machine is not running, Please turn it on.")
@app.call(env)
end
end
end
end
end

View File

@ -4,6 +4,8 @@ en:
Hyper-V instance already running. Hyper-V instance already running.
message_not_created: |- message_not_created: |-
VM not created. Moving on... VM not created. Moving on...
message_not_running: |-
Hyper-V machine isn't running. Can't SSH in!
errors: errors:
admin_required: |- admin_required: |-