-
Notifications
You must be signed in to change notification settings - Fork 25
/
vsphere-vsan-8-lab-deployment.ps1
506 lines (430 loc) · 24.3 KB
/
vsphere-vsan-8-lab-deployment.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# Author: William Lam
# Website: www.williamlam.com
# vCenter Server used to deploy vSphere & vSAN 8 Lab
$VIServer = "192.168.30.3"
$VIUsername = "[email protected]"
$VIPassword = "VMware1!"
# Full Path to the Nested ESXi 8.0 VA & Extracted VCSA 8.0 ISO
$NestedESXiApplianceOVA = "/Volumes/Storage/Software/VMware/Lab/Nested_ESXi8.0_IA_Appliance_Template_v2.ova"
$VCSAInstallerPath = "/Volumes/Storage/Software/VMware/Lab/VMware-VCSA-all-8.0.0-20519528"
# Nested ESXi VMs to deploy
$NestedESXiHostnameToIPs = @{
"esxi-1" = "192.168.30.181"
"esxi-2" = "192.168.30.182"
"esxi-3" = "192.168.30.183"
}
# Nested ESXi VM Resources
$NestedESXivCPU = "4"
$NestedESXivMEM = "10" #GB
$NestedESXiCachingvDisk = "8" #GB
$NestedESXiCapacityvDisk = "40" #GB
# VCSA Deployment Configuration
$VCSADeploymentSize = "tiny"
$VCSADisplayName = "vcsa-1"
$VCSAIPAddress = "192.168.30.180"
$VCSAHostname = "192.168.30.180" #Change to IP if you don't have valid DNS
$VCSAPrefix = "24"
$VCSASSODomainName = "vsphere.local"
$VCSASSOPassword = "VMware1!"
$VCSARootPassword = "VMware1!"
$VCSASSHEnable = "true"
# General Deployment Configuration for Nested ESX & VCSA VM
$VMDatacenter = "Primp-Datacenter"
$VMCluster = "Supermicro-Cluster"
$VMNetwork = "VM Network"
$VMDatastore = "sm-vsanDatastore"
$VMNetmask = "255.255.255.0"
$VMGateway = "192.168.30.1"
$VMDNS = "192.168.30.2"
$VMNTP = "45.87.78.35"
$VMPassword = "VMware1!"
$VMDomain = "primp-industries.local"
$VMSyslog = "172.17.33.3"
$VMFolder = "Workloads"
# Applicable to Nested ESXi only
$VMSSH = "true"
$VMVMFS = "false"
# Name of new vSphere Datacenter/Cluster when VCSA is deployed
$NewVCDatacenterName = "Datacenter"
$NewVCVSANClusterName = "Cluster"
$NewVCVDSName = "VDS"
$NewVCMgmtPortgroupName = "DVPG-Management-Network"
# Advanced Configurations
# Set to 1 only if you have DNS (forward/reverse) for ESXi hostnames
$addHostByDnsName = 0
#### DO NOT EDIT BEYOND HERE ####
$verboseLogFile = "vsphere-vsan-8-lab-deployment.log"
$random_string = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$VAppName = "Nested-vSphere-vSAN-8-Lab-$random_string"
$preCheck = 1
$confirmDeployment = 1
$deployNestedESXiVMs = 1
$deployVCSA = 1
$setupNewVC = 1
$addESXiHostsToVC = 1
$configureVSANDiskGroup = 1
$configureVDS = 1
$clearVSANHealthCheckAlarm = 1
$moveVMsIntovApp = 1
$vcsaSize2MemoryStorageMap = @{
"tiny"=@{"cpu"="2";"mem"="14";"disk"="415"};
"small"=@{"cpu"="4";"mem"="21";"disk"="480"};
"medium"=@{"cpu"="8";"mem"="30";"disk"="700"};
"large"=@{"cpu"="16";"mem"="39";"disk"="1065"};
"xlarge"=@{"cpu"="24";"mem"="58";"disk"="1805"}
}
$esxiTotalCPU = 0
$vcsaTotalCPU = 0
$esxiTotalMemory = 0
$vcsaTotalMemory = 0
$esxiTotalStorage = 0
$vcsaTotalStorage = 0
$StartTime = Get-Date
Function My-Logger {
param(
[Parameter(Mandatory=$true)][String]$message,
[Parameter(Mandatory=$false)][String]$color="green"
)
$timeStamp = Get-Date -Format "MM-dd-yyyy_hh:mm:ss"
Write-Host -NoNewline -ForegroundColor White "[$timestamp]"
Write-Host -ForegroundColor $color " $message"
$logMessage = "[$timeStamp] $message"
$logMessage | Out-File -Append -LiteralPath $verboseLogFile
}
if($preCheck -eq 1) {
if(!(Test-Path $NestedESXiApplianceOVA)) {
Write-Host -ForegroundColor Red "`nUnable to find $NestedESXiApplianceOVA ...`n"
exit
}
if(!(Test-Path $VCSAInstallerPath)) {
Write-Host -ForegroundColor Red "`nUnable to find $VCSAInstallerPath ...`n"
exit
}
if($PSVersionTable.PSEdition -ne "Core") {
Write-Host -ForegroundColor Red "`tPowerShell Core was not detected, please install that before continuing ... `n"
exit
}
}
if($confirmDeployment -eq 1) {
Write-Host -ForegroundColor Magenta "`nPlease confirm the following configuration will be deployed:`n"
Write-Host -ForegroundColor Yellow "---- vSphere and vSAN 8 Automated Lab Deployment Configuration ---- "
Write-Host -NoNewline -ForegroundColor Green "Nested ESXi Image Path: "
Write-Host -ForegroundColor White $NestedESXiApplianceOVA
Write-Host -NoNewline -ForegroundColor Green "VCSA Image Path: "
Write-Host -ForegroundColor White $VCSAInstallerPath
Write-Host -ForegroundColor Yellow "`n---- vCenter Server Deployment Target Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "vCenter Server Address: "
Write-Host -ForegroundColor White $VIServer
Write-Host -NoNewline -ForegroundColor Green "VM Network: "
Write-Host -ForegroundColor White $VMNetwork
Write-Host -NoNewline -ForegroundColor Green "VM Storage: "
Write-Host -ForegroundColor White $VMDatastore
Write-Host -NoNewline -ForegroundColor Green "VM Cluster: "
Write-Host -ForegroundColor White $VMCluster
Write-Host -NoNewline -ForegroundColor Green "VM vApp: "
Write-Host -ForegroundColor White $VAppName
Write-Host -ForegroundColor Yellow "`n---- vESXi Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "# of Nested ESXi VMs: "
Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.count
Write-Host -NoNewline -ForegroundColor Green "vCPU: "
Write-Host -ForegroundColor White $NestedESXivCPU
Write-Host -NoNewline -ForegroundColor Green "vMEM: "
Write-Host -ForegroundColor White "$NestedESXivMEM GB"
Write-Host -NoNewline -ForegroundColor Green "Caching VMDK: "
Write-Host -ForegroundColor White "$NestedESXiCachingvDisk GB"
Write-Host -NoNewline -ForegroundColor Green "Capacity VMDK: "
Write-Host -ForegroundColor White "$NestedESXiCapacityvDisk GB"
Write-Host -NoNewline -ForegroundColor Green "IP Address(s): "
Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.Values
Write-Host -NoNewline -ForegroundColor Green "Netmask "
Write-Host -ForegroundColor White $VMNetmask
Write-Host -NoNewline -ForegroundColor Green "Gateway: "
Write-Host -ForegroundColor White $VMGateway
Write-Host -NoNewline -ForegroundColor Green "DNS: "
Write-Host -ForegroundColor White $VMDNS
Write-Host -NoNewline -ForegroundColor Green "NTP: "
Write-Host -ForegroundColor White $VMNTP
Write-Host -NoNewline -ForegroundColor Green "Syslog: "
Write-Host -ForegroundColor White $VMSyslog
Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
Write-Host -ForegroundColor White $VMSSH
Write-Host -NoNewline -ForegroundColor Green "Create VMFS Volume: "
Write-Host -ForegroundColor White $VMVMFS
Write-Host -ForegroundColor Yellow "`n---- VCSA Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "Deployment Size: "
Write-Host -ForegroundColor White $VCSADeploymentSize
Write-Host -NoNewline -ForegroundColor Green "SSO Domain: "
Write-Host -ForegroundColor White $VCSASSODomainName
Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
Write-Host -ForegroundColor White $VCSASSHEnable
Write-Host -NoNewline -ForegroundColor Green "Hostname: "
Write-Host -ForegroundColor White $VCSAHostname
Write-Host -NoNewline -ForegroundColor Green "IP Address: "
Write-Host -ForegroundColor White $VCSAIPAddress
Write-Host -NoNewline -ForegroundColor Green "Netmask "
Write-Host -ForegroundColor White $VMNetmask
Write-Host -NoNewline -ForegroundColor Green "Gateway: "
Write-Host -ForegroundColor White $VMGateway
$esxiTotalCPU = $NestedESXiHostnameToIPs.count * [int]$NestedESXivCPU
$esxiTotalMemory = $NestedESXiHostnameToIPs.count * [int]$NestedESXivMEM
$esxiTotalStorage = ($NestedESXiHostnameToIPs.count * [int]$NestedESXiCachingvDisk) + ($NestedESXiHostnameToIPs.count * [int]$NestedESXiCapacityvDisk)
$vcsaTotalCPU = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.cpu
$vcsaTotalMemory = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.mem
$vcsaTotalStorage = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.disk
Write-Host -ForegroundColor Yellow "`n---- Resource Requirements ----"
Write-Host -NoNewline -ForegroundColor Green "ESXi VM CPU: "
Write-Host -NoNewline -ForegroundColor White $esxiTotalCPU
Write-Host -NoNewline -ForegroundColor Green " ESXi VM Memory: "
Write-Host -NoNewline -ForegroundColor White $esxiTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green "ESXi VM Storage: "
Write-Host -ForegroundColor White $esxiTotalStorage "GB"
Write-Host -NoNewline -ForegroundColor Green "VCSA VM CPU: "
Write-Host -NoNewline -ForegroundColor White $vcsaTotalCPU
Write-Host -NoNewline -ForegroundColor Green " VCSA VM Memory: "
Write-Host -NoNewline -ForegroundColor White $vcsaTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green "VCSA VM Storage: "
Write-Host -ForegroundColor White $vcsaTotalStorage "GB"
Write-Host -ForegroundColor White "---------------------------------------------"
Write-Host -NoNewline -ForegroundColor Green "Total CPU: "
Write-Host -ForegroundColor White ($esxiTotalCPU + $vcsaTotalCPU)
Write-Host -NoNewline -ForegroundColor Green "Total Memory: "
Write-Host -ForegroundColor White ($esxiTotalMemory + $vcsaTotalMemory) "GB"
Write-Host -NoNewline -ForegroundColor Green "Total Storage: "
Write-Host -ForegroundColor White ($esxiTotalStorage + $vcsaTotalStorage) "GB"
Write-Host -ForegroundColor Magenta "`nWould you like to proceed with this deployment?`n"
$answer = Read-Host -Prompt "Do you accept (Y or N)"
if($answer -ne "Y" -or $answer -ne "y") {
exit
}
Clear-Host
}
if( $deployNestedESXiVMs -eq 1 -or $deployVCSA -eq 1) {
My-Logger "Connecting to Management vCenter Server $VIServer ..."
$viConnection = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue
$datastore = Get-Datastore -Server $viConnection -Name $VMDatastore | Select -First 1
$cluster = Get-Cluster -Server $viConnection -Name $VMCluster
$datacenter = $cluster | Get-Datacenter
$vmhost = $cluster | Get-VMHost | Select -First 1
}
if($deployNestedESXiVMs -eq 1) {
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
$ovfconfig = Get-OvfConfiguration $NestedESXiApplianceOVA
$networkMapLabel = ($ovfconfig.ToHashTable().keys | where {$_ -Match "NetworkMapping"}).replace("NetworkMapping.","").replace("-","_").replace(" ","_")
$ovfconfig.NetworkMapping.$networkMapLabel.value = $VMNetwork
$ovfconfig.common.guestinfo.hostname.value = $VMName
$ovfconfig.common.guestinfo.ipaddress.value = $VMIPAddress
$ovfconfig.common.guestinfo.netmask.value = $VMNetmask
$ovfconfig.common.guestinfo.gateway.value = $VMGateway
$ovfconfig.common.guestinfo.dns.value = $VMDNS
$ovfconfig.common.guestinfo.domain.value = $VMDomain
$ovfconfig.common.guestinfo.ntp.value = $VMNTP
$ovfconfig.common.guestinfo.syslog.value = $VMSyslog
$ovfconfig.common.guestinfo.password.value = $VMPassword
if($VMSSH -eq "true") {
$VMSSHVar = $true
} else {
$VMSSHVar = $false
}
$ovfconfig.common.guestinfo.ssh.value = $VMSSHVar
My-Logger "Deploying Nested ESXi VM $VMName ..."
$vm = Import-VApp -Source $NestedESXiApplianceOVA -OvfConfiguration $ovfconfig -Name $VMName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
My-Logger "Adding vmnic2/vmnic3 for `"$VMNetwork`" to passthrough to Nested ESXi VMs ..."
New-NetworkAdapter -VM $vm -Type Vmxnet3 -NetworkName $VMNetwork -StartConnected -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
New-NetworkAdapter -VM $vm -Type Vmxnet3 -NetworkName $VMNetwork -StartConnected -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -name "ethernet2.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet2.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -name "ethernet3.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet3.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vCPU Count to $NestedESXivCPU & vMEM to $NestedESXivMEM GB ..."
Set-VM -Server $viConnection -VM $vm -NumCpu $NestedESXivCPU -MemoryGB $NestedESXivMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vSAN Cache VMDK size to $NestedESXiCachingvDisk GB & Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 3" | Set-HardDisk -CapacityGB $NestedESXiCapacityvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Powering On $vmname ..."
$vm | Start-Vm -RunAsync | Out-Null
}
}
if($deployVCSA -eq 1) {
if($IsWindows) {
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_VC.json") | convertfrom-json
} else {
$config = (Get-Content -Raw "$($VCSAInstallerPath)/vcsa-cli-installer/templates/install/embedded_vCSA_on_VC.json") | convertfrom-json
}
$config.'new_vcsa'.vc.hostname = $VIServer
$config.'new_vcsa'.vc.username = $VIUsername
$config.'new_vcsa'.vc.password = $VIPassword
$config.'new_vcsa'.vc.deployment_network = $VMNetwork
$config.'new_vcsa'.vc.datastore = $datastore
$config.'new_vcsa'.vc.datacenter = $datacenter.name
$config.'new_vcsa'.vc.target = $VMCluster
$config.'new_vcsa'.appliance.thin_disk_mode = $true
$config.'new_vcsa'.appliance.deployment_option = $VCSADeploymentSize
$config.'new_vcsa'.appliance.name = $VCSADisplayName
$config.'new_vcsa'.network.ip_family = "ipv4"
$config.'new_vcsa'.network.mode = "static"
$config.'new_vcsa'.network.ip = $VCSAIPAddress
$config.'new_vcsa'.network.dns_servers[0] = $VMDNS
$config.'new_vcsa'.network.prefix = $VCSAPrefix
$config.'new_vcsa'.network.gateway = $VMGateway
$config.'new_vcsa'.os.ntp_servers = $VMNTP
$config.'new_vcsa'.network.system_name = $VCSAHostname
$config.'new_vcsa'.os.password = $VCSARootPassword
if($VCSASSHEnable -eq "true") {
$VCSASSHEnableVar = $true
} else {
$VCSASSHEnableVar = $false
}
$config.'new_vcsa'.os.ssh_enable = $VCSASSHEnableVar
$config.'new_vcsa'.sso.password = $VCSASSOPassword
$config.'new_vcsa'.sso.domain_name = $VCSASSODomainName
if($IsWindows) {
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json -WarningAction Ignore | Set-Content -Path "$($ENV:Temp)\jsontemplate.json"
My-Logger "Deploying the VCSA ..."
Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:Temp)\jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
} elseif($IsMacOS) {
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json -WarningAction Ignore | Set-Content -Path "$($ENV:TMPDIR)jsontemplate.json"
My-Logger "Deploying the VCSA ..."
Invoke-Expression "$($VCSAInstallerPath)/vcsa-cli-installer/mac/vcsa-deploy install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:TMPDIR)jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
} elseif ($IsLinux) {
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json -WarningAction Ignore| Set-Content -Path "/tmp/jsontemplate.json"
My-Logger "Deploying the VCSA ..."
Invoke-Expression "$($VCSAInstallerPath)/vcsa-cli-installer/lin64/vcsa-deploy install --no-esx-ssl-verify --accept-eula --acknowledge-ceip /tmp/jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
}
}
if($moveVMsIntovApp -eq 1) {
# Check whether DRS is enabled as that is required to create vApp
if((Get-Cluster -Server $viConnection $cluster).DrsEnabled) {
My-Logger "Creating vApp $VAppName ..."
$VApp = New-VApp -Name $VAppName -Server $viConnection -Location $cluster
if(-Not (Get-Folder $VMFolder -ErrorAction Ignore)) {
My-Logger "Creating VM Folder $VMFolder ..."
$folder = New-Folder -Name $VMFolder -Server $viConnection -Location (Get-Datacenter $VMDatacenter | Get-Folder vm)
}
if($deployNestedESXiVMs -eq 1) {
My-Logger "Moving Nested ESXi VMs into $VAppName vApp ..."
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$vm = Get-VM -Name $_.Key -Server $viConnection
Move-VM -VM $vm -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($deployVCSA -eq 1) {
$vcsaVM = Get-VM -Name $VCSADisplayName -Server $viConnection
My-Logger "Moving $VCSADisplayName into $VAppName vApp ..."
Move-VM -VM $vcsaVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
My-Logger "Moving $VAppName to VM Folder $VMFolder ..."
Move-VApp -Server $viConnection $VAppName -Destination (Get-Folder -Server $viConnection $VMFolder) | Out-File -Append -LiteralPath $verboseLogFile
} else {
My-Logger "vApp $VAppName will NOT be created as DRS is NOT enabled on vSphere Cluster ${cluster} ..."
}
}
if( $deployNestedESXiVMs -eq 1 -or $deployVCSA -eq 1 -or $deployNSXAdvLB -eq 1) {
My-Logger "Disconnecting from $VIServer ..."
Disconnect-VIServer -Server $viConnection -Confirm:$false
}
if($setupNewVC -eq 1) {
My-Logger "Connecting to the new VCSA ..."
$vc = Connect-VIServer $VCSAIPAddress -User "administrator@$VCSASSODomainName" -Password $VCSASSOPassword -WarningAction SilentlyContinue
$d = Get-Datacenter -Server $vc $NewVCDatacenterName -ErrorAction Ignore
if( -Not $d) {
My-Logger "Creating Datacenter $NewVCDatacenterName ..."
New-Datacenter -Server $vc -Name $NewVCDatacenterName -Location (Get-Folder -Type Datacenter -Server $vc) | Out-File -Append -LiteralPath $verboseLogFile
}
$c = Get-Cluster -Server $vc $NewVCVSANClusterName -ErrorAction Ignore
if( -Not $c) {
My-Logger "Creating VSAN Cluster $NewVCVSANClusterName ..."
New-Cluster -Server $vc -Name $NewVCVSANClusterName -Location (Get-Datacenter -Name $NewVCDatacenterName -Server $vc) -DrsEnabled -HAEnabled -VsanEnabled | Out-File -Append -LiteralPath $verboseLogFile
(Get-Cluster $NewVCVSANClusterName) | New-AdvancedSetting -Name "das.ignoreRedundantNetWarning" -Type ClusterHA -Value $true -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
if($addESXiHostsToVC -eq 1) {
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
$targetVMHost = $VMIPAddress
if($addHostByDnsName -eq 1) {
$targetVMHost = $VMName
}
My-Logger "Adding ESXi host $targetVMHost to Cluster ..."
Add-VMHost -Server $vc -Location (Get-Cluster -Name $NewVCVSANClusterName) -User "root" -Password $VMPassword -Name $targetVMHost -Force | Out-File -Append -LiteralPath $verboseLogFile
}
$haRuntime = (Get-Cluster $NewVCVSANClusterName).ExtensionData.RetrieveDasAdvancedRuntimeInfo
$totalHaHosts = $haRuntime.TotalHosts
$totalHaGoodHosts = $haRuntime.TotalGoodHosts
while($totalHaGoodHosts -ne $totalHaHosts) {
My-Logger "Waiting for vSphere HA configuration to complete ..."
Start-Sleep -Seconds 60
$haRuntime = (Get-Cluster $NewVCVSANClusterName).ExtensionData.RetrieveDasAdvancedRuntimeInfo
$totalHaHosts = $haRuntime.TotalHosts
$totalHaGoodHosts = $haRuntime.TotalGoodHosts
}
}
if($configureVSANDiskGroup -eq 1) {
My-Logger "Enabling VSAN & disabling VSAN Health Check ..."
Get-VsanClusterConfiguration -Server $vc -Cluster $NewVCVSANClusterName | Set-VsanClusterConfiguration -HealthCheckIntervalMinutes 0 | Out-File -Append -LiteralPath $verboseLogFile
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
$luns = $vmhost | Get-ScsiLun | select CanonicalName, CapacityGB
My-Logger "Querying ESXi host disks to create VSAN Diskgroups ..."
foreach ($lun in $luns) {
if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCachingvDisk") {
$vsanCacheDisk = $lun.CanonicalName
}
if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCapacityvDisk") {
$vsanCapacityDisk = $lun.CanonicalName
}
}
My-Logger "Creating VSAN DiskGroup for $vmhost ..."
New-VsanDiskGroup -Server $vc -VMHost $vmhost -SsdCanonicalName $vsanCacheDisk -DataDiskCanonicalName $vsanCapacityDisk | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($configureVDS -eq 1) {
# vmnic0 = Management on VSS
# vmnic1 = unused
# vmnic2 = Management on VDS (uplink1)
# vmnic3 = unused
$vds = New-VDSwitch -Server $vc -Name $NewVCVDSName -Location (Get-Datacenter -Name $NewVCDatacenterName) -Mtu 1600 -NumUplinkPorts 2
My-Logger "Creating VDS Management Network Portgroup"
New-VDPortgroup -Server $vc -Name $NewVCMgmtPortgroupName -Vds $vds | Out-File -Append -LiteralPath $verboseLogFile
Get-VDPortgroup -Server $vc $NewVCMgmtPortgroupName | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort @("dvUplink1") -UnusedUplinkPort @("dvUplink2") | Out-File -Append -LiteralPath $verboseLogFile
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
My-Logger "Adding $vmhost to $NewVCVDSName"
$vds | Add-VDSwitchVMHost -VMHost $vmhost | Out-Null
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic2,vmnic3
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false
}
}
if($clearVSANHealthCheckAlarm -eq 1) {
My-Logger "Clearing default VSAN Health Check Alarms, not applicable in Nested ESXi env ..."
$alarmMgr = Get-View AlarmManager -Server $vc
Get-Cluster -Server $vc | where {$_.ExtensionData.TriggeredAlarmState} | %{
$cluster = $_
$Cluster.ExtensionData.TriggeredAlarmState | %{
$alarmMgr.AcknowledgeAlarm($_.Alarm,$cluster.ExtensionData.MoRef)
}
}
$alarmSpec = New-Object VMware.Vim.AlarmFilterSpec
$alarmMgr.ClearTriggeredAlarms($alarmSpec)
}
# Final configure and then exit maintanence mode in case patching was done earlier
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
# Disable Core Dump Warning
Get-AdvancedSetting -Entity $vmhost -Name UserVars.SuppressCoredumpWarning | Set-AdvancedSetting -Value 1 -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
# Enable vMotion traffic
$vmhost | Get-VMHostNetworkAdapter -VMKernel | Set-VMHostNetworkAdapter -VMotionEnabled $true -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
if($vmhost.ConnectionState -eq "Maintenance") {
Set-VMHost -VMhost $vmhost -State Connected -RunAsync -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
My-Logger "Disconnecting from new VCSA ..."
Disconnect-VIServer $vc -Confirm:$false
}
$EndTime = Get-Date
$duration = [math]::Round((New-TimeSpan -Start $StartTime -End $EndTime).TotalMinutes,2)
My-Logger "vSphere & vSAN 8 Lab Deployment Complete!"
My-Logger "StartTime: $StartTime"
My-Logger " EndTime: $EndTime"
My-Logger " Duration: $duration minutes"