Puppet Function: oci_config::wait_until_unavailable

Defined in:
lib/puppet/functions/oci_config/wait_until_unavailable.rb
Function type:
Ruby 4.x API

Overview

oci_config::wait_until_unavailable(Boltlib::TargetSpec $targets, Optional[Hash[String[1], Any]] $options)ResultSet

Wait until all targets no longer accept connections.

> Note: Not available in apply block

Examples:

Wait for targets

wait_until_unavailable($targets, wait_time => 300)

Parameters:

  • targets (Boltlib::TargetSpec)

    A pattern identifying zero or more targets. See get_targets for accepted patterns.

  • options (Optional[Hash[String[1], Any]])

    A hash of additional options.

Options Hash (options):

  • description (String)

    A description for logging. (default: ‘wait until no longer available’)

  • wait_time (Numeric)

    The time to wait. (default: 120)

  • retry_interval (Numeric)

    The interval to wait before retrying. (default: 1)

  • _catch_errors (Boolean)

    Whether to catch raised errors.

Returns:

  • (ResultSet)

    A list of results, one entry per target. Successful results have no value.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppet/functions/oci_config/wait_until_unavailable.rb', line 10

Puppet::Functions.create_function('oci_config::wait_until_unavailable') do
  # Wait until targets are available.
  # @param targets A pattern identifying zero or more targets. See {get_targets} for accepted patterns.
  # @param options A hash of additional options.
  # @option options [String] description A description for logging. (default: 'wait until no longer available')
  # @option options [Numeric] wait_time The time to wait. (default: 120)
  # @option options [Numeric] retry_interval The interval to wait before retrying. (default: 1)
  # @option options [Boolean] _catch_errors Whether to catch raised errors.
  # @return A list of results, one entry per target. Successful results have no value.
  # @example Wait for targets
  #   wait_until_unavailable($targets, wait_time => 300)
  dispatch :wait_until_unavailable do
    param 'Boltlib::TargetSpec', :targets
    optional_param 'Hash[String[1], Any]', :options
    return_type 'ResultSet'
  end
  def wait_until_unavailable(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_unavailable')
    end

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

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

    if targets.empty?
      call_function('debug', 'Simulating wait_until_unavailable - no targets given')
      Bolt::ResultSet.new([])
    else
      wait_time = options['wait_time'].to_i || 120
      description = options['description'] || 'wait until no longer available'
      retry_interval = options['retry_interval'].to_i || 10
      executor.log_action(description, targets) do
        executor.batch_execute(targets) do |transport, batch|
          executor.with_node_logging('Checking availability', batch) do
            begin
              executor.wait_until(wait_time, retry_interval) { !transport.batch_connected?(batch) }
              batch.map { |target| Bolt::Result.new(target, :action => 'wait_until_unavailable', :object => description) }
            rescue TimeoutError => e
              available, unavailable = batch.partition { |target| !transport.batch_connected?([target]) }
              (
                available.map { |target| Bolt::Result.new(target, :action => 'wait_until_unavailable', :object => description) } +
                unavailable.map { |target| Bolt::Result.from_exception(target, e, :action => 'wait_until_unavailable') }
              )
            end
          end
        end
      end
    end
  end
end