Module: VagrantPlugins::ProviderLibvirt::Action

Includes:
Vagrant::Action::Builtin, Vagrant::Action::General
Defined in:
lib/vagrant-libvirt/action.rb,
lib/vagrant-libvirt/action/is_created.rb,
lib/vagrant-libvirt/action/is_running.rb,
lib/vagrant-libvirt/action/halt_domain.rb,
lib/vagrant-libvirt/action/is_suspended.rb,
lib/vagrant-libvirt/action/start_domain.rb,
lib/vagrant-libvirt/action/wait_till_up.rb,
lib/vagrant-libvirt/action/create_domain.rb,
lib/vagrant-libvirt/action/forward_ports.rb,
lib/vagrant-libvirt/action/forward_ports.rb,
lib/vagrant-libvirt/action/resume_domain.rb,
lib/vagrant-libvirt/action/share_folders.rb,
lib/vagrant-libvirt/action/snapshot_save.rb,
lib/vagrant-libvirt/action/destroy_domain.rb,
lib/vagrant-libvirt/action/package_domain.rb,
lib/vagrant-libvirt/action/set_boot_order.rb,
lib/vagrant-libvirt/action/suspend_domain.rb,
lib/vagrant-libvirt/action/create_networks.rb,
lib/vagrant-libvirt/action/shutdown_domain.rb,
lib/vagrant-libvirt/action/shutdown_domain.rb,
lib/vagrant-libvirt/action/snapshot_delete.rb,
lib/vagrant-libvirt/action/destroy_networks.rb,
lib/vagrant-libvirt/action/handle_box_image.rb,
lib/vagrant-libvirt/action/snapshot_restore.rb,
lib/vagrant-libvirt/action/prune_nfs_exports.rb,
lib/vagrant-libvirt/action/cleanup_on_failure.rb,
lib/vagrant-libvirt/action/read_mac_addresses.rb,
lib/vagrant-libvirt/action/set_name_of_domain.rb,
lib/vagrant-libvirt/action/handle_storage_pool.rb,
lib/vagrant-libvirt/action/message_not_created.rb,
lib/vagrant-libvirt/action/message_not_running.rb,
lib/vagrant-libvirt/action/remove_stale_volume.rb,
lib/vagrant-libvirt/action/clean_machine_folder.rb,
lib/vagrant-libvirt/action/create_domain_volume.rb,
lib/vagrant-libvirt/action/prepare_nfs_settings.rb,
lib/vagrant-libvirt/action/remove_libvirt_image.rb,
lib/vagrant-libvirt/action/message_not_suspended.rb,
lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb,
lib/vagrant-libvirt/action/resolve_disk_settings.rb,
lib/vagrant-libvirt/action/message_already_created.rb,
lib/vagrant-libvirt/action/message_will_not_destroy.rb,
lib/vagrant-libvirt/action/create_network_interfaces.rb

Defined Under Namespace

Classes: CleanMachineFolder, CleanupOnFailure, ClearForwardedPorts, CreateDomain, CreateDomainVolume, CreateNetworkInterfaces, CreateNetworks, DestroyDomain, DestroyNetworks, ForwardPorts, HaltDomain, HandleBoxImage, HandleStoragePool, IsCreated, IsRunning, IsSuspended, MessageAlreadyCreated, MessageNotCreated, MessageNotRunning, MessageNotSuspended, MessageWillNotDestroy, PackageDomain, PrepareNFSSettings, PrepareNFSValidIds, PruneNFSExports, ReadMacAddresses, RemoveLibvirtImage, RemoveStaleVolume, ResolveDiskSettings, ResumeDomain, SetBootOrder, SetNameOfDomain, SetupComplete, ShareFolders, ShutdownDomain, SnapshotDelete, SnapshotRestore, SnapshotSave, StartDomain, StartShutdownTimer, SuspendDomain, WaitTillUp

Class Method Summary collapse

Class Method Details

.action_destroyObject

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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/vagrant-libvirt/action.rb', line 255

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        # Try to remove stale volumes anyway
        b2.use SetNameOfDomain
        b2.use RemoveStaleVolume if env[:machine].config.vm.box
        b2.use CleanMachineFolder, quiet: true
        b2.use MessageNotCreated unless env[:result]

        next
      end

      b2.use Call, DestroyConfirm do |env2, b3|
        if env2[:result]
          b3.use ProvisionerCleanup, :before
          b3.use ClearForwardedPorts
          b3.use PruneNFSExports
          b3.use DestroyDomain
          b3.use DestroyNetworks
          b3.use CleanMachineFolder
        else
          b3.use MessageWillNotDestroy
        end
      end
    end
  end
end

.action_haltObject

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



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/vagrant-libvirt/action.rb', line 179

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ClearForwardedPorts
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use Call, IsSuspended do |env2, b3|
        b3.use CreateNetworks if env2[:result]
        b3.use ResumeDomain if env2[:result]
      end

      # only perform shutdown if VM is running
      b2.use Call, IsRunning do |env2, b3|
        next unless env2[:result]

        b3.use StartShutdownTimer
        b3.use Call, GracefulHalt, :shutoff, :running do |env3, b4|
          if !env3[:result]
            b4.use Call, ShutdownDomain, :shutoff, :running do |env4, b5|
              if !env4[:result]
                 b5.use HaltDomain
              end
            end
          end
        end

      end
    end
  end
end

.action_packageObject

not implemented and looks like not require



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/vagrant-libvirt/action.rb', line 235

def self.action_package
  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 PackageSetupFolders
      b2.use PackageSetupFiles
      b2.use action_halt
      b2.use Package
      b2.use PackageDomain
    end
  end
end

.action_provisionObject

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



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/vagrant-libvirt/action.rb', line 306

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|
        unless env2[:result]
          b3.use MessageNotRunning
          next
        end

        b3.use Provision
      end
    end
  end
end

.action_read_mac_addressesObject



377
378
379
380
381
382
# File 'lib/vagrant-libvirt/action.rb', line 377

def self.action_read_mac_addresses
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ReadMacAddresses
  end
end

.action_reloadObject

This is the action implements the reload command It uses the halt and start actions



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

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 Provision
      b2.use action_halt

      b2.use ResolveDiskSettings
      b2.use action_start
    end
  end
end

.action_resumeObject

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



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/vagrant-libvirt/action.rb', line 352

def self.action_resume
  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, IsSuspended do |env2, b3|
        unless env2[:result]
          b3.use MessageNotSuspended
          next
        end
        b3.use CreateNetworks
        b3.use ResumeDomain
        b3.use Provision
        require 'vagrant/action/builtin/wait_for_communicator'
        b3.use WaitForCommunicator, [:running]
        b3.use ForwardPorts
      end
    end
  end
end

.action_snapshot_deleteObject

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



405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/vagrant-libvirt/action.rb', line 405

def self.action_snapshot_delete
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        raise Vagrant::Errors::VMNotCreatedError
      end

      b2.use SnapshotDelete
    end
  end
end

.action_snapshot_restoreObject

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



419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/vagrant-libvirt/action.rb', line 419

def self.action_snapshot_restore
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        raise Vagrant::Errors::VMNotCreatedError
      end

      b2.use SnapshotRestore
    end
  end
end

.action_snapshot_saveObject

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



433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/vagrant-libvirt/action.rb', line 433

def self.action_snapshot_save
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        raise Vagrant::Errors::VMNotCreatedError
      end

      b2.use SnapshotSave
    end
  end
end

.action_sshObject

This action is called to SSH into the machine.



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/vagrant-libvirt/action.rb', line 286

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        raise Vagrant::Errors::VMNotCreatedError
      end

      b2.use Call, IsRunning do |env2, b3|
        unless env2[:result]
          raise Vagrant::Errors::VMNotRunningError
        end

        b3.use SSHExec
      end
    end
  end
end

.action_ssh_runObject

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



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/vagrant-libvirt/action.rb', line 385

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]
        raise Vagrant::Errors::VMNotCreatedError
      end

      b2.use Call, IsRunning do |env2, b3|
        unless env2[:result]
          raise Vagrant::Errors::VMNotRunningError
        end

        b3.use SSHRun
      end
    end
  end
end

.action_suspendObject

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



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/vagrant-libvirt/action.rb', line 329

def self.action_suspend
  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
        b3.use ClearForwardedPorts
        b3.use SuspendDomain
      end
    end
  end
end

.action_upObject

This action is called to bring the box up from nothing.



77
78
79
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
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/vagrant-libvirt/action.rb', line 77

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use BoxCheckOutdated
    b.use Call, IsCreated do |env, b2|
      b2.use CleanupOnFailure
      b2.use Provision

      # Create VM if not yet created.
      if !env[:result]
        b2.use SetNameOfDomain

        if !env[:machine].config.vm.box
          b2.use ResolveDiskSettings
          b2.use CreateDomain
          b2.use CreateNetworks
          b2.use CreateNetworkInterfaces

          b2.use action_start
        else
          b2.use HandleStoragePool
          require 'vagrant/action/builtin/handle_box'
          b2.use HandleBox
          b2.use HandleBoxImage
          b2.use CreateDomainVolume
          b2.use ResolveDiskSettings
          b2.use CreateDomain
          b2.use CreateNetworks
          b2.use CreateNetworkInterfaces

          b2.use action_start

          b2.use SetHostname
        end
      else
        # start VM if halted
        env[:halt_on_error] = true
        b2.use ResolveDiskSettings
        b2.use CreateNetworks
        b2.use action_start
      end

      # corresponding action to CleanupOnFailure
      b2.use SetupComplete
    end
  end
end

.remove_libvirt_imageObject

remove image from Libvirt storage pool



70
71
72
73
74
# File 'lib/vagrant-libvirt/action.rb', line 70

def self.remove_libvirt_image
  Vagrant::Action::Builder.new.tap do |b|
    b.use RemoveLibvirtImage
  end
end