lib/vagrant-vcloud/action.rb in vagrant-vcloud-0.1.2 vs lib/vagrant-vcloud/action.rb in vagrant-vcloud-0.2.0
- old
+ new
@@ -1,7 +1,7 @@
-require "pathname"
-require "vagrant/action/builder"
+require 'pathname'
+require 'vagrant/action/builder'
module VagrantPlugins
module VCloud
module Action
include Vagrant::Action::Builtin
@@ -9,23 +9,28 @@
# Vagrant commands
# 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 ConfigValidate
b.use PowerOn
- b.use HandleNATPortCollisions
- b.use ForwardPorts
+ b.use Call, IsCreated do |env, b2|
+ unless env[:bridged_network]
+ b2.use HandleNATPortCollisions
+ b2.use ForwardPorts
+ end
+ end
b.use Provision
b.use SyncFolders
end
end
def self.action_reload
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ unless env[:result]
b2.use MessageNotCreated
next
end
b2.use action_halt
b2.use action_start
@@ -57,18 +62,19 @@
end
end
def self.action_halt
Vagrant::Action::Builder.new.tap do |b|
+ b.use ConfigValidate
b.use ConnectVCloud
b.use Call, IsPaused do |env, b2|
- if env[:result]
- b2.use Resume
- end
- b2.use UnmapPortForwardings
- b2.use PowerOff
+ b2.use Resume if env[:result]
end
+ b.use Call, IsBridged do |env, b2|
+ b2.use UnmapPortForwardings unless env[:bridged_network]
+ end
+ b.use PowerOff
end
end
def self.action_suspend
Vagrant::Action::Builder.new.tap do |b|
@@ -97,15 +103,13 @@
if env[:result]
b2.use ConfigValidate
b2.use ConnectVCloud
b2.use Call, IsRunning do |env2, b3|
# If the VM is running, must power off
- if env2[:result]
- b3.use action_halt
- end
+ b3.use action_halt if env2[:result]
b3.use Destroy
- end
+ end
else
b2.use MessageWillNotDestroy
end
end
end
@@ -113,11 +117,11 @@
def self.action_provision
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ unless env[:result]
b2.use MessageNotCreated
next
end
b2.use Provision
b2.use SyncFolders
@@ -149,26 +153,26 @@
def self.action_ssh
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ unless env[:result]
b2.use MessageNotCreated
next
end
# This calls our helper that announces the IP used to connect
- # to the VM, either directly to the vApp vShield or to the Org Edge.
+ # to the VM, either directly to the vApp vShield or to the Org Edge
b2.use AnnounceSSHExec
end
end
end
def self.action_ssh_run
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ unless env[:result]
b2.use MessageNotCreated
next
end
b2.use SSHRun
@@ -178,49 +182,72 @@
def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
- b2.use HandleBoxUrl
- end
+ b2.use HandleBox unless env[:result]
end
b.use ConnectVCloud
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ unless env[:result]
b2.use InventoryCheck
b2.use BuildVApp
end
end
b.use action_start
b.use DisconnectVCloud
end
end
# The autoload farm
- action_root = Pathname.new(File.expand_path("../action", __FILE__))
- autoload :AnnounceSSHExec, action_root.join("announce_ssh_exec")
- autoload :BuildVApp, action_root.join("build_vapp")
- autoload :ConnectVCloud, action_root.join("connect_vcloud")
- autoload :Destroy, action_root.join("destroy")
- autoload :DisconnectVCloud, action_root.join("disconnect_vcloud")
- autoload :ForwardPorts, action_root.join("forward_ports")
- autoload :HandleNATPortCollisions, action_root.join("handle_nat_port_collisions")
- autoload :InventoryCheck, action_root.join("inventory_check")
- autoload :IsCreated, action_root.join("is_created")
- autoload :IsPaused, action_root.join("is_paused")
- autoload :IsRunning, action_root.join("is_running")
- autoload :MessageAlreadyRunning, action_root.join("message_already_running")
- autoload :MessageCannotSuspend, action_root.join("message_cannot_suspend")
- autoload :MessageNotCreated, action_root.join("message_not_created")
- autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
- autoload :PowerOff, action_root.join("power_off")
- autoload :PowerOn, action_root.join("power_on")
- autoload :ReadSSHInfo, action_root.join("read_ssh_info")
- autoload :ReadState, action_root.join("read_state")
- autoload :Resume, action_root.join("resume")
- autoload :Suspend, action_root.join("suspend")
- autoload :SyncFolders, action_root.join("sync_folders")
- autoload :UnmapPortForwardings, action_root.join("unmap_port_forwardings")
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
+ autoload :AnnounceSSHExec,
+ action_root.join('announce_ssh_exec')
+ autoload :BuildVApp,
+ action_root.join('build_vapp')
+ autoload :ConnectVCloud,
+ action_root.join('connect_vcloud')
+ autoload :Destroy,
+ action_root.join('destroy')
+ autoload :DisconnectVCloud,
+ action_root.join('disconnect_vcloud')
+ autoload :ForwardPorts,
+ action_root.join('forward_ports')
+ autoload :HandleNATPortCollisions,
+ action_root.join('handle_nat_port_collisions')
+ autoload :InventoryCheck,
+ action_root.join('inventory_check')
+ autoload :IsCreated,
+ action_root.join('is_created')
+ autoload :IsBridged,
+ action_root.join('is_bridged')
+ autoload :IsPaused,
+ action_root.join('is_paused')
+ autoload :IsRunning,
+ action_root.join('is_running')
+ autoload :MessageAlreadyRunning,
+ action_root.join('message_already_running')
+ autoload :MessageCannotSuspend,
+ action_root.join('message_cannot_suspend')
+ autoload :MessageNotCreated,
+ action_root.join('message_not_created')
+ autoload :MessageWillNotDestroy,
+ action_root.join('message_will_not_destroy')
+ autoload :PowerOff,
+ action_root.join('power_off')
+ autoload :PowerOn,
+ action_root.join('power_on')
+ autoload :ReadSSHInfo,
+ action_root.join('read_ssh_info')
+ autoload :ReadState,
+ action_root.join('read_state')
+ autoload :Resume,
+ action_root.join('resume')
+ autoload :Suspend,
+ action_root.join('suspend')
+ autoload :SyncFolders,
+ action_root.join('sync_folders')
+ autoload :UnmapPortForwardings,
+ action_root.join('unmap_port_forwardings')
end
end
-end
\ No newline at end of file
+end