forked from puppetlabs/puppetlabs-peadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert_supported_architecture.pp
106 lines (101 loc) · 3.25 KB
/
assert_supported_architecture.pp
1
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# @summary Assert that the architecture given is a supported one
function peadm::assert_supported_architecture (
TargetSpec $primary_host,
Variant[TargetSpec, Undef] $replica_host = undef,
Variant[TargetSpec, Undef] $primary_postgresql_host = undef,
Variant[TargetSpec, Undef] $replica_postgresql_host = undef,
Variant[TargetSpec, Undef] $compiler_hosts = undef,
Variant[TargetSpec, Undef] $legacy_compilers = undef,
) >> Hash {
# Normalize $legacy_compilers to an array
$legacy_compilers_array = $legacy_compilers ? {
undef => [],
String => [$legacy_compilers],
Array => $legacy_compilers,
default => fail("Unexpected type for \$legacy_compilers: ${legacy_compilers}"),
}
# Normalize $compiler_hosts to an array
$compiler_hosts_array = $compiler_hosts ? {
undef => [],
String => [$compiler_hosts],
Array => $compiler_hosts,
default => fail("Unexpected type for \$compiler_hosts: ${compiler_hosts}"),
}
$all_compilers = $legacy_compilers_array + $compiler_hosts_array
# Set $has_compilers to undef if $all_compilers is empty, otherwise set it to true
$has_compilers = empty($all_compilers) ? {
true => undef,
default => true,
}
$result = case [
!!($primary_host),
!!($replica_host),
!!($primary_postgresql_host),
!!($replica_postgresql_host),
] {
[true, false, false, false]: { # Standard or Large, no DR
({ 'disaster-recovery' => false, 'architecture' => $has_compilers ? {
undef => 'standard',
default => 'large',
} })
}
[true, true, false, false]: { # Standard or Large, DR
({ 'disaster-recovery' => true, 'architecture' => $has_compilers ? {
undef => 'standard',
default => 'large',
} })
}
[true, false, true, false]: { # Extra Large, no DR
({ 'disaster-recovery' => false, 'architecture' => 'extra-large' })
}
[true, true, true, true]: { # Extra Large, DR
({ 'disaster-recovery' => true, 'architecture' => 'extra-large' })
}
# lint:ignore:strict_indent
default: { # Invalid
out::message(inline_epp(@(HEREDOC)))
Invalid architecture! Received:
- primary
<% if $replica_host { -%>
- primary-replica
<% } -%>
<% if $primary_postgresql_host { -%>
- pdb-database
<% } -%>
<% if $replica_postgresql_host { -%>
- pdb-database-replica
<% } -%>
<% if $has_compilers { -%>
- compilers
<% } -%>
Supported architectures include:
Standard
- primary
Standard with DR
- primary
- primary-replica
Large
- primary
- compilers
Large with DR
- primary
- primary-replica
- compilers
Extra Large
- primary
- pdb-database
- compilers (optional)
Extra Large with DR
- primary
- primary-replica
- pdb-database
- pdb-database-replica
- compilers (optional)
| HEREDOC
fail('Invalid architecture!')
}
}
# lint:endignore
# Return value
return({ 'supported' => true } + $result)
}