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 148
def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use ClearForwardedPorts
      # b2.use PruneNFSExports
      b2.use DestroyDomain
      b2.use DestroyNetworks
    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 104
def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectLibvirt
    b.use ClearForwardedPorts
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

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

      b2.use Call, IsRunning do |env2, b3|
        next if !env2[:result]

        # VM is running, halt it.
        b3.use HaltDomain
      end
    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 190
def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use Call, IsRunning do |env2, b3|
        if !env2[:result]
          b3.use MessageNotRunning
          next
        end

        b3.use Provision
        # b3.use SyncFolders
      end
    end
  end
end
action_read_ssh_info() click to toggle source

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.

# File lib/vagrant-libvirt/action.rb, line 272
def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectLibvirt
    b.use ReadSSHInfo
  end
end
action_read_state() click to toggle source

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.

# File lib/vagrant-libvirt/action.rb, line 261
def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectLibvirt
    b.use ReadState
  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 131
def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConfigValidate
      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 238
def self.action_resume
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use Call, IsSuspended do |env2, b3|
        if !env2[:result]
          b3.use MessageNotSuspended
          next
        end
        b3.use ResumeDomain
      end
    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 167
def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use Call, IsRunning do |env2, b3|
        if !env2[:result]
          b3.use MessageNotRunning
          next
        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 281
def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use Call, IsRunning do |env2, b3|
        if !env2[:result]
          b3.use MessageNotRunning
          next
        end

        b3.use SSHRun
      end
    end

  end
end
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 60
def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectLibvirt
    b.use Call, IsRunning do |env, b2|
      # If the VM is running, then our work here is done, exit
      next if env[:result]

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

        # VM is not running or suspended.

        # Ensure networks are created and active
        b3.use CreateNetworks

        b3.use PrepareNFSValidIds
        b3.use SyncedFolderCleanup
        b3.use SyncedFolders


        # Start it..
        b3.use StartDomain

        # Machine should gain IP address when comming up,
        # so wait for dhcp lease and store IP into machines data_dir.
        b3.use WaitTillUp


        b3.use ForwardPorts
        b3.use PrepareNFSSettings
        b3.use ShareFolders

      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 215
def self.action_suspend
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectLibvirt
      b2.use Call, IsRunning do |env2, b3|
        if !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 12
def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectLibvirt
    b.use Call, IsCreated do |env, b2|
      # Create VM if not yet created.
      if !env[:result]
        b2.use SetNameOfDomain
        b2.use HandleStoragePool
        b2.use HandleBox
        b2.use HandleBoxImage
        b2.use CreateDomainVolume
        b2.use CreateDomain

        b2.use Provision
        b2.use CreateNetworks
        b2.use CreateNetworkInterfaces


        b2.use PrepareNFSValidIds
        b2.use SyncedFolderCleanup
        b2.use SyncedFolders

        b2.use StartDomain
        b2.use WaitTillUp

        b2.use StartDomain
        b2.use WaitTillUp

        


        b2.use ForwardPorts

        b2.use PrepareNFSSettings
        b2.use ShareFolders
        b2.use SetHostname
        # b2.use SyncFolders
      else
        b2.use action_start
      end
    end
  end
end