Module: VagrantPlugins::Skytap::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-skytap/action.rb,
lib/vagrant-skytap/action/run_vm.rb,
lib/vagrant-skytap/action/stop_vm.rb,
lib/vagrant-skytap/action/delete_vm.rb,
lib/vagrant-skytap/action/set_up_vm.rb,
lib/vagrant-skytap/action/is_running.rb,
lib/vagrant-skytap/action/is_stopped.rb,
lib/vagrant-skytap/action/read_state.rb,
lib/vagrant-skytap/action/suspend_vm.rb,
lib/vagrant-skytap/action/is_suspended.rb,
lib/vagrant-skytap/action/set_hostname.rb,
lib/vagrant-skytap/action/initial_state.rb,
lib/vagrant-skytap/action/read_ssh_info.rb,
lib/vagrant-skytap/action/existence_check.rb,
lib/vagrant-skytap/action/is_parallelized.rb,
lib/vagrant-skytap/action/run_environment.rb,
lib/vagrant-skytap/action/timed_provision.rb,
lib/vagrant-skytap/action/update_hardware.rb,
lib/vagrant-skytap/action/message_resuming.rb,
lib/vagrant-skytap/action/stop_environment.rb,
lib/vagrant-skytap/action/store_extra_data.rb,
lib/vagrant-skytap/action/fetch_environment.rb,
lib/vagrant-skytap/action/create_environment.rb,
lib/vagrant-skytap/action/delete_environment.rb,
lib/vagrant-skytap/action/message_not_created.rb,
lib/vagrant-skytap/action/mixin_machine_index.rb,
lib/vagrant-skytap/action/suspend_environment.rb,
lib/vagrant-skytap/action/prepare_nfs_settings.rb,
lib/vagrant-skytap/action/add_vm_to_environment.rb,
lib/vagrant-skytap/action/initialize_api_client.rb,
lib/vagrant-skytap/action/prepare_nfs_valid_ids.rb,
lib/vagrant-skytap/action/wait_for_communicator.rb,
lib/vagrant-skytap/action/message_already_created.rb,
lib/vagrant-skytap/action/message_already_running.rb,
lib/vagrant-skytap/action/message_environment_url.rb,
lib/vagrant-skytap/action/message_will_not_destroy.rb

Defined Under Namespace

Modules: MixinMachineIndex Classes: AddVmToEnvironment, CreateEnvironment, DeleteEnvironment, DeleteVm, ExistenceCheck, FetchEnvironment, InitialState, InitializeAPIClient, IsParallelized, IsRunning, IsStopped, IsSuspended, MessageAlreadyCreated, MessageAlreadyRunning, MessageEnvironmentUrl, MessageNotCreated, MessageResuming, MessageWillNotDestroy, PrepareNFSSettings, PrepareNFSValidIds, ReadSSHInfo, ReadState, RunEnvironment, RunVm, SetHostname, SetUpVm, StopEnvironment, StopVm, StoreExtraData, SuspendEnvironment, SuspendVm, TimedProvision, UpdateHardware, WaitForCommunicator

Class Method Summary collapse

Class Method Details

.action_createObject

The Skytap provider has a modified “vagrant up” command which takes advantage of parallel runstate operations on Skytap environments. The create and update_hardware actions are separated from the run_vm action, so we can pass in the ids and initial states for all machines to be run, potentially with a single REST call.


209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/vagrant-skytap/action.rb', line 209

def self.action_create
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env, b1|
      case result = env[:result]
      when :missing_environment
        b1.use CreateEnvironment
        b1.use MessageEnvironmentUrl
      when :no_vms, :missing_vm
        b1.use AddVmToEnvironment
      else
        next
      end
      b1.use StoreExtraData
      b1.use SetUpVm
    end
  end
end

.action_destroyObject

This action is called to terminate the remote machine.


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vagrant-skytap/action.rb', line 44

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env, b1|
      case existence_state = env[:result]
      when :missing_environment, :no_vms
        b1.use MessageNotCreated
        b1.use DeleteEnvironment
        next
      when :missing_vm
        b1.use MessageNotCreated
        b1.use DeleteVm
        next
      end
      b1.use Call, DestroyConfirm do |env2, b2|
        if env2[:result]
          case existence_state
          when :one_of_many_vms
            b2.use DeleteVm
          else
            b2.use DeleteEnvironment
          end
          b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
        else
          b2.use MessageWillNotDestroy
        end
      end
    end
    b.use PrepareNFSValidIds
    b.use SyncedFolderCleanup
  end
end

.action_haltObject

This action is called to halt the remote machine.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant-skytap/action.rb', line 10

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use StopVm
      end
    end
  end
end

.action_prepare_bootObject

Note: Provision and SyncedFolders perform actions before and after calling the next middleware in the sequence. Both require that the machine be booted before those calls return. This requirement can be satisfied by putting the WaitForCommunicator middleware later in the sequence.


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

def self.action_prepare_boot
  Vagrant::Action::Builder.new.tap do |b|
    b.use PrepareNFSSettings
    b.use PrepareNFSValidIds
    b.use Provision
    b.use SyncedFolderCleanup
    b.use SyncedFolders
  end
end

.action_provisionObject

This action is called when `vagrant provision` is called.


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vagrant-skytap/action.rb', line 80

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env, b1|
      case result = env[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
        next
      end
      b1.use Call, IsStopped do |env2, b2|
        b2.use Call, IsRunning do |env3, b3|
          unless env3[:result]
            b3.use RunVm
            b3.use WaitForCommunicator
          end
        end

        was_stopped = env2[:result]
        if was_stopped
          b2.use PrepareNFSSettings
          b2.use PrepareNFSValidIds
        end
        b2.use Provision
        if was_stopped
          b2.use SyncedFolders
        end
      end
    end
  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.


116
117
118
119
120
121
122
123
# File 'lib/vagrant-skytap/action.rb', line 116

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


128
129
130
131
132
133
134
135
136
# File 'lib/vagrant-skytap/action.rb', line 128

def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    #TODO:NLA Can this whole action be removed?
    b.use ReadState
  end
end

.action_reloadObject


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/vagrant-skytap/action.rb', line 278

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env, b1|
      case env[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use action_halt
        b1.use action_update_hardware
        # We don't need to store the initial states
        # before calling run_vm, because the default
        # behavior is to treat the VMs as powered off.
        b1.use action_run_vm
      end
    end
  end
end

.action_resumeObject


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/vagrant-skytap/action.rb', line 186

def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    Vagrant::Action::Builder.new.tap do |b|
      b.use InitializeAPIClient
      b.use FetchEnvironment
      b.use Call, IsSuspended do |env, b1|
        if env[:result]
          b1.use MessageResuming
          b1.use RunVm
          b1.use WaitForCommunicator
        end
      end
    end
  end
end

.action_run_vmObject


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/vagrant-skytap/action.rb', line 244

def self.action_run_vm
  Vagrant::Action::Builder.new.tap do |b|
    b.use InitializeAPIClient
    b.use FetchEnvironment

    # The "up" command stores the pre-run states to
    # avoid a race condition when running multiple
    # VMs in parallel -- we need to know which VMs
    # are actually being powered on and need to
    # have folders synced and provisioning run.
    b.use Call, InitialState do |env, b1|
      case env[:result]
      when :running
        b1.use MessageAlreadyRunning
        next
      when :suspended
        b1.use MessageResuming
      else
        b1.use action_prepare_boot
      end
      b1.use Call, IsParallelized do |env2, b2|
        if env2[:result]
          # Note: RunEnvironment is a no-op after
          # the first invocation.
          b2.use RunEnvironment
        else
          b2.use RunVm
        end
      end
    end
    b.use WaitForCommunicator
  end
end

.action_sshObject

This action is called to SSH into the machine.


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/vagrant-skytap/action.rb', line 139

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use SSHExec
      end
    end
  end
end

.action_ssh_runObject


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

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use SSHRun
      end
    end
  end
end

.action_suspendObject

This action is called to suspend the remote machine.


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

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use SuspendVm
      end
    end
  end
end

.action_update_hardwareObject


231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/vagrant-skytap/action.rb', line 231

def self.action_update_hardware
  Vagrant::Action::Builder.new.tap do |b|
    b.use InitializeAPIClient
    b.use FetchEnvironment
    b.use Call, IsStopped do |env, b1|
      if env[:result]
        b1.use UpdateHardware
        b1.use SetHostname
      end
    end
  end
end