diff --git a/Vagrantfile.dev b/Vagrantfile.dev index 6bdbdbf..cf5d1b2 100644 --- a/Vagrantfile.dev +++ b/Vagrantfile.dev @@ -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, diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index aa3d257..b42a3f8 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -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 diff --git a/lib/vagrant-lxc/action/after_create.rb b/lib/vagrant-lxc/action/after_create.rb new file mode 100644 index 0000000..866e9ea --- /dev/null +++ b/lib/vagrant-lxc/action/after_create.rb @@ -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 diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb new file mode 100644 index 0000000..2572314 --- /dev/null +++ b/lib/vagrant-lxc/action/boot.rb @@ -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 diff --git a/lib/vagrant-lxc/action/check_created.rb b/lib/vagrant-lxc/action/check_created.rb new file mode 100644 index 0000000..7c43455 --- /dev/null +++ b/lib/vagrant-lxc/action/check_created.rb @@ -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 diff --git a/lib/vagrant-lxc/action/check_running.rb b/lib/vagrant-lxc/action/check_running.rb new file mode 100644 index 0000000..9f6d189 --- /dev/null +++ b/lib/vagrant-lxc/action/check_running.rb @@ -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 diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb new file mode 100644 index 0000000..bbb2d63 --- /dev/null +++ b/lib/vagrant-lxc/action/create.rb @@ -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 diff --git a/lib/vagrant-lxc/action/created.rb b/lib/vagrant-lxc/action/created.rb new file mode 100644 index 0000000..b4c4cc7 --- /dev/null +++ b/lib/vagrant-lxc/action/created.rb @@ -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 diff --git a/lib/vagrant-lxc/action/destroy.rb b/lib/vagrant-lxc/action/destroy.rb new file mode 100644 index 0000000..e249093 --- /dev/null +++ b/lib/vagrant-lxc/action/destroy.rb @@ -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 diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index a67c14e..239a58e 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -1,5 +1,3 @@ -require 'vagrant-lxc/action/base_action' - module Vagrant module LXC module Action diff --git a/lib/vagrant-lxc/action/is_running.rb b/lib/vagrant-lxc/action/is_running.rb new file mode 100644 index 0000000..194ec3e --- /dev/null +++ b/lib/vagrant-lxc/action/is_running.rb @@ -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 diff --git a/spec/unit/action/handle_box_metadata_spec.rb b/spec/unit/action/handle_box_metadata_spec.rb index 9953ad6..f7fe0eb 100644 --- a/spec/unit/action/handle_box_metadata_spec.rb +++ b/spec/unit/action/handle_box_metadata_spec.rb @@ -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