core: Remove actions that check for containers statuses

This commit is contained in:
Fabio Rehm 2014-03-12 23:34:16 -03:00
parent 35741ba5c5
commit 61002b9bb8
5 changed files with 54 additions and 112 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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