Module: VagrantPlugins::Parallels::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-parallels/action.rb,
lib/vagrant-parallels/action/boot.rb,
lib/vagrant-parallels/action/export.rb,
lib/vagrant-parallels/action/import.rb,
lib/vagrant-parallels/action/resume.rb,
lib/vagrant-parallels/action/destroy.rb,
lib/vagrant-parallels/action/network.rb,
lib/vagrant-parallels/action/package.rb,
lib/vagrant-parallels/action/suspend.rb,
lib/vagrant-parallels/action/set_name.rb,
lib/vagrant-parallels/action/customize.rb,
lib/vagrant-parallels/action/forced_halt.rb,
lib/vagrant-parallels/action/box_register.rb,
lib/vagrant-parallels/action/forward_ports.rb,
lib/vagrant-parallels/action/sane_defaults.rb,
lib/vagrant-parallels/action/snapshot_save.rb,
lib/vagrant-parallels/action/box_unregister.rb,
lib/vagrant-parallels/action/snapshot_delete.rb,
lib/vagrant-parallels/action/snapshot_restore.rb,
lib/vagrant-parallels/action/handle_guest_tools.rb,
lib/vagrant-parallels/action/package_vagrantfile.rb,
lib/vagrant-parallels/action/setup_package_files.rb,
lib/vagrant-parallels/action/clear_shared_folders.rb,
lib/vagrant-parallels/action/package_config_files.rb,
lib/vagrant-parallels/action/prepare_nfs_settings.rb,
lib/vagrant-parallels/action/clear_forwarded_ports.rb,
lib/vagrant-parallels/action/prepare_nfs_valid_ids.rb,
lib/vagrant-parallels/action/check_shared_interface.rb,
lib/vagrant-parallels/action/prepare_clone_snapshot.rb,
lib/vagrant-parallels/action/clear_network_interfaces.rb,
lib/vagrant-parallels/action/destroy_unused_network_interfaces.rb,
lib/vagrant-parallels/action/prepare_forwarded_port_collision_params.rb

Defined Under Namespace

Classes: Boot, BoxRegister, BoxUnregister, CheckSharedInterface, ClearForwardedPorts, ClearNetworkInterfaces, ClearSharedFolders, Customize, Destroy, DestroyUnusedNetworkInterfaces, Export, ForcedHalt, ForwardPorts, HandleGuestTools, Import, Network, Package, PackageConfigFiles, PackageVagrantfile, PrepareCloneSnapshot, PrepareForwardedPortCollisionParams, PrepareNFSSettings, PrepareNFSValidIds, Resume, SaneDefaults, SetName, SetupPackageFiles, SnapshotDelete, SnapshotRestore, SnapshotSave, Suspend

Class Method Summary collapse

Class Method Details

.action_bootObject

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



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

def self.action_boot
  Vagrant::Action::Builder.new.tap do |b|
    b.use CheckSharedInterface
    b.use SetName
    b.use ClearForwardedPorts
    b.use Provision
    b.use PrepareForwardedPortCollisionParams
    b.use HandleForwardedPortCollisions
    b.use PrepareNFSValidIds
    b.use SyncedFolderCleanup
    b.use SyncedFolders
    b.use PrepareNFSSettings
    b.use Network
    b.use ClearNetworkInterfaces
    b.use ForwardPorts
    b.use SetHostname
    b.use Customize, 'pre-boot'
    b.use Boot
    b.use Customize, 'post-boot'
    b.use WaitForCommunicator, [:starting, :running]
    b.use Customize, 'post-comm'
    b.use HandleGuestTools
  end
end

.action_destroyObject

This is the action that is primarily responsible for completely freeing the resources of the underlying virtual machine.



39
40
41
42
43
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
# File 'lib/vagrant-parallels/action.rb', line 39

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use Call, DestroyConfirm do |env2, b2|
        if !env2[:result]
          b2.use Message, I18n.t('vagrant.commands.destroy.will_not_destroy',
                                 :name => env2[:machine].name)
          next
        end

        # Do not resume && halt the suspended VM, just delete it
        b2.use Call, IsState, :suspended do |env3, b3|
          if !env3[:result]
            b3.use EnvSet, :force_halt => true
            b3.use action_halt
          end
        end

        b2.use Destroy
        b2.use DestroyUnusedNetworkInterfaces
        b2.use ProvisionerCleanup
        b2.use PrepareNFSValidIds
        b2.use SyncedFolderCleanup
      end
    end
  end
end

.action_haltObject

This is the action that is primarily responsible for halting the virtual machine, gracefully or by force.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vagrant-parallels/action.rb', line 75

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use CheckSharedInterface
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      # Resume/Unpause the VM if needed.
      b1.use Resume

      b1.use Call, GracefulHalt, :stopped, :running do |env2, b2|
        if !env2[:result]
          b2.use ForcedHalt
        end
      end

      b1.use ClearForwardedPorts
    end
  end
end

.action_packageObject

This action packages the virtual machine into a single box file.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vagrant-parallels/action.rb', line 100

def self.action_package
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use SetupPackageFiles
      b1.use action_halt
      b1.use PrepareNFSValidIds
      b1.use SyncedFolderCleanup
      b1.use Package
      b1.use Export
      b1.use PackageConfigFiles
      b1.use PackageVagrantfile
    end
  end
end

.action_provisionObject

This action just runs the provisioners on the machine.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/vagrant-parallels/action.rb', line 122

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use CheckSharedInterface
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use Call, IsState, :running do |env2, b2|
        if !env2[:result]
          b2.use Message, I18n.t('vagrant.commands.common.vm_not_running')
          next
        end

        b2.use Provision
      end
    end
  end
end

.action_reloadObject

This action is responsible for reloading the machine, which brings it down, sucks in new configuration, and brings the machine back up with the new configuration.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vagrant-parallels/action.rb', line 147

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use action_halt
      b1.use action_start
    end
  end
end

.action_resumeObject

This is the action that is primarily responsible for resuming suspended machines.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/vagrant-parallels/action.rb', line 164

def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use CheckSharedInterface
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use PrepareForwardedPortCollisionParams
      b1.use HandleForwardedPortCollisions
      b1.use ForwardPorts
      b1.use Resume
      b1.use Provision
      b1.use WaitForCommunicator, [:resuming, :running]
    end
  end
end

.action_simple_rebootObject

This action simply reboots the VM. It is executed right after Parallels Tools installation or upgrade.



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/vagrant-parallels/action.rb', line 357

def self.action_simple_reboot
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, GracefulHalt, :stopped, :running do |env2, b2|
      if !env2[:result]
        b2.use ForcedHalt
      end
    end

    b.use Customize, 'pre-boot'
    b.use Boot
    b.use Customize, 'post-boot'
    b.use WaitForCommunicator, [:starting, :running]
    b.use Customize, 'post-comm'
  end
end

.action_snapshot_deleteObject



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/vagrant-parallels/action.rb', line 184

def self.action_snapshot_delete
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
      else
        b1.use SnapshotDelete
      end
    end
  end
end

.action_snapshot_restoreObject

This is the action that is primarily responsible for saving a snapshot



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

def self.action_snapshot_restore
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use SnapshotRestore
      b1.use Call, IsEnvSet, :snapshot_delete do |env2, b2|
        if env2[:result]
          b2.use action_snapshot_delete
        end
      end
    end
  end
end

.action_snapshot_saveObject

This is the action that is primarily responsible for saving a snapshot



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/vagrant-parallels/action.rb', line 216

def self.action_snapshot_save
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
      else
        b1.use SnapshotSave
      end
    end
  end
end

.action_sshObject

This is the action that will exec into an SSH shell.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/vagrant-parallels/action.rb', line 229

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use CheckSharedInterface
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use Call, IsState, :running do |env2, b2|
        if !env2[:result]
          raise Vagrant::Errors::VMNotRunningError
        end

        b2.use SSHExec
      end
    end
  end
end

.action_ssh_runObject

This is the action that will run a single SSH command.



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/vagrant-parallels/action.rb', line 251

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use CheckSharedInterface
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use Call, IsState, :running do |env2, b2|
        if !env2[:result]
          raise Vagrant::Errors::VMNotRunningError
        end

        b2.use SSHRun
      end
    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.



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/vagrant-parallels/action.rb', line 274

def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use BoxCheckOutdated
    b.use Call, IsState, :running do |env1, b1|
      # If the VM is running, run the necessary provisioners
      if env1[:result]
        b1.use action_provision
        next
      end

      b1.use Call, IsState, :suspended do |env2, b2|
        if env2[:result]
          # The VM is suspended, go to resume
          b2.use action_resume
          next
        end

        b2.use Call, IsState, :paused do |env3, b3|
          if env3[:result]
            # The VM is paused, just run the Resume action to unpause it
            b3.use Resume
            next
          end

          # The VM is not suspended or paused, so we must have to
          # boot it up like normal. Boot!
          b3.use action_boot
        end
      end
    end
  end
end

.action_suspendObject

This is the action that is primarily responsible for suspending the virtual machine.



309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/vagrant-parallels/action.rb', line 309

def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use ClearForwardedPorts
      b1.use Suspend
    end
  end
end

.action_sync_foldersObject

This is the action that is called to sync folders to a running machine without a reboot. It is used by the docker provider to link synced folders on the host machine as volumes into the docker containers.



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/vagrant-parallels/action.rb', line 376

def self.action_sync_folders
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use Message, I18n.t('vagrant.commands.common.vm_not_created')
        next
      end

      b1.use Call, IsState, :running do |env2, b2|
        if !env2[:result]
          b2.use Message, I18n.t('vagrant.commands.common.vm_not_running')
          next
        end
        b2.use PrepareNFSValidIds
        b2.use SyncedFolders
        b2.use PrepareNFSSettings
      end
    end
  end
end

.action_upObject

This action brings the machine up from nothing, including importing the box, configuring metadata, and booting.



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/vagrant-parallels/action.rb', line 326

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    # Handle box_url downloading early so that if the Vagrantfile
    # references any files in the box or something it all just
    # works fine.
    b.use Call, IsState, :not_created do |env1, b1|
      if env1[:result]
        b1.use HandleBox
      end
    end

    b.use ConfigValidate
    b.use Call, IsState, :not_created do |env1, b1|
      # If the VM is NOT created yet, then do the setup steps
      if env1[:result]
        b1.use Customize, 'pre-import'
        b1.use BoxRegister
        b1.use PrepareClone
        b1.use PrepareCloneSnapshot
        b1.use Import
        b1.use BoxUnregister
        b1.use SaneDefaults
        b1.use Customize, 'post-import'
      end
    end
    b.use action_start
  end
end