Puppet Function: wmflib::get_clusters

Defined in:
modules/wmflib/lib/puppet/functions/wmflib/get_clusters.rb
Function type:
Ruby 4.x API

Overview

wmflib::get_clusters(Optional[Wmflib::Selector] $selector)Any

SPDX-License-Identifier: Apache-2.0

Parameters:

  • selector (Optional[Wmflib::Selector])

Returns:

  • (Any)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'modules/wmflib/lib/puppet/functions/wmflib/get_clusters.rb', line 2

Puppet::Functions.create_function(:'wmflib::get_clusters') do
  dispatch :get_clusters do
    optional_param 'Wmflib::Selector', :selector
  end

  def get_clusters(selector = {})
    clusters = selector.fetch('cluster', call_function('lookup', 'wikimedia_clusters').keys)
    sites = selector.fetch('site', [])
    pql = <<~PQL
    resources[certname, parameters] {
        type = "Class" and title = "Cumin::Selector"
        order by parameters
    }
    PQL
    call_function('wmflib::puppetdb_query', pql).select do |res|
      clusters.include?(res['parameters']['cluster']) &&
        (sites.empty? || sites.include?(res['parameters']['site']))
    end.reduce({}) do |memo, res|  # rubocop:disable Style/MultilineBlockChain
      cluster = res['parameters']['cluster']
      site = res['parameters']['site']
      memo[cluster] ||= {}
      memo[cluster][site] ||= []
      memo[cluster][site] << res['certname']
      memo
    end
  end
end