Puppet Function: ipa_topology_flat

Defined in:
lib/puppet/parser/functions/ipa_topology_flat.rb
Function type:
Ruby 3.x API

Overview

ipa_topology_flat()Any

Return an ipa N-N topology from a sorted list of hosts

Example:

$valid_peers = ipa_topology_flat($peers) notice(“valid peers is: $valid_peers”)

This function is used internally for building automatic topologies.

Returns:

  • (Any)


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
66
67
68
69
70
71
72
73
74
# File 'lib/puppet/parser/functions/ipa_topology_flat.rb', line 21

newfunction(:ipa_topology_flat, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
	Return an ipa N-N topology from a sorted list of hosts

	Example:

		$valid_peers = ipa_topology_flat($peers)
		notice("valid peers is: ${valid_peers}")

	This function is used internally for building automatic topologies.

	ENDHEREDOC

	Puppet::Parser::Functions.function('warning')	# load function
	# signature: replica, bricks -> bricks
	unless args.length == 1
		raise Puppet::ParseError, "ipa_topology_flat(): wrong number of arguments (#{args.length}; must be 1)"
	end
	if not(args[0].is_a?(Array))
		raise Puppet::ParseError, "ipa_topology_flat(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
	end

	peers = args[0]

	if peers.uniq.length != peers.length	# there are duplicates!
		raise Puppet::ParseError, "ipa_topology_flat(): duplicates were found in the first argument!"
	end

	# NOTE: need at least one
	if peers.length < 1
		function_warning(["ipa_topology_flat(): peer list is empty"])
		return {}
	end

	# if we only have one peer, and it's me, then topology is empty
	if peers.length == 1 and peers[0] == lookupvar('fqdn')
		return {}
	end

	result = {}

	peers.each do |x|

		same = peers.dup	# copy... to not destroy peers!
		if same.delete(x).nil?	# normally returns the value...
			# TODO: return programming error: delete failed
		end

		# connect to every peer except yourself
		result[x] = same

	end

	result	# return
end