From 2e5e5920d780f8810176d318532ddec43700f1d1 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 28 Sep 2013 01:05:10 -0300 Subject: [PATCH] Shortcuts! --- lib/vagrant-lxc/action.rb | 80 ++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 08ce0c0..0ecc6d4 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -27,18 +27,22 @@ end module Vagrant module LXC module Action + # Shortcuts + Builtin = Vagrant::Action::Builtin + Builder = Vagrant::Action::Builder + # This action is responsible for reloading the machine, which # brings it down, sucks in new configuration, and brings the # machine back up with the new configuration. def self.action_reload - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| + Builder.new.tap do |b| + b.use Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created next end - b2.use Vagrant::Action::Builtin::ConfigValidate + b2.use Builtin::ConfigValidate b2.use action_halt b2.use action_start end @@ -48,35 +52,35 @@ module Vagrant # This action boots the VM, assuming the VM is in a state that requires # a bootup (i.e. not saved). def self.action_boot - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::Provision - b.use Vagrant::Action::Builtin::EnvSet, :port_collision_repair => true - b.use Vagrant::Action::Builtin::HandleForwardedPortCollisions + Builder.new.tap do |b| + b.use Builtin::Provision + b.use Builtin::EnvSet, :port_collision_repair => true + b.use Builtin::HandleForwardedPortCollisions b.use ShareFolders - b.use Vagrant::Action::Builtin::SetHostname + b.use Builtin::SetHostname b.use ForwardPorts b.use Boot - b.use Vagrant::Action::Builtin::WaitForCommunicator + b.use Builtin::WaitForCommunicator end end # This action just runs the provisioners on the machine. def self.action_provision - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::ConfigValidate - b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| + Builder.new.tap do |b| + b.use Builtin::ConfigValidate + b.use Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created next end - b2.use Vagrant::Action::Builtin::Call, IsRunning do |env2, b3| + b2.use Builtin::Call, IsRunning do |env2, b3| if !env2[:result] b3.use Message, :not_running next end - b3.use Vagrant::Action::Builtin::Provision + b3.use Builtin::Provision end end end @@ -85,9 +89,9 @@ module Vagrant # This action starts a container, assuming it is already created and exists. # A precondition of this action is that the container exists. def self.action_start - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::ConfigValidate - b.use Vagrant::Action::Builtin::Call, IsRunning do |env, b2| + Builder.new.tap do |b| + b.use Builtin::ConfigValidate + b.use Builtin::Call, IsRunning do |env, b2| # If the VM is running, then our work here is done, exit next if env[:result] # TODO: Check if has been saved / frozen and resume @@ -99,12 +103,12 @@ module Vagrant # This action brings the machine up from nothing, including creating the # container, configuring metadata, and booting. def self.action_up - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::ConfigValidate - b.use Vagrant::Action::Builtin::Call, Created do |env, b2| + Builder.new.tap do |b| + b.use Builtin::ConfigValidate + b.use Builtin::Call, Created do |env, b2| # If the VM is NOT created yet, then do the setup steps if !env[:result] - b2.use Vagrant::Action::Builtin::HandleBoxUrl + b2.use Builtin::HandleBoxUrl b2.use HandleBoxMetadata b2.use Create end @@ -116,14 +120,14 @@ module Vagrant # This is the action that is primarily responsible for halting # the virtual machine, gracefully or by force. def self.action_halt - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::Call, Created do |env, b2| + Builder.new.tap do |b| + b.use Builtin::Call, Created do |env, b2| if env[:result] # TODO: Check vagrant version and use only if lower than 1.X b2.use Disconnect b2.use ClearForwardedPorts b2.use RemoveTemporaryFiles - b2.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :stopped, :running do |env2, b3| + b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3| if !env2[:result] b3.use ForcedHalt end @@ -138,22 +142,22 @@ module Vagrant # This is the action that is primarily responsible for completely # freeing the resources of the underlying virtual machine. def self.action_destroy - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| + Builder.new.tap do |b| + b.use Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created next end # TODO: Use Vagrant's built in action - b2.use Vagrant::Action::Builtin::Call, DestroyConfirm do |env2, b3| + b2.use Builtin::Call, DestroyConfirm do |env2, b3| if env2[:result] - b3.use Vagrant::Action::Builtin::ConfigValidate - b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true + b3.use Builtin::ConfigValidate + b3.use Builtin::EnvSet, :force_halt => true b3.use action_halt b3.use Destroy if Vagrant::LXC.vagrant_1_3_or_later - b3.use Vagrant::Action::Builtin::ProvisionerCleanup + b3.use Builtin::ProvisionerCleanup end else b3.use Message, :will_not_destroy @@ -165,8 +169,8 @@ module Vagrant # This action packages the virtual machine into a single box file. def self.action_package - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| + Builder.new.tap do |b| + b.use Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created next @@ -183,8 +187,8 @@ module Vagrant # This action is called to read the IP of the container. The IP found # is expected to be put into the `:machine_ip` key. def self.action_fetch_ip - Vagrant::Action::Builder.new.tap do |b| - b.use Vagrant::Action::Builtin::ConfigValidate + Builder.new.tap do |b| + b.use Builtin::ConfigValidate b.use FetchIpWithLxcAttach b.use FetchIpFromDnsmasqLeases end @@ -192,19 +196,19 @@ module Vagrant # This is the action that will exec into an SSH shell. def self.action_ssh - Vagrant::Action::Builder.new.tap do |b| + Builder.new.tap do |b| b.use CheckCreated b.use CheckRunning - b.use Vagrant::Action::Builtin::SSHExec + b.use Builtin::SSHExec end end # This is the action that will run a single SSH command. def self.action_ssh_run - Vagrant::Action::Builder.new.tap do |b| + Builder.new.tap do |b| b.use CheckCreated b.use CheckRunning - b.use Vagrant::Action::Builtin::SSHRun + b.use Builtin::SSHRun end end end