-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-pod-variables.ps1
86 lines (85 loc) · 2.77 KB
/
generate-pod-variables.ps1
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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$csv,
[Parameter(Mandatory=$True,Position=1)]
[int]$count
)
$appJson = @"
[
{
tier: "app",
count: 3
},
{
tier: "db",
count: 3
},
{
tier: "haproxy-app",
count: 1
},
{
tier: "haproxy-db",
count: 1
},
{
tier: "load-sim",
count: 1
}
]
"@
$app = $appJson | ConvertFrom-JSON
$csvDict = @()
(1 .. $count) | % {
$pod = $_
$hostCount = 0
$app | % {
$tier = $_
(1 .. $tier.count) | % {
$hostCount++
$tierDict = new-object PSObject
if ($tier.count -gt 1)
{
$tierDict | add-member -MemberType NoteProperty -Name "HOSTNAME" -Value "$($tier.tier)-$_-pod-$pod"
}
else {
$tierDict | add-member -MemberType NoteProperty -Name "HOSTNAME" -Value "$($tier.tier)-pod-$pod"
}
$tierDict | add-member -MemberType NoteProperty -Name "IP" -Value "192.168.$(100 + $pod).$(200 + $hostCount)"
$tierDict | add-member -MemberType NoteProperty -Name "POD" -Value $pod
$tierDict | add-member -MemberType NoteProperty -Name "APP_TIER" -Value "$($tier.tier)"
$csvDict += $tierDict
}
}
$variableFile = "pod_$($pod)_variables.sh"
"#!/bin/sh" | Out-File -Encoding "ASCII" $variableFile
$target = $csvDict | where {$_.POD -eq $pod -and $_.APP_TIER -eq "haproxy-app" }
"HAPROXY_APP_IP=`"$($target.IP)`"" | Add-Content $variableFile
$target = $csvDict | where {$_.POD -eq $pod -and $_.APP_TIER -eq "haproxy-db" }
"HAPROXY_DB_IP=`"$($target.IP)`"" | Add-Content $variableFile
$target = $csvDict | where {$_.POD -eq $pod -and $_.APP_TIER -eq "app" }
$appNames = ""
$appIPs = ""
$target | % {
$appNames += "$($_.HOSTNAME),"
$appIPs += "$($_.IP),"
}
"APP_TIER_IPS=`"$($appIPs.Trim(','))`"" | Add-Content $variableFile
"APP_TIER_HOSTNAMES=`"$($appNames.Trim(','))`"" | Add-Content $variableFile
"APP_PORT=`"8081`"" | Add-Content $variableFile
$target = $csvDict | where {$_.POD -eq $pod -and $_.APP_TIER -eq "db" }
$dbNames = ""
$dbIPs = ""
$target | % {
$dbNames += "$($_.HOSTNAME),"
$dbIPs += "$($_.IP),"
}
"DB_TIER_IPS=`"$($dbIPs.Trim(','))`"" | Add-Content $variableFile
"DB_TIER_HOSTNAMES=`"$($dbNames.Trim(','))`"" | Add-Content $variableFile
"GALERA_DB_USER=`"siwapp`"" | Add-Content $variableFile
"GALERA_DB_USER_PWD=`"siwapp`"" | Add-Content $variableFile
"GALERA_DB_ROOT_PWD=`"siwapp`"" | Add-Content $variableFile
"GALERA_CLUSTER_NAME=`"siwapp`"" | Add-Content $variableFile
}
$csvDict | Export-Csv -NoTypeInformation $csv