@@ -25,7 +25,7 @@ function Enable-NSHighAvailability {
25
25
. EXAMPLE
26
26
Enable-NSHighAvailability -PrimarySession $ns1 -SecondarySession Session $ns2
27
27
28
- Enable high-availability between the netscaler instances corresponding to
28
+ Enable high-availability between the netscaler instances corresponding to
29
29
the already opened $ns1 and $ns2.
30
30
31
31
. PARAMETER PrimarySession
@@ -39,6 +39,14 @@ function Enable-NSHighAvailability {
39
39
40
40
Default value: 1
41
41
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
+
42
50
. PARAMETER Force
43
51
Suppress confirmation when activating high-availability.
44
52
#>
@@ -52,6 +60,10 @@ function Enable-NSHighAvailability {
52
60
53
61
[int ]$PeerNodeId = 1 ,
54
62
63
+ [int ]$Timeout = 300 ,
64
+
65
+ [switch ]$Save ,
66
+
55
67
[switch ]$Force
56
68
)
57
69
@@ -61,10 +73,61 @@ function Enable-NSHighAvailability {
61
73
}
62
74
63
75
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 ) " )) {
65
78
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
+ }
68
131
} catch {
69
132
throw $_
70
133
}
0 commit comments