Module: VagrantPlugins::VCloud::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-vcloud/action.rb,
lib/vagrant-vcloud/action/resume.rb,
lib/vagrant-vcloud/action/suspend.rb,
lib/vagrant-vcloud/action/power_on.rb,
lib/vagrant-vcloud/action/is_paused.rb,
lib/vagrant-vcloud/action/power_off.rb,
lib/vagrant-vcloud/action/shut_down.rb,
lib/vagrant-vcloud/action/build_vapp.rb,
lib/vagrant-vcloud/action/destroy_vm.rb,
lib/vagrant-vcloud/action/is_bridged.rb,
lib/vagrant-vcloud/action/is_created.rb,
lib/vagrant-vcloud/action/is_last_vm.rb,
lib/vagrant-vcloud/action/is_running.rb,
lib/vagrant-vcloud/action/read_state.rb,
lib/vagrant-vcloud/action/destroy_vapp.rb,
lib/vagrant-vcloud/action/sync_folders.rb,
lib/vagrant-vcloud/action/forward_ports.rb,
lib/vagrant-vcloud/action/read_ssh_info.rb,
lib/vagrant-vcloud/action/connect_vcloud.rb,
lib/vagrant-vcloud/action/power_off_vapp.rb,
lib/vagrant-vcloud/action/inventory_check.rb,
lib/vagrant-vcloud/action/announce_ssh_exec.rb,
lib/vagrant-vcloud/action/disconnect_vcloud.rb,
lib/vagrant-vcloud/action/message_not_created.rb,
lib/vagrant-vcloud/action/message_not_running.rb,
lib/vagrant-vcloud/action/message_cannot_suspend.rb,
lib/vagrant-vcloud/action/unmap_port_forwardings.rb,
lib/vagrant-vcloud/action/message_already_running.rb,
lib/vagrant-vcloud/action/message_will_not_destroy.rb,
lib/vagrant-vcloud/action/handle_nat_port_collisions.rb

Overview

This module dictates the actions to be performed by Vagrant when called with a specific command

Defined Under Namespace

Classes: AnnounceSSHExec, BuildVApp, ConnectVCloud, DestroyVApp, DestroyVM, DisconnectVCloud, ForwardPorts, HandleNATPortCollisions, InventoryCheck, IsBridged, IsCreated, IsLastVM, IsPaused, IsRunning, MessageAlreadyRunning, MessageCannotSuspend, MessageNotCreated, MessageNotRunning, MessageWillNotDestroy, PowerOff, PowerOffVApp, PowerOn, ReadSSHInfo, ReadState, Resume, ShutDown, Suspend, SyncFolders, UnmapPortForwardings

Class Method Summary collapse

Class Method Details

.action_bootObject

Vagrant commands This action boots the VM, assuming the VM is in a state that requires a bootup (i.e. not saved).


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-vcloud/action.rb', line 14

def self.action_boot
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use PowerOn
    b.use Call, IsCreated do |env, b2|
      unless env[:bridged_network]
        b2.use HandleNATPortCollisions
        b2.use ForwardPorts
      end
      cfg = env[:machine].provider_config
      if cfg.power_on.nil? || cfg.power_on == true
        if cfg.ssh_enabled.nil? || cfg.ssh_enabled == true
          b2.use WaitForCommunicator, [:starting, :running]
        end
      end
      b2.use Provision
      if cfg.power_on.nil? || cfg.power_on == true # can't ssh if not on
        if cfg.ssh_enabled.nil? || cfg.ssh_enabled == true  # can't sync if ssh is disabled
          if cfg.sync_enabled.nil? || cfg.sync_enabled == true
            b2.use SyncFolders
          end
        end
      end
    end
  end
end

.action_destroyObject


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/vagrant-vcloud/action.rb', line 116

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, DestroyConfirm do |env, b2|
      if env[:result]
        b2.use ConfigValidate
        b2.use ConnectVCloud
        b2.use Call, IsCreated do |env2, b3|
          unless env2[:result]
            b3.use MessageNotCreated
            next
          end

          b3.use Call, IsRunning do |env3, b4|
          # If the VM is running, must power off
            b4.use action_poweroff if env3[:result]
          end
          b3.use Call, IsLastVM do |env3, b4|
            if env3[:result]
              # Check if the network is bridged
              # b4.use Call, IsBridged do |env4, b5|
              #   # if it's not, delete port forwardings.
              #   b5.use UnmapPortForwardings unless env4[:bridged_network] || env4[:advanced_network]
              # end
              b4.use PowerOffVApp
              b4.use DestroyVApp
            else
              b4.use DestroyVM
            end
          end
          b3.use ProvisionerCleanup
        end
      else
        b2.use MessageWillNotDestroy
      end
    end
  end
end

.action_haltObject


84
85
86
87
88
89
90
91
92
93
# File 'lib/vagrant-vcloud/action.rb', line 84

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectVCloud
    b.use Call, IsPaused do |env, b2|
      b2.use Resume if env[:result]
    end
    b.use ShutDown
  end
end

.action_poweroffObject


73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant-vcloud/action.rb', line 73

def self.action_poweroff
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectVCloud
    b.use Call, IsPaused do |env, b2|
      b2.use Resume if env[:result]
    end
    b.use PowerOff
  end
end

.action_provisionObject


154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/vagrant-vcloud/action.rb', line 154

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use Provision
      b2.use SyncFolders
    end
  end
end

.action_read_rdp_infoObject


185
186
187
188
189
190
# File 'lib/vagrant-vcloud/action.rb', line 185

def self.action_read_rdp_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloud
    b.use ReadSSHInfo, 3389
  end
end

.action_read_ssh_infoObject

This action is called to read the SSH info of the machine. The resulting state is expected to be put into the `:machine_ssh_info` key.


171
172
173
174
175
176
# File 'lib/vagrant-vcloud/action.rb', line 171

def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloud
    b.use ReadSSHInfo, 22
  end
end

.action_read_stateObject

This action is called to read the state of the machine. The resulting state is expected to be put into the `:machine_state_id` key.


195
196
197
198
199
200
201
# File 'lib/vagrant-vcloud/action.rb', line 195

def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectVCloud
    b.use ReadState
  end
end

.action_read_winrm_infoObject


178
179
180
181
182
183
# File 'lib/vagrant-vcloud/action.rb', line 178

def self.action_read_winrm_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloud
    b.use ReadSSHInfo, 5985
  end
end

.action_reloadObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-vcloud/action.rb', line 41

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end
      b2.use action_halt
      b2.use action_start
      b2.use DisconnectVCloud
    end
  end
end

.action_resumeObject


109
110
111
112
113
114
# File 'lib/vagrant-vcloud/action.rb', line 109

def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloud
    b.use Resume
  end
end

.action_sshObject


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/vagrant-vcloud/action.rb', line 203

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    # b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use Call, IsRunning do |env2, b3|
        unless env2[:result]
          b3.use MessageNotRunning
          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
        b3.use AnnounceSSHExec
      end
    end
  end
end

.action_ssh_runObject


225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/vagrant-vcloud/action.rb', line 225

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use SSHRun
    end
  end
end

.action_startObject

This action starts a VM, assuming it is already imported and exists. A precondition of this action is that the VM exists.


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vagrant-vcloud/action.rb', line 58

def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectVCloud
    b.use Call, IsRunning do |env, b2|
      # If the VM is running, then our work here is done, exit
      if env[:result]
        b2.use MessageAlreadyRunning
      else
        b2.use PowerOn
      end
    end
  end
end

.action_suspendObject


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vagrant-vcloud/action.rb', line 95

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloud
    b.use Call, IsRunning do |env, b2|
      # If the VM is stopped, can't suspend
      if !env[:result]
        b2.use MessageCannotSuspend
      else
        b2.use Suspend
      end
    end
  end
end

.action_upObject


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/vagrant-vcloud/action.rb', line 239

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      b2.use HandleBox unless env[:result]
    end
    b.use ConnectVCloud
    b.use InventoryCheck
    b.use Call, IsCreated do |env, b2|
      if env[:result]
        b2.use action_start
      else
        b2.use BuildVApp
        b2.use action_boot
      end
    end
    b.use DisconnectVCloud
  end
end