💣 BaseAction

This commit is contained in:
Fabio Rehm 2013-04-01 21:05:19 -03:00
parent 0ad76b753a
commit 164e57695e
14 changed files with 52 additions and 29 deletions

View file

@ -1,7 +1,3 @@
# TODO: Remove base action
require 'vagrant-lxc/action/base_action'
# TODO: Use require_relative
require 'vagrant-lxc/action/boot'
require 'vagrant-lxc/action/check_created'
require 'vagrant-lxc/action/check_running'

View file

@ -1,11 +0,0 @@
module Vagrant
module LXC
module Action
class BaseAction
def initialize(app, env)
@app = app
end
end
end
end
end

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class Boot < BaseAction
class Boot
def initialize(app, env)
@app = app
end
def call(env)
@env = env

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class CheckCreated < BaseAction
class CheckCreated
def initialize(app, env)
@app = app
end
def call(env)
unless env[:machine].state.created?
raise Vagrant::Errors::VMNotCreatedError

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class CheckRunning < BaseAction
class CheckRunning
def initialize(app, env)
@app = app
end
def call(env)
unless env[:machine].state.running?
raise Vagrant::Errors::VMNotRunningError

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class Create < BaseAction
class Create
def initialize(app, env)
@app = app
end
def call(env)
base_name = env[:root_path].basename.to_s
base_name.gsub!(/[^-a-z0-9_]/i, "")

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class Created < BaseAction
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.created?

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class Destroy < BaseAction
class Destroy
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
env[:machine].provider.container.destroy

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class Disconnect < BaseAction
class Disconnect
def initialize(app, env)
@app = app
end
def call(env)
@app.call env
# FIXME: Vagrant >= 1.1.3 should not need this

View file

@ -2,12 +2,12 @@ module Vagrant
module LXC
module Action
# Prepare arguments to be used for lxc-create
class HandleBoxMetadata < BaseAction
class HandleBoxMetadata
LXC_TEMPLATES_PATH = Pathname.new("/usr/share/lxc/templates")
TEMP_PREFIX = "vagrant-lxc-rootfs-temp-"
def initialize(app, env)
super
@app = app
@logger = Log4r::Logger.new("vagrant::lxc::action::handle_box_metadata")
end

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class IsRunning < BaseAction
class IsRunning
def initialize(app, env)
@app = app
end
def call(env)
env[:result] = env[:machine].state.running?

View file

@ -1,9 +1,12 @@
module Vagrant
module LXC
module Action
class Network < BaseAction
class Network
def initialize(app, env)
@app = app
end
def call(env)
# TODO: Validate network configuration prior to anything below
@env = env
env[:machine].config.vm.networks.each do |type, options|

View file

@ -1,7 +1,11 @@
module Vagrant
module LXC
module Action
class ShareFolders < BaseAction
class ShareFolders
def initialize(app, env)
@app = app
end
def call(env)
@env = env
prepare_folders

View file

@ -1,6 +1,5 @@
require 'unit_helper'
require 'vagrant-lxc/action/base_action'
require 'vagrant-lxc/action/handle_box_metadata'
describe Vagrant::LXC::Action::HandleBoxMetadata do