Module: Bosh::Common

Defined in:
lib/common/common.rb,
lib/common/errors.rb,
lib/common/version.rb,
lib/common/deep_copy.rb,
lib/common/version/bosh_version.rb,
lib/common/version/version_list.rb,
lib/common/version/release_version.rb,
lib/common/version/stemcell_version.rb,
lib/common/version/release_version_list.rb,
lib/common/version/semi_semantic_version.rb,
lib/common/version/stemcell_version_list.rb

Overview

Module for common methods used throughout the BOSH code.

Defined Under Namespace

Modules: DeepCopy, Release, Version Classes: RetryCountExceeded

Constant Summary collapse

VERSION =
'1.3262.24.0'

Class Method Summary collapse

Class Method Details

.retryable(options = {}, &block) ⇒ Object

Retries execution of given block until block returns true

The block is called with two parameters: the number of tries and the most recent exception. If the block returns true retrying is stopped. Examples:

 Bosh::Common.retryable do |retries, exception|
   puts "try #{retries} failed with exception: #{exception}" if retries > 0
   pick_up_soap
 end

 # Wait for EC2 instance to be terminated
 Bosh::Common.retryable(on: AWS::EC2::Errors::RequestLimitExceeded) do |retries, exception|
   @ec2.instance['i-a3x5g5'].status == :terminated
 end

end

Bosh::Common.retryable(ensure: ensure_cb) do
  # process file
end

Parameters:

  • options (Hash) (defaults to: {})


118
119
120
# File 'lib/common/common.rb', line 118

def retryable(options = {}, &block)
  Bosh::Retryable.new(options).retryer(&block)
end

.symbolize_keys(hash) ⇒ Hash

Converts all keys of a [Hash] to symbols. Performs deep conversion.

Parameters:

  • hash (Hash)

    to convert

Returns:

  • (Hash)

    a copy of the original hash



14
15
16
17
18
19
# File 'lib/common/common.rb', line 14

def symbolize_keys(hash)
  hash.inject({}) do |h, (key, value)|
    h[key.to_sym] = value.is_a?(Hash) ? symbolize_keys(value) : value
    h
  end
end

.which(program, path) ⇒ String .which(programs, path) ⇒ String

Overloads:

  • .which(program, path) ⇒ String

    Looks for program in the executables search path (PATH). The file must be executable to be found.

    Parameters:

    • program (String)
    • path (String)

      search path

    Returns:

    • (String)

      full path of the executable, or nil if not found

  • .which(programs, path) ⇒ String

    Looks for one of the programs in the executables search path (PATH). The file must be executable to be found.

    Parameters:

    • programs (Array)
    • path (String)

      search path

    Returns:

    • (String)

      full path of the executable, or nil if not found



37
38
39
40
41
42
43
44
45
# File 'lib/common/common.rb', line 37

def which(programs, path=ENV["PATH"])
  path.split(File::PATH_SEPARATOR).each do |dir|
    Array(programs).each do |bin|
      exe = File.join(dir, bin)
      return exe if File.executable?(exe)
    end
  end
  nil
end