Skip to content

Commit 703da68

Browse files
committed
Finished implementating HA setup
1 parent 39b2e77 commit 703da68

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

NetScaler/Public/Enable-NSHighAvailability.ps1

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Enable-NSHighAvailability {
2525
.EXAMPLE
2626
Enable-NSHighAvailability -PrimarySession $ns1 -SecondarySession Session $ns2
2727
28-
Enable high-availability between the netscaler instances corresponding to
28+
Enable high-availability between the netscaler instances corresponding to
2929
the already opened $ns1 and $ns2.
3030
3131
.PARAMETER PrimarySession
@@ -39,6 +39,14 @@ function Enable-NSHighAvailability {
3939
4040
Default value: 1
4141
42+
.PARAMETER Timeout
43+
Time to wait, in secondes, for the synchronization to complete.
44+
45+
Default value: 300
46+
47+
.PARAMETER Save
48+
If true, wait for the synchronization to finish and save configurations.
49+
4250
.PARAMETER Force
4351
Suppress confirmation when activating high-availability.
4452
#>
@@ -52,6 +60,10 @@ function Enable-NSHighAvailability {
5260

5361
[int]$PeerNodeId = 1,
5462

63+
[int]$Timeout = 300,
64+
65+
[switch]$Save,
66+
5567
[switch]$Force
5668
)
5769

@@ -61,10 +73,61 @@ function Enable-NSHighAvailability {
6173
}
6274

6375
process {
64-
if ($Force -or $PSCmdlet.ShouldProcess($item, 'Enable high-availability')) {
76+
if ($Force -or $PSCmdlet.ShouldProcess(
77+
"Enable high-availability of $($PrimarySession.Endpoint) and $($SecondarySession.Endpoint)")) {
6578
try {
66-
67-
79+
$primaryIp = $PrimarySession.Endpoint
80+
$secondaryIp = $SecondarySession.Endpoint
81+
82+
Write-Verbose "$primaryIp -> STAYPRIMARY..."
83+
_InvokeNSRestApi -Session $PrimarySession -Method PUT -Type hanode `
84+
-Payload @{ id = 0; hastatus = "STAYPRIMARY" }
85+
86+
Write-Verbose "$secondaryIp -> STAYSECONDARY..."
87+
_InvokeNSRestApi -Session $SecondarySession -Method PUT -Type hanode `
88+
-Payload @{ id = 0; hastatus = "STAYSECONDARY" }
89+
90+
Write-Verbose "$primaryIp -> set secondatory to $secondaryIp..."
91+
_InvokeNSRestApi -Session $PrimarySession -Method POST -Type hanode `
92+
-Payload @{ id = $PeerNodeId; ipaddress = $secondaryIp } -Action add
93+
94+
Write-Verbose "$secondaryIp -> set secondatory to $primaryIp..."
95+
_InvokeNSRestApi -Session $SecondarySession -Method POST -Type hanode `
96+
-Payload @{ id = $PeerNodeId; ipaddress = $primaryIp } -Action Add
97+
98+
Write-Verbose "$primaryIp -> ENABLED..."
99+
_InvokeNSRestApi -Session $PrimarySession -Method PUT -Type hanode `
100+
-Payload @{ id = 0; hastatus = "ENABLED" }
101+
102+
Write-Verbose "$secondaryIp -> ENABLED..."
103+
_InvokeNSRestApi -Session $SecondarySession -Method PUT -Type hanode `
104+
-Payload @{ id = 0; hastatus = "ENABLED" }
105+
106+
if ($Save) {
107+
$waitStart = Get-Date
108+
109+
while (((Get-Date) - $waitStart).TotalSeconds -lt $Timeout) {
110+
Write-Verbose "Waiting for synchronization to complete..."
111+
Start-Sleep -Seconds 5
112+
$HaNode = Get-NSHaNode -Session $PrimarySession -Id $PeerNodeId
113+
114+
if ($HaNode.hasync -match "IN PROGRESS|ENABLED") {
115+
Write-Verbose "Synchronizing..."
116+
continue
117+
} elseif ($HaNode.hasync -eq "SUCCESS") {
118+
Write-Verbose "Synchronization succesful. Saving configurations..."
119+
Save-NSConfig -Session $PrimarySession
120+
Save-NSConfig -Session $SecondarySession
121+
break
122+
} else {
123+
throw "Unexpected sync status '$($HaNode.hasync)'"
124+
}
125+
}
126+
127+
if ($HaNode.hasync -ne "SUCCESS") {
128+
throw "Timeout expired before the synchronization ended. Configurations will not be saved!"
129+
}
130+
}
68131
} catch {
69132
throw $_
70133
}

0 commit comments

Comments
 (0)