Module: PEBuild::Util::MachineComms

Included in:
Provisioner::PEAgent
Defined in:
lib/pe_build/util/machine_comms.rb

Overview

Utilities related to Vagrant Machine communications

This module provides general-purpose utility functions for communicating with Vagrant machines.

Since:

  • 0.13.0

Defined Under Namespace

Classes: MachineNotReachable

Class Method Summary collapse

Class Method Details

.ensure_reachable(machine) ⇒ void

This method returns an undefined value.

Raise an error if Vagrant commands cannot be executed on a machine

This function raises an error if a given vagrant machine is not ready for communication.

Parameters:

  • machine (Vagrant::Machine)

    A Vagrant machine.

Raises:

Since:

  • 0.13.0



44
45
46
# File 'lib/pe_build/util/machine_comms.rb', line 44

def ensure_reachable(machine)
  raise MachineNotReachable, :vm_name => machine.name.to_s unless is_reachable?(machine)
end

.is_reachable?(machine) ⇒ true, false

Determine if commands can be executed on a Vagrant machine

Parameters:

  • machine (Vagrant::Machine)

    A Vagrant machine.

Returns:

  • (true)

    If the machine can accept communication.

  • (false)

    If the machine cannot accept communication.

Since:

  • 0.13.0



19
20
21
22
23
24
25
26
27
# File 'lib/pe_build/util/machine_comms.rb', line 19

def is_reachable?(machine)
  begin
    machine.communicate.ready?
  rescue Vagrant::Errors::VagrantError
    # WinRM will raise an error if the VM isn't running instead of
    # returning false (GH-6356).
    false
  end
end