Move action classes into their own files
This commit is contained in:
parent
8a54b8dde8
commit
30d163d4bb
12 changed files with 130 additions and 86 deletions
|
@ -6,9 +6,6 @@ Vagrant::Config.run do |config|
|
||||||
config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
|
config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
|
||||||
|
|
||||||
config.vm.network :hostonly, "192.168.33.10"
|
config.vm.network :hostonly, "192.168.33.10"
|
||||||
config.vm.forward_port 80, 8080
|
|
||||||
config.vm.forward_port 2222, 2223
|
|
||||||
|
|
||||||
config.vm.customize [
|
config.vm.customize [
|
||||||
"modifyvm", :id,
|
"modifyvm", :id,
|
||||||
"--memory", 1024,
|
"--memory", 1024,
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
require 'vagrant-lxc/action/base_action'
|
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 Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
@ -154,85 +162,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
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.
|
# TODO: Check if our requirements are met.
|
||||||
class CheckLXC < BaseAction; end
|
class CheckLXC < BaseAction; end
|
||||||
|
|
||||||
|
|
14
lib/vagrant-lxc/action/after_create.rb
Normal file
14
lib/vagrant-lxc/action/after_create.rb
Normal 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
|
12
lib/vagrant-lxc/action/boot.rb
Normal file
12
lib/vagrant-lxc/action/boot.rb
Normal 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
|
17
lib/vagrant-lxc/action/check_created.rb
Normal file
17
lib/vagrant-lxc/action/check_created.rb
Normal 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
|
17
lib/vagrant-lxc/action/check_running.rb
Normal file
17
lib/vagrant-lxc/action/check_running.rb
Normal 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
|
14
lib/vagrant-lxc/action/create.rb
Normal file
14
lib/vagrant-lxc/action/create.rb
Normal 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
|
16
lib/vagrant-lxc/action/created.rb
Normal file
16
lib/vagrant-lxc/action/created.rb
Normal 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
|
13
lib/vagrant-lxc/action/destroy.rb
Normal file
13
lib/vagrant-lxc/action/destroy.rb
Normal 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
|
|
@ -1,5 +1,3 @@
|
||||||
require 'vagrant-lxc/action/base_action'
|
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
|
16
lib/vagrant-lxc/action/is_running.rb
Normal file
16
lib/vagrant-lxc/action/is_running.rb
Normal 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
|
|
@ -1,5 +1,6 @@
|
||||||
require 'unit_helper'
|
require 'unit_helper'
|
||||||
|
|
||||||
|
require 'vagrant-lxc/action/base_action'
|
||||||
require 'vagrant-lxc/action/handle_box_metadata'
|
require 'vagrant-lxc/action/handle_box_metadata'
|
||||||
|
|
||||||
describe Vagrant::LXC::Action::HandleBoxMetadata do
|
describe Vagrant::LXC::Action::HandleBoxMetadata do
|
||||||
|
|
Loading…
Reference in a new issue