Module: VagrantPlugins::VCloudAir::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-vcloudair/action.rb,
lib/vagrant-vcloudair/action/resume.rb,
lib/vagrant-vcloudair/action/suspend.rb,
lib/vagrant-vcloudair/action/power_on.rb,
lib/vagrant-vcloudair/action/is_paused.rb,
lib/vagrant-vcloudair/action/power_off.rb,
lib/vagrant-vcloudair/action/build_vapp.rb,
lib/vagrant-vcloudair/action/destroy_vm.rb,
lib/vagrant-vcloudair/action/is_bridged.rb,
lib/vagrant-vcloudair/action/is_created.rb,
lib/vagrant-vcloudair/action/is_last_vm.rb,
lib/vagrant-vcloudair/action/is_running.rb,
lib/vagrant-vcloudair/action/read_state.rb,
lib/vagrant-vcloudair/action/destroy_vapp.rb,
lib/vagrant-vcloudair/action/forward_ports.rb,
lib/vagrant-vcloudair/action/read_ssh_info.rb,
lib/vagrant-vcloudair/action/connect_vcloud.rb,
lib/vagrant-vcloudair/action/power_off_vapp.rb,
lib/vagrant-vcloudair/action/inventory_check.rb,
lib/vagrant-vcloudair/action/announce_ssh_exec.rb,
lib/vagrant-vcloudair/action/disconnect_vcloud.rb,
lib/vagrant-vcloudair/action/message_not_created.rb,
lib/vagrant-vcloudair/action/message_not_running.rb,
lib/vagrant-vcloudair/action/message_cannot_suspend.rb,
lib/vagrant-vcloudair/action/unmap_port_forwardings.rb,
lib/vagrant-vcloudair/action/message_already_running.rb,
lib/vagrant-vcloudair/action/message_will_not_destroy.rb,
lib/vagrant-vcloudair/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, ConnectVCloudAir, DestroyVApp, DestroyVM, DisconnectVCloudAir, ForwardPorts, HandleNATPortCollisions, InventoryCheck, IsBridged, IsCreated, IsLastVM, IsPaused, IsRunning, MessageAlreadyRunning, MessageCannotSuspend, MessageNotCreated, MessageNotRunning, MessageWillNotDestroy, PowerOff, PowerOffVApp, PowerOn, ReadSSHInfo, ReadState, Resume, Suspend, 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
# File 'lib/vagrant-vcloudair/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 WaitForCommunicator, [:starting, :running]
    b.use Provision
    b.use SyncedFolders
  end
end

.action_destroyObject



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
129
# File 'lib/vagrant-vcloudair/action.rb', line 94

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 ConnectVCloudAir
        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



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

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

.action_provisionObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/vagrant-vcloudair/action.rb', line 131

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 Call, IsRunning do |env2, b3|
        # If the VM is not running, must power on
        b3.use action_start unless env2[:result]
        b3.use Provision
        b3.use SyncedFolders
      end
    end
  end
end

.action_read_rdp_infoObject



166
167
168
169
170
171
# File 'lib/vagrant-vcloudair/action.rb', line 166

def self.action_read_rdp_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloudAir
    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.



152
153
154
155
156
157
# File 'lib/vagrant-vcloudair/action.rb', line 152

def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloudAir
    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.



176
177
178
179
180
181
182
# File 'lib/vagrant-vcloudair/action.rb', line 176

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

.action_read_winrm_infoObject



159
160
161
162
163
164
# File 'lib/vagrant-vcloudair/action.rb', line 159

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

.action_reloadObject



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

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

.action_resumeObject



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

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

.action_sshObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/vagrant-vcloudair/action.rb', line 184

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



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/vagrant-vcloudair/action.rb', line 206

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.



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

def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectVCloudAir
    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



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

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConnectVCloudAir
    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



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/vagrant-vcloudair/action.rb', line 220

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 ConnectVCloudAir
    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 DisconnectVCloudAir
  end
end