Sha256: 07973664ec805df91639826a0402f78e0f036eafdd3e867db901fdc655e57f6b

Contents?: true

Size: 1.59 KB

Versions: 39

Compression:

Stored size: 1.59 KB

Contents

require 'vagrant/errors'

module PEBuild
  module Util
    # Utilities related to Vagrant Machine communications
    #
    # This module provides general-purpose utility functions for communicating
    # with Vagrant machines.
    #
    # @since 0.13.0
    module MachineComms

      # Determine if commands can be executed on a Vagrant machine
      #
      # @param machine [Vagrant::Machine] A Vagrant machine.
      #
      # @return [true] If the machine can accept communication.
      # @return [false] If the machine cannot accept communication.
      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
      module_function :is_reachable?

      class MachineNotReachable < ::Vagrant::Errors::VagrantError
        error_key(:machine_not_reachable, 'pebuild.errors')
      end

      # 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.
      #
      # @param machine [Vagrant::Machine] A Vagrant machine.
      #
      # @return [void] If the machine can accept communication.
      # @raise [MachineNotReachable] If the machine cannot accept
      #   communication.
      def ensure_reachable(machine)
        raise MachineNotReachable, :vm_name => machine.name.to_s unless is_reachable?(machine)
      end
      module_function :ensure_reachable

    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
vagrant-pe_build-0.19.2 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.19.1 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.19.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.18.2 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.18.1 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.18.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.14 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.13 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.12 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.11 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.10 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.9 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.8 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.7 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.6 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.5 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.4 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.3 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.2 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.17.1 lib/pe_build/util/machine_comms.rb