From 61002b9bb861fd5ac31846fc9da79b3d2d8eb916 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 12 Mar 2014 23:34:16 -0300 Subject: [PATCH] core: Remove actions that check for containers statuses --- lib/vagrant-lxc/action.rb | 85 ++++++++++++++++--------- lib/vagrant-lxc/action/check_created.rb | 21 ------ lib/vagrant-lxc/action/check_running.rb | 21 ------ lib/vagrant-lxc/action/created.rb | 20 ------ lib/vagrant-lxc/action/is_running.rb | 19 ------ 5 files changed, 54 insertions(+), 112 deletions(-) delete mode 100644 lib/vagrant-lxc/action/check_created.rb delete mode 100644 lib/vagrant-lxc/action/check_running.rb delete mode 100644 lib/vagrant-lxc/action/created.rb delete mode 100644 lib/vagrant-lxc/action/is_running.rb diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 81e0b25..ce53061 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -1,9 +1,6 @@ require 'vagrant-lxc/action/boot' -require 'vagrant-lxc/action/check_created' -require 'vagrant-lxc/action/check_running' require 'vagrant-lxc/action/clear_forwarded_ports' require 'vagrant-lxc/action/create' -require 'vagrant-lxc/action/created' require 'vagrant-lxc/action/destroy' require 'vagrant-lxc/action/destroy_confirm' require 'vagrant-lxc/action/compress_rootfs' @@ -12,7 +9,6 @@ require 'vagrant-lxc/action/fetch_ip_from_dnsmasq_leases' require 'vagrant-lxc/action/forced_halt' require 'vagrant-lxc/action/forward_ports' require 'vagrant-lxc/action/handle_box_metadata' -require 'vagrant-lxc/action/is_running' require 'vagrant-lxc/action/prepare_nfs_settings' require 'vagrant-lxc/action/prepare_nfs_valid_ids' require 'vagrant-lxc/action/remove_temporary_files' @@ -41,8 +37,8 @@ module Vagrant # machine back up with the new configuration. def self.action_reload Builder.new.tap do |b| - b.use Builtin::Call, Created do |env1, b2| - if !env1[:result] + b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2| + if env1[:result] b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end @@ -82,13 +78,13 @@ module Vagrant def self.action_provision Builder.new.tap do |b| b.use Builtin::ConfigValidate - b.use Builtin::Call, Created do |env1, b2| - if !env1[:result] + b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2| + if env1[:result] b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end - b2.use Builtin::Call, IsRunning do |env2, b3| + b2.use Builtin::Call, Builtin::IsState, :running do |env2, b3| if !env2[:result] b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running") next @@ -105,7 +101,7 @@ module Vagrant def self.action_start Builder.new.tap do |b| b.use Builtin::ConfigValidate - b.use Builtin::Call, IsRunning do |env, b2| + b.use Builtin::Call, Builtin::IsState, :running do |env, b2| # If the VM is running, then our work here is done, exit next if env[:result] b2.use action_boot @@ -118,9 +114,9 @@ module Vagrant def self.action_up Builder.new.tap do |b| b.use Builtin::ConfigValidate - b.use Builtin::Call, Created do |env, b2| + b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2| # If the VM is NOT created yet, then do the setup steps - if !env[:result] + if env[:result] b2.use Builtin::HandleBox b2.use HandleBoxMetadata b2.use Create @@ -134,17 +130,18 @@ module Vagrant # the virtual machine, gracefully or by force. def self.action_halt Builder.new.tap do |b| - b.use Builtin::Call, Created do |env, b2| + b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2| if env[:result] - b2.use ClearForwardedPorts - b2.use RemoveTemporaryFiles - b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3| - if !env2[:result] - b3.use ForcedHalt - end - end - else b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") + 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 end end end @@ -154,8 +151,8 @@ module Vagrant # freeing the resources of the underlying virtual machine. def self.action_destroy Builder.new.tap do |b| - b.use Builtin::Call, Created do |env1, b2| - if !env1[:result] + b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2| + if env1[:result] b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end @@ -181,8 +178,8 @@ module Vagrant # This action packages the virtual machine into a single box file. def self.action_package Builder.new.tap do |b| - b.use Builtin::Call, Created do |env1, b2| - if !env1[:result] + b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2| + if env1[:result] b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end @@ -208,18 +205,44 @@ module Vagrant # This is the action that will exec into an SSH shell. def self.action_ssh Builder.new.tap do |b| - b.use CheckCreated - b.use CheckRunning - b.use Builtin::SSHExec + 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 + + b3.use BuiltIn::SSHExec + end + end end end # This is the action that will run a single SSH command. def self.action_ssh_run Builder.new.tap do |b| - b.use CheckCreated - b.use CheckRunning - b.use Builtin::SSHRun + 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 + + b3.use Builtin::SSHRun + end + end end end end diff --git a/lib/vagrant-lxc/action/check_created.rb b/lib/vagrant-lxc/action/check_created.rb deleted file mode 100644 index 94f7cb8..0000000 --- a/lib/vagrant-lxc/action/check_created.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Vagrant - module LXC - module Action - class CheckCreated - def initialize(app, env) - @app = app - end - - def call(env) - if env[:machine].state.id == :not_created - raise Vagrant::Errors::VMNotCreatedError - end - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-lxc/action/check_running.rb b/lib/vagrant-lxc/action/check_running.rb deleted file mode 100644 index c4481a3..0000000 --- a/lib/vagrant-lxc/action/check_running.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Vagrant - module LXC - module Action - class CheckRunning - def initialize(app, env) - @app = app - end - - def call(env) - if env[:machine].state.id != :running - raise Vagrant::Errors::VMNotRunningError - end - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-lxc/action/created.rb b/lib/vagrant-lxc/action/created.rb deleted file mode 100644 index 71897e9..0000000 --- a/lib/vagrant-lxc/action/created.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Vagrant - module LXC - module Action - class Created - def initialize(app, env) - @app = app - end - - def call(env) - # Set the result to be true if the machine is created. - env[:result] = env[:machine].state.id != :not_created - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-lxc/action/is_running.rb b/lib/vagrant-lxc/action/is_running.rb deleted file mode 100644 index 0c14e2d..0000000 --- a/lib/vagrant-lxc/action/is_running.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Vagrant - module LXC - module Action - class IsRunning - def initialize(app, env) - @app = app - end - - def call(env) - env[:result] = env[:machine].state.id == :running - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end