-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerVCF.psm1
3054 lines (2585 loc) · 98.1 KB
/
powerVCF.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
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#PowerShell module for VMware Cloud Foundation
#Contributions, Improvements &/or Complete Re-writes Welcome!
#https://github.com/PowerVCF/PowerVCF
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
### Note
#This powershell module should be considered entirely experimental. It is still
#in development & not tested beyond lab scenarios.
#It is recommended you dont use it for any production environment
#without testing extensively!
# Enable communication with self signed certs when using Powershell Core
# If you require all communications to be secure and do not wish to
# allow communication with self signed certs remove lines 31-52 before
# importing the module
if ($PSEdition -eq 'Core') {
$PSDefaultParameterValues.Add("Invoke-RestMethod:SkipCertificateCheck",$true)
}
if ($PSEdition -eq 'Desktop') {
# Enable communication with self signed certs when using Windows Powershell
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertificatePolicy : ICertificatePolicy {
public TrustAllCertificatePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate certificate,
WebRequest wRequest, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertificatePolicy
}
#### Do not modify anything below this line. All user variables are in the accompanying JSON files #####
Function Connect-VCFManager {
<#
.SYNOPSIS
Connects to the specified SDDC Manager and stores the credentials in a base64 string
.DESCRIPTION
The Connect-VCFManager cmdlet connects to the specified SDDC Manager and stores the credentials
in a base64 string. It is required once per session before running all other cmdlets
.EXAMPLE
PS C:\> Connect-VCFManager -fqdn sfo01vcf01.sfo.rainpole.local -username admin -password VMware1!
This example shows how to connect to SDDC Manager
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$fqdn,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$username,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$password
)
if ( -not $PsBoundParameters.ContainsKey("username") -or ( -not $PsBoundParameters.ContainsKey("username")))
{
# Request Credentials
$creds = Get-Credential
$username = $creds.UserName.ToString()
$password = $creds.GetNetworkCredential().password
}
$Global:sddcManager = $fqdn
# Create Basic Authentication Encoded Credentials
$Global:base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
# validate credentials by executing an API call
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
# Checking against the sddc-managers API
$uri = "https://$sddcManager/v1/sddc-managers"
Try {
# PS Core has -SkipCertificateCheck implemented, PowerShell 5.x does not
if ($PSEdition -eq 'Core') {
$response = Invoke-WebRequest -Method GET -Uri $uri -Headers $headers -SkipCertificateCheck
}
else {
$response = Invoke-WebRequest -Method GET -Uri $uri -Headers $headers
}
if ($response.StatusCode -eq 200) {
Write-Host ""
Write-Host " Successfully connected to SDDC Manager:" $sddcManager -ForegroundColor Yellow
Write-Host ""
}
}
Catch {
Write-Host ""
Write-Host "" $_.Exception.Message -ForegroundColor Red
Write-Host " Credentials provided did not return a valid API response (expected 200). Retry Connect-VCFManager cmdlet" -ForegroundColor Red
Write-Host
}
}
Export-ModuleMember -function Connect-VCFManager
######### Start Host Operations ##########
Function Get-VCFHost {
<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of hosts.
.DESCRIPTION
The Get-VCFHost cmdlet connects to the specified SDDC Manager and retrieves a list of hosts.
VCF Hosts are defined by status
- ASSIGNED - Hosts that are assigned to a Workload domain
- UNASSIGNED_USEABLE - Hosts that are available to be assigned to a Workload Domain
- UNASSIGNED_UNUSEABLE - Hosts that are currently not assigned to any domain and can be used
for other domain tasks after completion of cleanup operation
.EXAMPLE
PS C:\> Get-VCFHost
This example shows how to get all hosts regardless of status
.EXAMPLE
PS C:\> Get-VCFHost -Status ASSIGNED
This example shows how to get all hosts with a specific status
.EXAMPLE
PS C:\> Get-VCFHost -id edc4f372-aab5-4906-b6d8-9b96d3113304
This example shows how to get a host by id
.EXAMPLE
PS C:\> Get-VCFHost -fqdn sfo01m01esx01.sfo01.rainpole.local
This example shows how to get a host by fqdn
#>
param (
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$fqdn,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$Status,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
if ($PsBoundParameters.ContainsKey("status")) {
$uri = "https://$sddcManager/v1/hosts?status=$status"
}
if ($PsBoundParameters.ContainsKey("id")) {
$uri = "https://$sddcManager/v1/hosts/$id"
}
if ( -not $PsBoundParameters.ContainsKey("status") -and ( -not $PsBoundParameters.ContainsKey("id"))) {
$uri = "https://$sddcManager/v1/hosts"
}
if ($PsBoundParameters.ContainsKey("fqdn")) {
$uri = "https://$sddcManager/v1/hosts"
}
try {
if ($PsBoundParameters.ContainsKey("fqdn")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.fqdn -eq $fqdn}
}
if ($PsBoundParameters.ContainsKey("id")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response
}
if ($PsBoundParameters.ContainsKey("status")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements
}
if ( -not $PsBoundParameters.ContainsKey("status") -and ( -not $PsBoundParameters.ContainsKey("id")) -and ( -not $PsBoundParameters.ContainsKey("fqdn"))) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements
}
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Get-VCFHost
Function Commission-VCFHost {
<#
.SYNOPSIS
Connects to the specified SDDC Manager and commissions a list of hosts.
.DESCRIPTION
The Commission-VCFHost cmdlet connects to the specified SDDC Manager
and commissions a list of hosts. Host list spec is provided in a JSON file.
.EXAMPLE
PS C:\> Commission-VCFHost -json .\Host\commissionHosts\commissionHostSpec.json
This example shows how to commission a list of hosts based on the details
provided in the JSON file.
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$json
)
if (!(Test-Path $json)) {
throw "JSON File Not Found"
}
else {
# Reads the commissionHostsJSON json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content -Raw $json)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
# Validate the provided JSON input specification file
$response = Validate-CommissionHostSpec -json $ConfigJson
# get the task id from the validation function
$taskId = $response.id
# keep checking until executionStatus is not IN_PROGRESS
do {
$uri = "https://$sddcManager/v1/hosts/validations/$taskId"
$response = Invoke-RestMethod -Method GET -URI $uri -Headers $headers -ContentType application/json
} While ($response.executionStatus -eq "IN_PROGRESS")
# Submit the commissiong job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDED
if ($response.executionStatus -eq "COMPLETED" -and $response.resultStatus -eq "SUCCEEDED") {
Try {
Write-Host ""
Write-Host "Task validation completed successfully, invoking host(s) commissioning on SDDC Manager" -ForegroundColor Green
$uri = "https://$sddcManager/v1/hosts/"
$response = Invoke-RestMethod -Method POST -URI $uri -headers $headers -ContentType application/json -body $ConfigJson
return $response
Write-Host ""
}
Catch {
#Get response from the exception
ResponseExeception
}
}
else {
Write-Host ""
Write-Host "The validation task commpleted the run with the following problems:" -ForegroundColor Yellow
Write-Host $response.validationChecks.errorResponse.message -ForegroundColor Yellow
Write-Host ""
}
}
}
Export-ModuleMember -Function Commission-VCFHost
Function Decommission-VCFHost {
<#
.SYNOPSIS
Connects to the specified SDDC Manager and decommissions a list of hosts.
Host list is provided in a JSON file.
.DESCRIPTION
The Decommission-VCFHost cmdlet connects to the specified SDDC Manager
and decommissions a list of hosts.
.EXAMPLE
PS C:\> Decommission-VCFHost -json .\Host\decommissionHostSpec.json
This example shows how to decommission a set of hosts based on the details
provided in the JSON file.
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$json
)
if (!(Test-Path $json)) {
throw "JSON File Not Found"
}
else {
# Reads the json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content -Raw $json)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/hosts"
try {
$response = Invoke-RestMethod -Method DELETE -URI $uri -headers $headers -ContentType application/json -body $ConfigJson
$response
}
catch {
#Get response from the exception
ResponseExeception
}
}
}
Export-ModuleMember -Function Decommission-VCFHost
Function Reset-VCFHost {
<#
.SYNOPSIS
Performs an ESXi host cleanup using the command line SoS utility
.DESCRIPTION
Performs a host cleanup using SoS option --cleanup-host. Valid options for the -dirtyHost parameter are: ALL, <MGMT ESXi IP>
Please note:The SoS utility on VCF 3.9 is unable to perform networking host cleanup when the host belongs to an NSX-T cluster.
This issue has been resolved on VCF 3.9.1
.EXAMPLE
Reset-VCFHost -privilegedUsername [email protected] -privilegedPassword "VMware1!" -sddcManagerRootPassword "VMware1!"-dirtyHost 192.168.210.53
This command will perform SoS host cleanup for host 192.168.210.53
.EXAMPLE
Reset-VCFHost -privilegedUsername [email protected] -privilegedPassword "VMware1!" -sddcManagerRootPassword "VMware1!" -dirtyHost all
This command will perform SoS host cleanup for all hosts in need of cleanup in the SDDC Manager database.
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String] $privilegedUsername,
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String] $privilegedPassword,
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String] $sddcManagerRootPassword,
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$dirtyHost
)
# get the full list of PSC credentials
$pscCreds = Get-VCFCredential -privilegedUsername $privilegedUsername -privilegedPassword $privilegedPassword -resourceType PSC
# from PSC credentials extract the SSO username and password
$ssoCreds = $pscCreds.elements | Where-Object {$_.credentialType -eq "SSO"}
# get the list of all VCENTER credentials
$vcCreds = Get-VCFCredential $privilegedUsername -privilegedPassword $privilegedPassword -resourceType VCENTER
# find out which VC is the MGMT. This is use to extract the MGMT VC FQDN ($mgmtVC.resourceName)
$mgmtVC = $vcCreds.elements.resource | Where-Object {$_.domainName -eq "MGMT"}
# connect to the management vCenter without displaying the connection
Connect-VIServer -Server $mgmtVC.resourceName -User $ssoCreds.username -Password $ssoCreds.password | Out-Null
# get the vm object for sddc-manager
$sddcManagerVM = Get-VM -Name "sddc-manager"
# the SoS help says to use ALL not sure if it's case sensitive but I'm converting upper case
if ($dirtyHost -eq "all") { $dirtyHost = "ALL" }
# build the cmd to run and auto confirm
$sshCommand = "echo Y | /opt/vmware/sddc-support/sos --cleanup-host " + $dirtyHost
Write-Host ""
Write-Host "Executing clean up for host(s): $dirtyHost - This might take a while, please wait..."
Write-Host ""
Try {
$vmScript = Invoke-VMScript -VM $sddcManagerVM -ScriptText $sshCommand -GuestUser root -GuestPassword $sddcManagerRootPassword
$vmScript
}
Catch {
ResponseExeception
}
}
Export-ModuleMember -Function Reset-VCFHost
######### End Host Operations ##########
######### Start Workload Domain Operations ##########
Function Get-VCFWorkloadDomain {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & retrieves a list of workload domains.
.DESCRIPTION
The Get-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager
& retrieves a list of workload domains.
.EXAMPLE
PS C:\> Get-VCFWorkloadDomain
This example shows how to get a list of Workload Domains
.EXAMPLE
PS C:\> Get-VCFWorkloadDomain -name WLD01
This example shows how to get a Workload Domain by name
.EXAMPLE
PS C:\> Get-VCFWorkloadDomain -id 8423f92e-e4b9-46e7-92f7-befce4755ba2
This example shows how to get a Workload Domain by id
#>
param (
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$name,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
if ($PsBoundParameters.ContainsKey("id")) {
$uri = "https://$sddcManager/v1/domains/$id"
}
if ($PsBoundParameters.ContainsKey("name")) {
$uri = "https://$sddcManager/v1/domains"
}
if ( -not $PsBoundParameters.ContainsKey("name") -and ( -not $PsBoundParameters.ContainsKey("id"))) {
$uri = "https://$sddcManager/v1/domains"
}
try {
if ($PsBoundParameters.ContainsKey("name")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.name -eq $name}
}
if ($PsBoundParameters.ContainsKey("id")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response
}
if ( -not $PsBoundParameters.ContainsKey("name") -and ( -not $PsBoundParameters.ContainsKey("id"))) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements
}
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Get-VCFWorkloadDomain
Function New-VCFWorkloadDomain {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & creates a workload domain.
.DESCRIPTION
The New-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager
& creates a workload domain.
.EXAMPLE
PS C:\> New-VCFWorkloadDomain -json .\WorkloadDomain\workloadDomainSpec.json
This example shows how to create a Workload Domain from a json spec
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$json
)
if (!(Test-Path $json)) {
Throw "JSON File Not Found"
}
else {
# Read the json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content $json)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
# Validate the provided JSON input specification file
$response = Validate-WorkloadDomainSpec -json $ConfigJson
# the validation API does not currently support polling with a task ID
Sleep 5
# Submit the job only if the JSON validation task completed with executionStatus=COMPLETED & resultStatus=SUCCEEDED
if ($response.executionStatus -eq "COMPLETED" -and $response.resultStatus -eq "SUCCEEDED") {
Try {
Write-Host ""
Write-Host "Task validation completed successfully, invoking Workload Domain Creation on SDDC Manager" -ForegroundColor Green
$uri = "https://$sddcManager/v1/domains"
$response = Invoke-RestMethod -Method POST -URI $uri -ContentType application/json -headers $headers -body $ConfigJson
return $response
Write-Host ""
return $response
Write-Host ""
}
catch {
#Get response from the exception
ResponseExeception
}
}
else {
Write-Host ""
Write-Host "The validation task commpleted the run with the following problems:" -ForegroundColor Yellow
Write-Host $response.validationChecks.errorResponse.message -ForegroundColor Yellow
Write-Host ""
}
}
}
Export-ModuleMember -Function New-VCFWorkloadDomain
Function Set-VCFWorkloadDomain {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & marks a workload domain for deletion.
.DESCRIPTION
Before a workload domain can be deleted it must first be marked for deletion.
The Set-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager
& marks a workload domain for deletion.
.EXAMPLE
PS C:\> Set-VCFWorkloadDomain -id fbdcf199-c086-43aa-9071-5d53b5c5b99d
This example shows how to mark a workload domain for deletion
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/domains/$id"
$body = '{"markForDeletion": true}'
try {
$response = Invoke-RestMethod -Method PATCH -URI $uri -ContentType application/json -headers $headers -body $body
# This API does not return a response
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Set-VCFWorkloadDomain
Function Remove-VCFWorkloadDomain {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & deletes a workload domain.
.DESCRIPTION
Before a workload domain can be deleted it must first be marked for deletion.
See Set-VCFWorkloadDomain
The Remove-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager
& deletes a workload domain.
.EXAMPLE
PS C:\> Remove-VCFWorkloadDomain -id fbdcf199-c086-43aa-9071-5d53b5c5b99d
This example shows how to delete a workload domain
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/domains/$id"
try {
$response = Invoke-RestMethod -Method DELETE -URI $uri -headers $headers
$response
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Remove-VCFWorkloadDomain
######### End Workload Domain Operations ##########
######### Start Cluster Operations ##########
Function Get-VCFCluster {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & retrieves a list of clusters.
.DESCRIPTION
The Get-VCFCluster cmdlet connects to the specified SDDC Manager
& retrieves a list of clusters.
.EXAMPLE
PS C:\> Get-VCFCluster
This example shows how to get a list of all clusters
.EXAMPLE
PS C:\> Get-VCFCluster -name wld01-cl01
This example shows how to get a cluster by name
.EXAMPLE
PS C:\> Get-VCFCluster -id 8423f92e-e4b9-46e7-92f7-befce4755ba2
This example shows how to get a cluster by id
#>
param (
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$name,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
if ($PsBoundParameters.ContainsKey("id")) {
$uri = "https://$sddcManager/v1/clusters/$id"
}
else {
$uri = "https://$sddcManager/v1/clusters"
}
try {
if ($PsBoundParameters.ContainsKey("name")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.name -eq $name}
}
if ($PsBoundParameters.ContainsKey("id")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.id -eq $id}
}
if ( -not $PsBoundParameters.ContainsKey("name") -and ( -not $PsBoundParameters.ContainsKey("id"))) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements
}
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Get-VCFCluster
Function New-VCFCluster {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & creates cluster.
.DESCRIPTION
The New-VCFCluster cmdlet connects to the specified SDDC Manager
& creates a cluster in a specified workload domains.
.EXAMPLE
PS C:\> New-VCFCluster -json .\WorkloadDomain\addClusterSpec.json
This example shows how to create a cluster in a Workload Domain from a json spec
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$json
)
if (!(Test-Path $json)) {
Throw "JSON File Not Found"
}
else {
# Read the json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content $json)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
# Validate the provided JSON input specification file
$response = Validate-VCFClusterSpec -json $ConfigJson
# the validation API does not currently support polling with a task ID
Sleep 5
# Submit the job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDED
if ($response.executionStatus -eq "COMPLETED" -and $response.resultStatus -eq "SUCCEEDED") {
Try {
Write-Host ""
Write-Host "Task validation completed successfully, invoking cluster task on SDDC Manager" -ForegroundColor Green
$uri = "https://$sddcManager/v1/clusters"
$response = Invoke-RestMethod -Method POST -URI $uri -ContentType application/json -headers $headers -body $ConfigJson
$response.elements
}
catch {
#Get response from the exception
ResponseExeception
}
}
else {
Write-Host ""
Write-Host "The validation task commpleted the run with the following problems:" -ForegroundColor Yellow
Write-Host $response.validationChecks.errorResponse.message -ForegroundColor Yellow
Write-Host ""
}
}
}
Export-ModuleMember -Function New-VCFCluster
Function Set-VCFCluster {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & expands or compacts a cluster.
.DESCRIPTION
The Set-VCFCluster cmdlet connects to the specified SDDC Manager
& expands or compacts a cluster by adding or removing a host(s). A cluster
can also be marked for deletion
.EXAMPLE
PS C:\> Set-VCFCluster -id a511b625-8eb8-417e-85f0-5b47ebb4c0f1
-json .\Cluster\clusterExpansionSpec.json
This example shows how to expand a cluster by adding a host(s)
.EXAMPLE
PS C:\> Set-VCFCluster -id a511b625-8eb8-417e-85f0-5b47ebb4c0f1
-json .\Cluster\clusterCompactionSpec.json
This example shows how to compact a cluster by removing a host(s)
.EXAMPLE
PS C:\> Set-VCFCluster -id a511b625-8eb8-417e-85f0-5b47ebb4c0f1
-markForDeletion
This example shows how to mark a cluster for deletion
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$id,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$json,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[switch]$markForDeletion
)
if ($PsBoundParameters.ContainsKey("json")) {
if (!(Test-Path $json)) {
Throw "JSON File Not Found"
}
else {
# Read the json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content $json)
}
}
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
try {
if ( -not $PsBoundParameters.ContainsKey("json") -and ( -not $PsBoundParameters.ContainsKey("markForDeletion"))) {
throw "You must include either -json or -markForDeletion"
}
if ($PsBoundParameters.ContainsKey("json")) {
# Validate the provided JSON input specification file
$response = Validate-VCFUpdateClusterSpec -clusterid $clusterid -json $ConfigJson
# the validation API does not currently support polling with a task ID
Sleep 5
# Submit the job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDED
if ($response.executionStatus -eq "COMPLETED" -and $response.resultStatus -eq "SUCCEEDED") {
Try {
Write-Host ""
Write-Host "Task validation completed successfully, invoking cluster task on SDDC Manager" -ForegroundColor Green
$uri = "https://$sddcManager/v1/clusters/$clusterid/"
$response = Invoke-RestMethod -Method PATCH -URI $uri -headers $headers -ContentType application/json -body $ConfigJson
return $response
Write-Host ""
}
Catch {
#Get response from the exception
ResponseExeception
}
}
else {
Write-Host ""
Write-Host "The validation task commpleted the run with the following problems:" -ForegroundColor Yellow
Write-Host $response.validationChecks.errorResponse.message -ForegroundColor Yellow
Write-Host ""
}
}
if ($PsBoundParameters.ContainsKey("markForDeletion")) {
$ConfigJson = '{"markForDeletion": true}'
$response = Invoke-RestMethod -Method PATCH -URI $uri -ContentType application/json -headers $headers -body $ConfigJson
}
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Set-VCFCluster
Function Remove-VCFCluster {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & deletes a cluster.
.DESCRIPTION
Before a cluster can be deleted it must first be marked for deletion. See Set-VCFCluster
The Remove-VCFCluster cmdlet connects to the specified SDDC Manager & deletes a cluster.
.EXAMPLE
PS C:\> Remove-VCFCluster -id a511b625-8eb8-417e-85f0-5b47ebb4c0f1
This example shows how to delete a cluster
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/clusters/$id"
try {
$response = Invoke-RestMethod -Method DELETE -URI $uri -headers $headers
#TODO: Parse the response
#$response.elements
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Remove-VCFCluster
######### End Cluster Operations ##########
######### Start Network Pool Operations ##########
Function Get-VCFNetworkPool {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & retrieves a list of Network Pools.
.DESCRIPTION
The Get-VCFNetworkPool cmdlet connects to the specified SDDC Manager
& retrieves a list of Network Pools.
.EXAMPLE
PS C:\> Get-VCFNetworkPool
This example shows how to get a list of all Network Pools
.EXAMPLE
PS C:\> Get-VCFNetworkPool -name sfo01-networkpool
This example shows how to get a Network Pool by name
.EXAMPLE
PS C:\> Get-VCFNetworkPool -id 40b0b36d-36d6-454c-814b-ba8bf9b383e3
This example shows how to get a Network Pool by id
#>
param (
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$name,
[Parameter (Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/network-pools"
try {
if ($PsBoundParameters.ContainsKey("name")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.name -eq $name}
}
if ($PsBoundParameters.ContainsKey("id")) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements | Where-Object {$_.id -eq $id}
}
if ( -not $PsBoundParameters.ContainsKey("name") -and ( -not $PsBoundParameters.ContainsKey("id"))) {
$response = Invoke-RestMethod -Method GET -URI $uri -headers $headers
$response.elements
}
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Get-VCFNetworkPool
Function New-VCFNetworkPool {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & creates a new Network Pool.
.DESCRIPTION
The New-VCFNetworkPool cmdlet connects to the specified SDDC Manager & creates a new Network Pool.
Network Pool spec is provided in a JSON file.
.EXAMPLE
PS C:\> New-VCFNetworkPool -json .\NetworkPool\createNetworkPoolSpec.json
This example shows how to create a Network Pool
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$json
)
if (!(Test-Path $json)) {
Throw "JSON File Not Found"
}
else {
# Read the json file contents into the $ConfigJson variable
$ConfigJson = (Get-Content $json)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/network-pools"
try {
$response = Invoke-RestMethod -Method POST -URI $uri -headers $headers -ContentType application/json -body $ConfigJson
# This API does not return a response body. Sending GET to validate the Network Pool creation was successful
$validate = $ConfigJson | ConvertFrom-Json
$poolName = $validate.name
Get-VCFNetworkPool -name $poolName
}
catch {
#Get response from the exception
ResponseExeception
}
}
}
Export-ModuleMember -Function New-VCFNetworkPool
Function Remove-VCFNetworkPool {
<#
.SYNOPSIS
Connects to the specified SDDC Manager & deletes a Network Pool.
.DESCRIPTION
The Remove-VCFNetworkPool cmdlet connects to the specified SDDC Manager & deletes a Network Pool.
.EXAMPLE
PS C:\> Remove-VCFNetworkPool -id 7ee7c7d2-5251-4bc9-9f91-4ee8d911511f
This example shows how to get a Network Pool by id
#>
param (
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$id
)
$headers = @{"Accept" = "application/json"}
$headers.Add("Authorization", "Basic $base64AuthInfo")
$uri = "https://$sddcManager/v1/network-pools/$id"
try {
# This API does not return a response
$response = Invoke-RestMethod -Method DELETE -URI $uri -headers $headers
}
catch {
#Get response from the exception
ResponseExeception
}
}
Export-ModuleMember -Function Remove-VCFNetworkPool
Function Get-VCFNetworkIPPool {
<#
.SYNOPSIS
Get a Network of a Network Pool
.DESCRIPTION
The Get-VCFNetworkIPPool cmdlet connects to the specified SDDC Manager and retrieves a list of the networks
configured for the provided network pool.
.EXAMPLE
PS C:\> Get-VCFNetworkIPPool -id 917bcf8f-93e8-4b84-9627-471899c05f52
This example shows how to get a list of all networks associated to the network pool based on the id provided
.EXAMPLE
PS C:\> Get-VCFNetworkIPPool -id 917bcf8f-93e8-4b84-9627-471899c05f52 -networkid c2197368-5b7c-4003-80e5-ff9d3caef795
This example shows how to get a list of details for a specific network associated to the network pool using ids
#>
param (
[Parameter (Mandatory=$true)]