-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLargeClusters.psm1
289 lines (225 loc) · 12.1 KB
/
LargeClusters.psm1
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<#==========================================================================
Script Name: LargeClusters.psm1
Created on: 12/19/2018
Created by: Jase McCarty
Github: http://www.github.com/jasemccarty
Twitter: @jasemccarty
Website: http://www.jasemccarty.com
===========================================================================
To use this module, Use Import-Module <path>/LargeClusters.psm1
#>
Function RebootVsanNode {
# Set our Parameters
[CmdletBinding()]Param(
[Parameter(Mandatory=$True)][string]$EsxHost,
[Parameter(Mandatory=$False)][ValidateSet("Full","EnsureAccessibility")][string]$DataMigration
)
Write-Host " "
Write-Host "Performing a reboot of $EsxHost" -ForegroundColor "DarkGreen"
# Get the Cluster Object
$Cluster = (Get-VMHost $EsxHost).Parent
# Get a list of the VM's on $EsxHost
$EsxHostGuests = Get-VM -Location $EsxHost
If ((Get-VM -Location $EsxHost).Count -gt 0) {
# Determine if the Cluster has DRS Enabled and is ste to Fully Automated
If (($Cluster.DrsEnabled -eq $True) -and ($Cluster.DrsAutomationLevel -eq 'FullyAutomated')) {
# Everything is good to go. Running VM's 'should' move off of $EsxHost automatically
Write-Host "------ "$EsxHostGuests.Count"VMs will be evacuated from $EsxHost when put into Maintenance Mode because DRS is enabled & set to FullyAutomated"
} else {
# DRS is either disabled or not fully automated, VM's will have to be moved off of the host
Write-Host "------ Evacuate any virtual machines from $EsxHost"
Write-Host " |--- "$EsxHostGuests.Count"VMs must be evacuated from $EsxHost " -ForegroundColor "DarkYellow"
Write-Host " because DRS is either not enabled or it is not set to FullyAutomated" -ForegroundColor "DarkYellow"
# Find hosts other than $EsxHost that are connected and available
$ConnectedHosts = $Cluster | Get-VMHost | Where-Object {$_.Name -ne $EsxHost -and $_.ConnectionState -eq "Connected"}
#Write-Host "Connected Hosts:" $ConnectedHosts
If ($EsxHostGuests.Count -gt 0) {
# Loop through the VM's in the list. If they are on $EsxHost, move them to a random alternate host
# DRS would be advantageous here for better uniform utilization across the cluster.
Foreach ($EsxHostGuest in $EsxHostGuests) {
# Get a random host to move the VM to
$AvailableHost = $ConnectedHosts | Get-Random
# Move the VM to the random host
Write-Host " |--- Moving $EsxHostGuest to $AvailableHost" -ForegroundColor "Green"
Move-VM $EsxHostGuest -Destination $AvailableHost -Confirm:$false -RunAsync:$true | Out-Null
}
Write-Host " |--- Waiting for all VM's to evacuate $EsxHost" -ForegroundColor "DarkYellow"
While ((Get-VM -Location $EsxHost).Count -gt 0) {
Sleep 1
Write-Host "." -NoNewline
}
Write-Host " "
Write-Host " |--- "$EsxHostGuests.Count" VMs have been moved off of $EsxHost" -ForegroundColor "Green"
}
}
} else {
Write-Host "|"
Write-Host "------ Evacuate the Host of VMs and put it in Maintenance Mode " -ForegroundColor "White"
Write-Host " |--- " -NoNewLine
Write-Host "No VM's on $EsxHost, proceeding to put the host in Maintenance Mode " -ForegroundColor "Green"
}
# Make sure there are no resyncs going on in the environment
$VsanResyncs = Get-VsanResyncingComponent -Cluster $Cluster
If ($VsanResyncs) {
Write-Host " |--- " -NoNewLine
Write-Host "Waiting on vSAN Resyncs to complete" -ForegroundColor "DarkYellow"
While ((Get-VsanResyncingComponent -Cluster $Cluster)) {
Write-Host "." -ForegroundColor "DarkYellow" -NoNewline
}
Write-Host ""
} else {
Write-Host " |--- No vSAN Resyncs being performed" -ForegroundColor "Green"
}
# Put server in maintenance mode
Write-Host "|"
Write-Host "------ Putting $EsxHost into Maintenance Mode " -ForegroundColor "White"
# Invoke Maintenance Mode for $EsxHost
If (-Not ($DataMigration)) {
$DataMigration = "EnsureAccessibility"
}
Set-VMHost -VMHost $ESXHost –State “Maintenance” –VsanDataMigrationMode $DataMigration | Out-Null
While ((Get-VMHost $EsxHost).ConnectionState -ne "Maintenance") {
Write-Host "." -NoNewline
}
Write-Host " |--- $EsxHost is now in Maintenance Mode" -ForegroundColor "Green"
# Reboot $EsxHost
Write-Host "|"
Write-Host "------ Rebooting $EsxHost" -ForegroundColor "White"
Write-Host " |--- $EsxHost is rebooting" -ForegroundColor "DarkYellow" -NoNewline
Restart-VMHost $EsxHost -Confirm:$false | Out-Null
While (((Get-VMHost $EsxHost).ConnectionState) -ne "NotResponding") {
Sleep 1
Write-Host "." -NoNewline
}
Write-Host " "
Write-Host " |--- $EsxHost is offline " -ForegroundColor "Red" -NoNewline
While (((Get-VMHost $EsxHost).ConnectionState) -eq "NotResponding") {
Sleep 1
Write-Host "." -NoNewline
}
Write-Host ""
Write-Host " |--- $EsxHost is back online and will exit Maintenance Mode shortly" -ForegroundColor "DarkYellow"
While (((Get-VMHost $EsxHost).ConnectionState) -ne "Maintenance") {
Sleep 1
Write-Host "." -NoNewline
}
# Exit maintenance mode
Write-Host " |--- $EsxHost exiting Maintenance mode"
Set-VMhost $EsxHost -State Connected | Out-Null
While (((Get-VMHost $EsxHost).ConnectionState) -ne "Connected") {
Sleep 1
}
Write-Host ""
Write-Host " |--- Reboot of $EsxHost complete" -ForegroundColor "Green"
Write-Host " "
}
Function Set-VsanLargeClusterSupport {
<#---
.SYNOPSIS
This function will go through each host in a designated cluster and enable or disable Large Cluster Support
.DESCRIPTION
This function will go through each host in a designated cluster and enable or disable Large Cluster Support
.PARAMETER ClusterName
The Cluster to modify
.PARAMETER LargeClusterSupport
Enable/Disable Large Cluster Support
.PARAMETER DataMigration
Set the Data Migration Mode for vSAN Nodes that are put in Maintenance Mode - Valid values are "Full" or "EnsureAccessibility"
.EXAMPLE To Set Large Cluster Support
Set-VsanLargeCluserSupport -ClusterName <ClusterName> -LargeClusterSupport $true
.EXAMPLE To Disable Large Cluster Support
Set-VsanLargeCluserSupport -ClusterName <ClusterName> -LargeClusterSupport $false
.NOTES This is only applicable to ESXi hosts with Virtual SAN 6.2 or greater
#>
# Set our Parameters
[CmdletBinding()]Param(
[Parameter(Mandatory=$True)][string]$ClusterName,
[Parameter(Mandatory=$True)][Boolean]$LargeClusterSupport,
[Parameter(Mandatory=$False)][ValidateSet("Full","EnsureAccessibility")][string]$DataMigration
)
# Get the Cluster Name
$Cluster = Get-Cluster -Name $ClusterName
# Display the Cluster
Write-Host Cluster: $($Cluster.name)
# If the Cluster has VSAN Enabled, then proceed
if ($Cluster.VsanEnabled){
# Cycle through each ESXi Host in the cluster
Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort-Object Name)){
# Grab EsxCLI content to check for proper host version
$esxcli = Get-EsxCli -VMHost $ESXHost -V2
# Write the name of the current host
Write-Host "Configuring Large Cluster Support for $EsxHost"
# Setup our Advanced Arguments for the EsxCli object
$GetAdvancedArgs = $EsxCli.system.settings.advanced.list.CreateArgs()
$SetAdvancedArgs = $EsxCli.system.settings.advanced.set.CreateArgs()
# Get the current setting for 'Increased Node Support'
$GetAdvancedArgs.option = "/VSAN/goto11"
$IncreasedNodeSupport = $esxcli.system.settings.advanced.list.Invoke($GetAdvancedArgs)
# Get the current setting for 'TCP/IP Heap Size'
$GetAdvancedArgs.option = "/Net/TcpipHeapMax"
$TcpipHeapMax = $esxcli.system.settings.advanced.list.Invoke($GetAdvancedArgs)
# Perform Different Actions Based on Whether We're Enabling/Disabling Large Cluster Support
Switch ($LargeClusterSupport) {
$true {
# Set 'Increased Node Support' if it is not already
If ($IncreasedNodeSupport.intvalue -ne "1") {
Write-Host "|"
Write-Host "------ Enabling Increased Node Support' for $EsxHost" -ForegroundColor "White"
$SetAdvancedArgs.option = "/VSAN/goto11"
$SetAdvancedArgs.intvalue = "1"
$esxcli.system.settings.advanced.set.Invoke($SetAdvancedArgs)
$RebootRequired = $true
} else {
# Do nothing if this is already set
Write-Host "|"
Write-Host "------ $EsxHost already setup for 'Increased Node Support'" -ForegroundColor "Green"
}
# Set 'Tcpip Heap Max' if it is not already
If (($TcpipHeapMax.IntValue -ne $TcpipHeapMax.MaxValue)) {
Write-Host "------ Adjusting TCP/IP Heap Max value' for $EsxHost" -ForegroundColor "White"
$SetAdvancedArgs.option = "/Net/TcpipHeapMax"
$SetAdvancedArgs.intvalue = $TcpipHeapMax.MaxValue
$esxcli.system.settings.advanced.set.Invoke($SetAdvancedArgs)
$RebootRequired = $true
} else {
# Do nothing if this is already set
Write-Host "------ $EsxHost already setup for correct 'TCP/IP Heap Size" -ForegroundColor "Green"
}
}
$false {
# Disable 'Increased Node Support' if it is set
If ($IncreasedNodeSupport.intvalue -ne "0") {
Write-Host "------ Disabling Increased Node Support' for $EsxHost" -ForegroundColor "White"
$SetAdvancedArgs.option = "/VSAN/goto11"
$SetAdvancedArgs.intvalue = "0"
$esxcli.system.settings.advanced.set.Invoke($SetAdvancedArgs)
$RebootRequired = $true
} else {
# Do nothing if it is already set
Write-Host "------ $EsxHost isn't setup for 'Increased Node Support'" -ForegroundColor "Green"
}
# Return 'Tcpip Heap Max' to the default setting if it is not already
If (($TcpipHeapMax.IntValue -ne $TcpipHeapMax.defaultintvalue)) {
Write-Host "------ Adjusting TCP/IP Heap Max value' for $EsxHost" -ForegroundColor "White"
$SetAdvancedArgs.option = "/Net/TcpipHeapMax"
$SetAdvancedArgs.intvalue = $TcpipHeapMax.defaultintvalue
$esxcli.system.settings.advanced.set.Invoke($SetAdvancedArgs)
$RebootRequired = $true
} else {
# Do nothing if it is already set
Write-Host "------ $EsxHost already setup for the default 'TCP/IP Heap Size" -ForegroundColor "Green"
}
}
}
If ($RebootRequired -eq $true) {
# Reboot the ESXi Host
Write-Host "Reboot Required for $EsxHost"
# If the Data Migration Mode is specified, honor it.
If ($DataMigration) {
RebootVsanNode -EsxHost $ESXHost -DataMigration $DataMigration
}
RebootVsanNode -EsxHost $ESXHost
}
}
}
}