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/get_host_vm.rb,
lib/vagrant-skytap/action/is_suspended.rb,
lib/vagrant-skytap/action/set_hostname.rb,
lib/vagrant-skytap/action/check_created.rb,
lib/vagrant-skytap/action/check_running.rb,
lib/vagrant-skytap/action/forward_ports.rb,
lib/vagrant-skytap/action/initial_state.rb,
lib/vagrant-skytap/action/read_ssh_info.rb,
lib/vagrant-skytap/action/action_helpers.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/compose_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/clear_forwarded_ports.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,
lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb

Defined Under Namespace

Modules: ActionHelpers, MixinMachineIndex Classes: AddVmToEnvironment, CheckCreated, CheckRunning, ClearForwardedPorts, ComposeEnvironment, CreateEnvironment, DeleteEnvironment, DeleteVm, ExistenceCheck, FetchEnvironment, ForwardPorts, GetHostVM, InitialState, InitializeAPIClient, IsParallelized, IsRunning, IsStopped, IsSuspended, MessageAlreadyCreated, MessageAlreadyRunning, MessageEnvironmentUrl, MessageNotCreated, MessageResuming, MessageWillNotDestroy, PrepareForwardedPortCollisionParams, 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.



238
239
240
241
242
243
244
245
# File 'lib/vagrant-skytap/action.rb', line 238

def self.action_create
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate
    b.use action_fetch_environment
    b.use ComposeEnvironment
  end
end

.action_destroyObject

This action is called to terminate the remote machine.



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
112
113
114
115
116
# File 'lib/vagrant-skytap/action.rb', line 83

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use action_fetch_environment
    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]
          b2.use ClearForwardedPorts
          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_fetch_environmentObject



314
315
316
317
318
319
# File 'lib/vagrant-skytap/action.rb', line 314

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

.action_forward_portsObject



321
322
323
324
325
326
327
328
329
# File 'lib/vagrant-skytap/action.rb', line 321

def self.action_forward_ports
  Vagrant::Action::Builder.new.tap do |b|
    b.use ClearForwardedPorts
    b.use EnvSet, port_collision_repair: true
    b.use PrepareForwardedPortCollisionParams
    b.use HandleForwardedPortCollisions
    b.use ForwardPorts
  end
end

.action_haltObject

This action is called to halt the remote machine.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vagrant-skytap/action.rb', line 32

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use action_fetch_environment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use ClearForwardedPorts
        # May not halt suspended machines without --force flag
        b1.use Call, IsSuspended do |env2, b2|
          if env2[:result]
            b2.use Call, IsEnvSet, :force_halt do |env3, b3|
              if env3[:result]
                b3.use StopVm
              else
                b3.use Message, I18n.t("vagrant_skytap.commands.halt.not_allowed_if_suspended")
              end
            end
          else
            b2.use StopVm
          end
        end
      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.



193
194
195
196
197
198
199
200
201
202
# File 'lib/vagrant-skytap/action.rb', line 193

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



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
# File 'lib/vagrant-skytap/action.rb', line 119

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



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

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



164
165
166
167
168
169
# File 'lib/vagrant-skytap/action.rb', line 164

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

.action_reloadObject



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/vagrant-skytap/action.rb', line 294

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



204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/vagrant-skytap/action.rb', line 204

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

.action_run_vmObject



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/vagrant-skytap/action.rb', line 261

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

    # 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
    b.use action_forward_ports
  end
end

.action_sshObject

This action is called to SSH into the machine.



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

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use CheckCreated
    b.use CheckRunning
    b.use SSHExec
  end
end

.action_ssh_runObject



180
181
182
183
184
185
186
# File 'lib/vagrant-skytap/action.rb', line 180

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use CheckCreated
    b.use CheckRunning
    b.use SSHRun
  end
end

.action_suspendObject

This action is called to suspend the remote machine.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vagrant-skytap/action.rb', line 61

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use action_fetch_environment
    b.use Call, ExistenceCheck do |env1, b1|
      case result = env1[:result]
      when :missing_environment, :missing_vm, :no_vms
        b1.use MessageNotCreated
      else
        b1.use Call, IsRunning do |env2, b2|
          if env2[:result]
            b2.use ClearForwardedPorts
            b2.use SuspendVm
          else
            b2.use Message, I18n.t("vagrant_skytap.commands.suspend.only_allowed_if_running")
          end
        end
      end
    end
  end
end

.action_upObject

This is the action that the default “vagrant up” invokes. Since we don’t call action_up, this will only be called if the user attempts to install the Skytap provider using the –install-provider flag.



222
223
224
225
226
227
228
229
# File 'lib/vagrant-skytap/action.rb', line 222

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use Message, "You are seeing this message because the Skytap "\
      "provider currently does not fully support the --install-provider "\
      "flag. The provider has been installed successfully. Please run " \
      "'vagrant up' again to continue."
  end
end

.action_update_hardwareObject



247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/vagrant-skytap/action.rb', line 247

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