module VagrantPlugins::ProviderLibvirt::Action

Public Class Methods

action_destroy() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 253
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_halt() click to toggle source

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

# 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_package() click to toggle source

not implemented and looks like not require

# File lib/vagrant-libvirt/action.rb, line 233
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_provision() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 304
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_addresses() click to toggle source
# File lib/vagrant-libvirt/action.rb, line 373
def self.action_read_mac_addresses
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ReadMacAddresses
  end
end
action_reload() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 216
def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConfigValidate
      b2.use Provision
      b2.use action_halt
      b2.use action_start
    end
  end
end
action_resume() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 349
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]
      end
    end
  end
end
action_snapshot_delete() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 401
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_restore() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 415
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_save() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 429
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_ssh() click to toggle source

This action is called to SSH into the machine.

# File lib/vagrant-libvirt/action.rb, line 284
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_run() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 381
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_suspend() click to toggle source

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

# File lib/vagrant-libvirt/action.rb, line 327
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 SuspendDomain
      end
    end
  end
end
action_up() click to toggle source

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

# 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

          b2.use SetupComplete
        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
        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_image() click to toggle source

remove image from Libvirt storage pool

# 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

Private Class Methods

action_start() click to toggle source

Assuming VM is created, just start it. This action is not called directly by any subcommand. VM can be suspended, already running or in poweroff state.

# File lib/vagrant-libvirt/action.rb, line 129
                     def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsRunning do |env, b2|
      # If the VM is running, run the necessary provisioners
      if env[:result]
        b2.use action_provision
        next
      end

      b2.use Call, IsSuspended do |env2, b3|
        # if vm is suspended resume it then exit
        if env2[:result]
          b3.use ResumeDomain
          next
        end

        if !env[:machine].config.vm.box
          # With no box, we just care about network creation and starting it
          b3.use SetBootOrder
          b3.use StartDomain
        else
          # VM is not running or suspended.
          b3.use PrepareNFSValidIds
          b3.use SyncedFolderCleanup
          require 'vagrant/action/builtin/synced_folders'
          b3.use SyncedFolders
          b3.use PrepareNFSSettings
          b3.use ShareFolders

          b3.use SetBootOrder

          # Start it..
          b3.use StartDomain

          # Machine should gain IP address when coming up,
          # so wait for dhcp lease and store IP into machines data_dir.
          b3.use WaitTillUp
          require 'vagrant/action/builtin/wait_for_communicator'
          b3.use WaitForCommunicator, [:running]

          b3.use ForwardPorts
        end
      end
    end
  end
end