Sha256: 060eaaff40ac582b3124216892d92ad7fb786cf4f7d1724d1c4c45e619402b10

Contents?: true

Size: 1.72 KB

Versions: 31

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require 'bolt/util'

# Wait until all targets accept connections.
#
# **NOTE:** Not available in apply block
Puppet::Functions.create_function(:wait_until_available) do
  # Wait until targets are available.
  # @param targets A pattern identifying zero or more targets. See {get_targets} for accepted patterns.
  # @param options Additional options: 'description', 'wait_time', 'retry_interval', '_catch_errors'.
  # @return A list of results, one entry per target. Successful results have no value.
  # @example Wait for targets
  #   wait_until_available($targets, wait_time => 300)
  dispatch :wait_until_available do
    param 'Boltlib::TargetSpec', :targets
    optional_param 'Hash[String[1], Any]', :options
    return_type 'ResultSet'
  end

  def wait_until_available(targets, options = nil)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING,
                              action: 'wait_until_available')
    end

    options ||= {}
    executor = Puppet.lookup(:bolt_executor)
    inventory = Puppet.lookup(:bolt_inventory)

    executor.report_function_call(self.class.name)

    # Ensure that given targets are all Target instances
    targets = inventory.get_targets(targets)

    if targets.empty?
      call_function('debug', "Simulating wait_until_available - no targets given")
      r = Bolt::ResultSet.new([])
    else
      opts = Bolt::Util.symbolize_top_level_keys(options.reject { |k| k == '_catch_errors' })
      r = executor.wait_until_available(targets, **opts)
    end

    if !r.ok && !options['_catch_errors']
      raise Bolt::RunFailure.new(r, 'wait_until_available')
    end
    r
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
bolt-1.49.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.48.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.47.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.45.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.44.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.43.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.42.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.41.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.40.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.39.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.38.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.37.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.36.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.35.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.34.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.33.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.32.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.31.1 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.31.0 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb
bolt-1.30.1 bolt-modules/boltlib/lib/puppet/functions/wait_until_available.rb