From af4bc18c143dc2c93adba7b6b4c7823cbbbb1fde Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 26 Feb 2014 17:52:38 -0800 Subject: [PATCH] providers/hyperv: use IsState and Message built-ins everywhere --- plugins/providers/hyperv/action.rb | 55 +++++++++---------- plugins/providers/hyperv/action/is_created.rb | 22 -------- plugins/providers/hyperv/action/is_stopped.rb | 22 -------- .../hyperv/action/message_already_created.rb | 22 -------- .../hyperv/action/message_not_created.rb | 22 -------- .../hyperv/action/message_not_running.rb | 22 -------- templates/locales/providers_hyperv.yml | 2 + 7 files changed, 28 insertions(+), 139 deletions(-) delete mode 100644 plugins/providers/hyperv/action/is_created.rb delete mode 100644 plugins/providers/hyperv/action/is_stopped.rb delete mode 100644 plugins/providers/hyperv/action/message_already_created.rb delete mode 100644 plugins/providers/hyperv/action/message_not_created.rb delete mode 100644 plugins/providers/hyperv/action/message_not_running.rb diff --git a/plugins/providers/hyperv/action.rb b/plugins/providers/hyperv/action.rb index 81e5dc6ce..abda706da 100644 --- a/plugins/providers/hyperv/action.rb +++ b/plugins/providers/hyperv/action.rb @@ -11,9 +11,9 @@ module VagrantPlugins def self.action_reload Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate - b.use Call, IsCreated do |env, b2| - if !env[:result] - b2.use MessageNotCreated + b.use Call, IsState, :not_created do |env, b2| + if env[:result] + b2.use Message, I18n.t("vagrant_hyperv.message_not_created") next end @@ -25,9 +25,9 @@ module VagrantPlugins def self.action_destroy Vagrant::Action::Builder.new.tap do |b| - b.use Call, IsCreated do |env1, b1| - if !env1[:result] - b1.use MessageNotCreated + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant_hyperv.message_not_created") next end @@ -48,9 +48,9 @@ module VagrantPlugins def self.action_halt Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate - b.use Call, IsCreated do |env, b2| - if !env[:result] - b2.use MessageNotCreated + b.use Call, IsState, :not_created do |env, b2| + if env[:result] + b2.use Message, I18n.t("vagrant_hyperv.message_not_created") next end @@ -67,8 +67,8 @@ module VagrantPlugins Vagrant::Action::Builder.new.tap do |b| b.use HandleBox b.use ConfigValidate - b.use Call, IsCreated do |env1, b1| - if !env1[:result] + b.use Call, IsState, :not_created do |env, b2| + if env1[:result] b1.use Message, I18n.t("vagrant_hyperv.message_not_created") next end @@ -108,8 +108,8 @@ module VagrantPlugins Vagrant::Action::Builder.new.tap do |b| b.use HandleBox b.use ConfigValidate - b.use Call, IsCreated do |env1, b1| - if !env1[:result] + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] b1.use Import end @@ -128,17 +128,19 @@ module VagrantPlugins def self.action_ssh Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate - b.use Call, IsCreated do |env, b2| - if !env[:result] - b2.use MessageNotCreated + b.use Call, IsState, :not_created do |env, b2| + if env[:result] + b2.use Message, I18n.t("vagrant_hyperv.message_not_created") next end - b2.use Call, IsStopped do |env1, b3| - if env1[:result] - b3.use MessageNotRunning - else - b3.use SSHExec + + b2.use Call, IsState, :running do |env1, b3| + if !env1[:result] + b3.use Message, I18n.t("vagrant_hyperv.message_not_running") + next end + + b3.use SSHExec end end end @@ -147,9 +149,9 @@ module VagrantPlugins def self.action_suspend Vagrant::Action::Builder.new.tap do |b| b.use ConfigValidate - b.use Call, IsCreated do |env, b2| - if !env[:result] - b2.use MessageNotCreated + b.use Call, IsState, :not_created do |env, b2| + if env[:result] + b2.use Message, I18n.t("vagrant_hyperv.message_not_created") next end @@ -169,17 +171,12 @@ module VagrantPlugins # The autoload farm action_root = Pathname.new(File.expand_path("../action", __FILE__)) 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 :ReadState, action_root.join("read_state") autoload :ResumeVM, action_root.join("resume_vm") autoload :StartInstance, action_root.join('start_instance') autoload :StopInstance, action_root.join('stop_instance') 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 :WaitForIPAddress, action_root.join("wait_for_ip_address") end diff --git a/plugins/providers/hyperv/action/is_created.rb b/plugins/providers/hyperv/action/is_created.rb deleted file mode 100644 index 1d9934f99..000000000 --- a/plugins/providers/hyperv/action/is_created.rb +++ /dev/null @@ -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 diff --git a/plugins/providers/hyperv/action/is_stopped.rb b/plugins/providers/hyperv/action/is_stopped.rb deleted file mode 100644 index 83e87bd8c..000000000 --- a/plugins/providers/hyperv/action/is_stopped.rb +++ /dev/null @@ -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 diff --git a/plugins/providers/hyperv/action/message_already_created.rb b/plugins/providers/hyperv/action/message_already_created.rb deleted file mode 100644 index 72e4b052d..000000000 --- a/plugins/providers/hyperv/action/message_already_created.rb +++ /dev/null @@ -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 diff --git a/plugins/providers/hyperv/action/message_not_created.rb b/plugins/providers/hyperv/action/message_not_created.rb deleted file mode 100644 index 5af00f180..000000000 --- a/plugins/providers/hyperv/action/message_not_created.rb +++ /dev/null @@ -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 diff --git a/plugins/providers/hyperv/action/message_not_running.rb b/plugins/providers/hyperv/action/message_not_running.rb deleted file mode 100644 index 1a5ca2502..000000000 --- a/plugins/providers/hyperv/action/message_not_running.rb +++ /dev/null @@ -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 diff --git a/templates/locales/providers_hyperv.yml b/templates/locales/providers_hyperv.yml index 5d560741c..92f265b50 100644 --- a/templates/locales/providers_hyperv.yml +++ b/templates/locales/providers_hyperv.yml @@ -4,6 +4,8 @@ en: Hyper-V instance already running. message_not_created: |- VM not created. Moving on... + message_not_running: |- + Hyper-V machine isn't running. Can't SSH in! errors: admin_required: |-