-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcf-automated-workload-domain-deployment.ps1
359 lines (314 loc) · 13.7 KB
/
vcf-automated-workload-domain-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
# Author: William Lam
# Website: www.williamlam.com
$sddcManagerFQDN = "vcf-m01-sddcm01.vmbeer.local"
$sddcManagerUsername = "admin@local"
$sddcManagerPassword = "VMware1!VMware1!"
# License Later feature only applicable for VCF 5.1.1 and later
$LicenseLater = $true
$ESXILicense = ""
$VSANLicense = ""
$NSXLicense = ""
# Management Domain Configurations
$VCFManagementDomainPoolName = "vcf-m01-rp01"
# Workload Domain Configurations
$VCFWorkloadDomainAPIJSONFile = "vcf-commission-host-api.json"
$VCFWorkloadDomainName = "wld-w01"
$VCFWorkloadDomainOrgName = "vcf-w01"
$EnableVCLM = $true
$VLCMImageName = "Management-Domain-ESXi-Personality"
$EnableVSANESA = $false
# vCenter Configuration
$VCSAHostname = "vcf-w01-vc01"
$VCSAIP = "192.168.68.15"
$VCSARootPassword = "VMware1!"
# NSX Configuration
$NSXManagerVIPHostname = "vcf-w01-nsx01"
$NSXManagerVIPIP = "192.168.68.16"
$NSXManagerNode1Hostname = "vcf-w01-nsx01a"
$NSXManagerNode1IP = "192.168.68.17"
$NSXManagerNode2Hostname = "vcf-w01-nsx01b"
$NSXManagerNode2IP = "192.168.68.18"
$NSXManagerNode3Hostname = "vcf-w01-nsx01c"
$NSXManagerNode3IP = "192.168.68.19"
$NSXAdminPassword = "VMware1!VMware1!"
$SeparateNSXSwitch = $false
$VMNetmask = "255.255.255.0"
$VMGateway = "192.168.68.1"
$VMDomain = "vmbeer.local"
#### DO NOT EDIT BEYOND HERE ####
$confirmDeployment = 1
$commissionHost = 1
$generateWLDDeploymentFile = 1
$startWLDDeployment = 1
$verboseLogFile = "vcf-workload-domain-deployment.log"
$VCFWorkloadDomainDeploymentJSONFile = "${VCFWorkloadDomainName}.json"
$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(-Not (Get-InstalledModule -Name PowerVCF)) {
My-Logger "PowerVCF module was not detected, please install by running: Install-Module PowerVCF"
exit
}
if(!(Test-Path $VCFWorkloadDomainAPIJSONFile)) {
Write-Host -ForegroundColor Red "`nUnable to find $VCFWorkloadDomainAPIJSONFile ...`n"
exit
}
if($confirmDeployment -eq 1) {
Write-Host -ForegroundColor Magenta "`nPlease confirm the following configuration will be deployed:`n"
Write-Host -ForegroundColor Yellow "---- VCF Automated Workload Domain Deployment Configuration ---- "
Write-Host -NoNewline -ForegroundColor Green "Workload Domain Name: "
Write-Host -ForegroundColor White $VCFWorkloadDomainName
Write-Host -NoNewline -ForegroundColor Green "Workload Domain Org Name: "
Write-Host -ForegroundColor White $VCFWorkloadDomainOrgName
Write-Host -NoNewline -ForegroundColor Green "Workload Domain Host Comission File: "
Write-Host -ForegroundColor White $VCFWorkloadDomainAPIJSONFile
Write-Host -ForegroundColor Yellow "`n---- Target SDDC Manager Configuration ---- "
Write-Host -NoNewline -ForegroundColor Green "SDDC Manager Hostname: "
Write-Host -ForegroundColor White $sddcManagerFQDN
Write-Host -ForegroundColor Yellow "`n---- Workload Domain vCenter Server Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "vCenter Server Hostname: "
Write-Host -ForegroundColor White "${VCSAHostname}.${VMDomain} (${VCSAIP})"
Write-Host -ForegroundColor Yellow "`n---- Workload Domain NSX Server Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "NSX Manager VIP Hostname: "
Write-Host -ForegroundColor White $NSXManagerVIPHostname"."$VMDomain
Write-Host -NoNewline -ForegroundColor Green "NSX Manager VIP IP Address: "
Write-Host -ForegroundColor White $NSXManagerVIPIP
Write-Host -NoNewline -ForegroundColor Green "Node 1: "
Write-Host -ForegroundColor White "${NSXManagerNode1Hostname}.${VMDomain} ($NSXManagerNode1IP)"
Write-Host -NoNewline -ForegroundColor Green "Node 2: "
Write-Host -ForegroundColor White "${NSXManagerNode2Hostname}.${VMDomain} ($NSXManagerNode2IP)"
Write-Host -NoNewline -ForegroundColor Green "Node 3: "
Write-Host -ForegroundColor White "${NSXManagerNode3Hostname}.${VMDomain} ($NSXManagerNode3IP)"
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
}
My-Logger "Logging into SDDC Manager ..."
Request-VCFToken -fqdn $sddcManagerFQDN -username $sddcManagerUsername -password $sddcManagerPassword | Out-Null
if($commissionHost -eq 1) {
My-Logger "Retreiving VCF Management Domain $VCFManagementDomainPoolName PoolId ..."
$mgmtPoolId = (Get-VCFNetworkPool $VCFManagementDomainPoolName).id
My-Logger "Updating $VCFWorkloadDomainAPIJSONFile with PoolId value ..."
$hostCommissionFile = (Get-Content -Raw $VCFWorkloadDomainAPIJSONFile | ConvertFrom-Json)
foreach ($line in $hostCommissionFile) {
$line.networkPoolId = $mgmtPoolId
if($EnableVSANESA) {
$line.storageType = "VSAN_ESA"
}
}
$hostCommissionFile | ConvertTo-Json | Out-File -Force $VCFWorkloadDomainAPIJSONFile
My-Logger "Validating ESXi host commission file $VCFWorkloadDomainAPIJSONFile ..."
$commissionHostValidationResult = New-VCFCommissionedHost -json (Get-Content -Raw $VCFWorkloadDomainAPIJSONFile) -Validate
if($commissionHostValidationResult.resultStatus) {
$commissionHostResult = New-VCFCommissionedHost -json (Get-Content -Raw $VCFWorkloadDomainAPIJSONFile)
} else {
Write-Error "Validation of host commission file $VCFWorkloadDomainAPIJSONFile failed"
break
}
My-Logger "Comissioning new ESXi hosts for Workload Domain deployment using $VCFWorkloadDomainAPIJSONFile ..."
while( (Get-VCFTask ${commissionHostResult}.id).status -ne "Successful" ) {
My-Logger "Host commission has not completed, sleeping for 30 seconds"
Start-Sleep -Second 30
}
}
if($generateWLDDeploymentFile -eq 1) {
My-Logger "Retreiving unassigned ESXi hosts from SDDC Manager and creating Workload Domain JSON deployment file $VCFWorkloadDomainDeploymentJSONFile"
$hostSpecs = @()
foreach ($id in (Get-VCFhost -Status UNASSIGNED_USEABLE).id) {
if($SeparateNSXSwitch) {
$vmNics = @(
@{
"id" = "vmnic0"
"vdsName" = "wld-w01-cl01-vds01"
}
@{
"id" = "vmnic1"
"vdsName" = "wld-w01-cl01-vds01"
}
@{
"id" = "vmnic2"
"vdsName" = "wld-w01-cl01-vds02"
}
@{
"id" = "vmnic3"
"vdsName" = "wld-w01-cl01-vds02"
}
)
} else {
$vmNics = @(
@{
"id" = "vmnic0"
"vdsName" = "wld-w01-cl01-vds01"
}
@{
"id" = "vmnic1"
"vdsName" = "wld-w01-cl01-vds01"
}
)
}
$tmp = [ordered] @{
"id" = $id
"licenseKey" = $ESXILicense
"hostNetworkSpec" = @{
"vmNics" = $vmNics
}
}
$hostSpecs += $tmp
}
$payload = [ordered] @{
"domainName" = $VCFWorkloadDomainName
"orgName" = $VCFWorkloadDomainOrgName
"vcenterSpec" = @{
"name" = "wld-vc-w01"
"networkDetailsSpec" = @{
"ipAddress" = $VCSAIP
"dnsName" = $VCSAHostname + "." + $VMDomain
"gateway" = $VMGateway
"subnetMask" = $VMNetmask
}
"rootPassword" = $VCSARootPassword
"datacenterName" = "wld-w01-dc01"
}
"computeSpec" = [ordered] @{
"clusterSpecs" = @(
[ordered] @{
"name" = "wld-w01-cl01"
"hostSpecs" = $hostSpecs
"datastoreSpec" = @{
"vsanDatastoreSpec" = @{
"failuresToTolerate" = "1"
"licenseKey" = $VSANLicense
"datastoreName" = "wld-w01-cl01-vsan01"
}
}
"networkSpec" = @{
"vdsSpecs" = @(
[ordered] @{
"name" = "wld-w01-cl01-vds01"
"portGroupSpecs" = @(
@{
"name" = "wld-w01-cl01-vds01-management"
"transportType" = "MANAGEMENT"
}
@{
"name" = "wld-w01-cl01-vds01-vmotion"
"transportType" = "VMOTION"
}
@{
"name" = "wld-w01-cl01-vds01-vsan"
"transportType" = "VSAN"
}
)
}
)
"nsxClusterSpec" = [ordered] @{
"nsxTClusterSpec" = @{
"geneveVlanId" = 2005
"ipAddressPoolSpec" = @{
"name" = "wld-pool"
"subnets" = @(
[ordered] @{
"cidr" = "10.0.5.0/24"
"gateway" = "10.0.5.253"
"ipAddressPoolRanges" = @(
[ordered] @{
"start" = "10.0.5.1"
"end" = "10.0.5.128"
}
)
}
)
}
}
}
}
}
)
}
"nsxTSpec" = [ordered] @{
"nsxManagerSpecs" = @(
[ordered] @{
"name" = $NSXManagerNode1Hostname
"networkDetailsSpec" = @{
"ipAddress" = $NSXManagerNode1IP
"dnsName" = $NSXManagerNode1Hostname + "." + $VMDomain
"gateway" = $VMGateway
"subnetMask" = $VMNetmask
}
}
[ordered] @{
"name" = $NSXManagerNode2Hostname
"networkDetailsSpec" = @{
"ipAddress" = $NSXManagerNode2IP
"dnsName" = $NSXManagerNode2Hostname + "." + $VMDomain
"gateway" = $VMGateway
"subnetMask" = $VMNetmask
}
}
[ordered] @{
"name" = $NSXManagerNode3Hostname
"networkDetailsSpec" = @{
"ipAddress" = $NSXManagerNode3IP
"dnsName" = $NSXManagerNode3Hostname + "." + $VMDomain
"gateway" = $VMGateway
"subnetMask" = $VMNetmask
}
}
)
"vip" = $NSXManagerVIPIP
"vipFqdn" = $NSXManagerVIPHostname + "." + $VMDomain
"licenseKey" = $NSXLicense
"nsxManagerAdminPassword" = $NSXAdminPassword
}
}
if($SeparateNSXSwitch) {
$payload.computeSpec.clusterSpecs.networkSpec.vdsSpecs+=@{"name"="wld-w01-cl01-vds02";"isUsedByNsxt"=$true}
}
if($LicenseLater) {
if($ESXILicense -eq "" -and $VSANLicense -eq "" -and $NSXLicense -eq "") {
$EvaluationMode = $true
} else {
$EvaluationMode = $false
}
$payload.add("deployWithoutLicenseKeys",$EvaluationMode)
}
if($EnableVSANESA) {
$esaEnable = [ordered]@{
"enabled" = $true
}
$payload.computeSpec.clusterSpecs.datastoreSpec.vsanDatastoreSpec.Add("esaConfig",$esaEnable)
$payload.computeSpec.clusterSpecs.datastoreSpec.vsanDatastoreSpec.Remove("failuresToTolerate")
}
if($EnableVCLM) {
$clusterImageId = (Get-VCFPersonality | where {$_.personalityName -eq $VLCMImageName}).personalityId
if($clusterImageId -eq $null) {
Write-Host -ForegroundColor Red "`nUnable to find vLCM Image named $VLCMImageName ...`n"
exit
}
$payload.computeSpec.clusterSpecs.Add("clusterImageId",$clusterImageId)
}
$payload | ConvertTo-Json -Depth 12 | Out-File $VCFWorkloadDomainDeploymentJSONFile
}
if($startWLDDeployment -eq 1) {
My-Logger "Starting Workload Domain deployment using file $VCFWorkloadDomainDeploymentJSONFile"
$wldDeployment = New-VCFWorkloadDomain -json $VCFWorkloadDomainDeploymentJSONFile
My-Logger "Open a browser to your SDDC Manager to monitor the deployment progress"
}
$EndTime = Get-Date
$duration = [math]::Round((New-TimeSpan -Start $StartTime -End $EndTime).TotalMinutes,2)
My-Logger "VCF Workload Domain Deployment Complete!"
My-Logger "StartTime: $StartTime"
My-Logger "EndTime: $EndTime"
My-Logger "Duration: $duration minutes to initiate Workload Domain deployment"