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.17.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.16.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.6 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.5 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.4 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.3 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.1 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.15.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.14.2 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.14.1 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.14.0 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.7 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.6 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.5 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.4 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.3 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.2 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.1 lib/pe_build/util/machine_comms.rb
vagrant-pe_build-0.13.0 lib/pe_build/util/machine_comms.rb