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/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, 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
# 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
    end
    b.use Provision
    b.use SyncFolders
  end
end

.action_destroyObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vagrant-vcloud/action.rb', line 93

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_halt 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]
              end
              b4.use PowerOffVApp
              b4.use DestroyVApp
            else
              b4.use DestroyVM
            end
          end
        end
      else
        b2.use MessageWillNotDestroy
      end
    end
  end
end

.action_haltObject



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

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 PowerOff
  end
end

.action_provisionObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/vagrant-vcloud/action.rb', line 130

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



161
162
163
164
165
166
# File 'lib/vagrant-vcloud/action.rb', line 161

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.



147
148
149
150
151
152
# File 'lib/vagrant-vcloud/action.rb', line 147

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.



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

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



154
155
156
157
158
159
# File 'lib/vagrant-vcloud/action.rb', line 154

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

.action_reloadObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-vcloud/action.rb', line 29

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



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

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

.action_sshObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/vagrant-vcloud/action.rb', line 179

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



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/vagrant-vcloud/action.rb', line 201

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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-vcloud/action.rb', line 46

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



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

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



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/vagrant-vcloud/action.rb', line 215

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