Move action classes into their own files

This commit is contained in:
Fabio Rehm 2013-03-03 02:24:05 -03:00
parent 8a54b8dde8
commit 30d163d4bb
12 changed files with 130 additions and 86 deletions

View file

@ -6,9 +6,6 @@ Vagrant::Config.run do |config|
config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
config.vm.network :hostonly, "192.168.33.10"
config.vm.forward_port 80, 8080
config.vm.forward_port 2222, 2223
config.vm.customize [
"modifyvm", :id,
"--memory", 1024,

View file

@ -1,7 +1,15 @@
require 'vagrant-lxc/action/base_action'
require 'vagrant-lxc/action/handle_box_metadata'
# TODO: Split action classes into their own files
require 'vagrant-lxc/action/after_create'
require 'vagrant-lxc/action/boot'
require 'vagrant-lxc/action/check_created'
require 'vagrant-lxc/action/check_running'
require 'vagrant-lxc/action/create'
require 'vagrant-lxc/action/created'
require 'vagrant-lxc/action/destroy'
require 'vagrant-lxc/action/handle_box_metadata'
require 'vagrant-lxc/action/is_running'
module Vagrant
module LXC
module Action
@ -154,85 +162,6 @@ module Vagrant
end
end
class CheckCreated < BaseAction
def call(env)
unless env[:machine].state.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
class CheckRunning < BaseAction
def call(env)
unless env[:machine].state.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
class Created < BaseAction
def call(env)
# Set the result to be true if the machine is created.
env[:result] = env[:machine].state.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
class IsRunning < BaseAction
def call(env)
# Set the result to be true if the machine is created.
env[:result] = env[:machine].state.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
class Create < BaseAction
def call(env)
machine_id = env[:machine].provider.container.create(env[:machine].box.metadata)
env[:machine].id = machine_id
env[:just_created] = true
@app.call env
end
end
class AfterCreate < BaseAction
def call(env)
if env[:just_created] && (script = env[:machine].box.metadata['after-create-script'])
env[:machine].provider.container.run_after_create_script script
end
@app.call env
end
end
class Destroy < BaseAction
def call(env)
env[:machine].provider.container.destroy
env[:machine].id = nil
@app.call env
end
end
class Boot < BaseAction
def call(env)
env[:machine].provider.container.start
@app.call env
end
end
# TODO: Check if our requirements are met.
class CheckLXC < BaseAction; end

View file

@ -0,0 +1,14 @@
module Vagrant
module LXC
module Action
class AfterCreate < BaseAction
def call(env)
if env[:just_created] && (script = env[:machine].box.metadata['after-create-script'])
env[:machine].provider.container.run_after_create_script script
end
@app.call env
end
end
end
end
end

View file

@ -0,0 +1,12 @@
module Vagrant
module LXC
module Action
class Boot < BaseAction
def call(env)
env[:machine].provider.container.start
@app.call env
end
end
end
end
end

View file

@ -0,0 +1,17 @@
module Vagrant
module LXC
module Action
class CheckCreated < BaseAction
def call(env)
unless env[:machine].state.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

@ -0,0 +1,17 @@
module Vagrant
module LXC
module Action
class CheckRunning < BaseAction
def call(env)
unless env[:machine].state.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

@ -0,0 +1,14 @@
module Vagrant
module LXC
module Action
class Create < BaseAction
def call(env)
machine_id = env[:machine].provider.container.create(env[:machine].box.metadata)
env[:machine].id = machine_id
env[:just_created] = true
@app.call env
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Vagrant
module LXC
module Action
class Created < BaseAction
def call(env)
# Set the result to be true if the machine is created.
env[:result] = env[:machine].state.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

@ -0,0 +1,13 @@
module Vagrant
module LXC
module Action
class Destroy < BaseAction
def call(env)
env[:machine].provider.container.destroy
env[:machine].id = nil
@app.call env
end
end
end
end
end

View file

@ -1,5 +1,3 @@
require 'vagrant-lxc/action/base_action'
module Vagrant
module LXC
module Action

View file

@ -0,0 +1,16 @@
module Vagrant
module LXC
module Action
class IsRunning < BaseAction
def call(env)
# Set the result to be true if the machine is created.
env[:result] = env[:machine].state.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

View file

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