-
Notifications
You must be signed in to change notification settings - Fork 609
Add PAIF-N automation example #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,344 @@ | ||
<# | ||
# © 2024 Broadcom. All Rights Reserved. Broadcom. The term "Broadcom" refers to | ||
# Broadcom Inc. and/or its subsidiaries. | ||
#> | ||
|
||
<# | ||
.SYNOPSIS | ||
|
||
This script deploys a VI workload domain | ||
|
||
.DESCRIPTION | ||
|
||
This script creates a VI workload domain using the PowerCLI SDK module for VCF SDDC Manager. | ||
|
||
The script can be broken into two main parts. First, the ESXi hosts are being commissioned. | ||
Then, the actual VI domain is created using the commissioned ESXi hosts. | ||
|
||
Both steps - ESXi host commissioning and VI domain creations - are three-stage operations themselves. | ||
The commissioning/creation specs are constructed. The specs are validated. The actual operation is invoked. | ||
The validation and operation invocation are long-running tasks. This requires awaiting and status tracking | ||
until their completion. The waiting for validation and the actual operation is done using helper cmdlets - | ||
Wait-VcfValidation and Wait-VcfTask, located in utils sub-folder. | ||
|
||
On completion a new VI workload domain reflecting the given parameters should be created. | ||
|
||
.NOTES | ||
|
||
Prerequisites: | ||
- A VCF Management Domain | ||
- A minimum of three free hosts marked with the appropriate storage and at least 4 NICs. | ||
Two of the NICs will be used for Frontend/Management and the other two for workloads. | ||
|
||
"Global parameters", "Host commissioning parameters", "Workload domain creation parameters" should be updated to | ||
reflect the environment they are run in. This may require altering the spec creation script. | ||
|
||
#> | ||
|
||
$ErrorActionPreference = 'Stop' | ||
$SCRIPTROOT = ($PWD.ProviderPath, $PSScriptRoot)[!!$PSScriptRoot] | ||
. (Join-Path $SCRIPTROOT 'utils/Wait-VcfTask.ps1') | ||
. (Join-Path $SCRIPTROOT 'utils/Wait-VcfValidation.ps1') | ||
|
||
# -------------------------------------------------------------------------------------------------------------------------- | ||
# Global parameters | ||
# -------------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Organization name of the workload domain | ||
$OrgName = 'VMware' | ||
|
||
# Name of the workload domain - used as a prefix for nested inventory items | ||
$domainName = 'sfo-w01' | ||
|
||
$domain = 'vrack.vsphere.local' | ||
$gateway = '10.0.0.250' | ||
$sddcManager = @{ | ||
Fqdn = "sddc-manager.$domain" | ||
User = 'administrator@vsphere.local' | ||
Password = 'VMware123!' | ||
} | ||
|
||
############################################################################################################################ | ||
# Host commissioning | ||
############################################################################################################################ | ||
|
||
# -------------------------------------------------------------------------------------------------------------------------- | ||
# Host commissioning parameters | ||
|
||
$esxiHosts = @( | ||
@{ | ||
Fqdn = "esxi-5.$domain" | ||
Username = 'root' | ||
Password = "ESXiSddc123!" | ||
StorageType = "VSAN" | ||
LicenseKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' | ||
} | ||
@{ | ||
Fqdn = "esxi-6.$domain" | ||
Username = 'root' | ||
Password = "ESXiSddc123!" | ||
StorageType = "VSAN" | ||
LicenseKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' | ||
} | ||
@{ | ||
Fqdn = "esxi-7.$domain" | ||
Username = 'root' | ||
Password = "ESXiSddc123!" | ||
StorageType = "VSAN" | ||
LicenseKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' | ||
} | ||
@{ | ||
Fqdn = "esxi-8.$domain" | ||
Username = 'root' | ||
Password = "ESXiSddc123!" | ||
StorageType = "VSAN" | ||
LicenseKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' | ||
} | ||
) | ||
|
||
# The network pool to associate the host with | ||
$networkPoolName = 'networkpool' | ||
lyuboasenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# -------------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Connect to SDDC manager | ||
$sddcConn = Connect-VcfSddcManagerServer ` | ||
-Server $sddcManager.Fqdn ` | ||
-User $sddcManager.User ` | ||
-Password $sddcManager.Password | ||
|
||
## Host commissioning spec construction | ||
$NetworkPool = Invoke-VcfGetNetworkPool | ` | ||
Select-Object -ExpandProperty Elements | ` | ||
Where-Object { $_.Name -eq $NetworkPoolName } | ||
|
||
$hostCommissionSpecs = $esxiHosts | % { | ||
Initialize-VcfHostCommissionSpec -Fqdn $_.Fqdn ` | ||
-NetworkPoolId $NetworkPool.Id ` | ||
-Password $_.Password ` | ||
-StorageType $_.StorageType ` | ||
-Username $_.Username | ||
} | ||
|
||
## Host commissioning validation | ||
$hostValidationResult = Invoke-VcfValidateHostCommissionSpec -HostCommissionSpecs $hostCommissionSpecs | ||
$hostValidationResult = Wait-VcfValidation ` | ||
-Validation $hostValidationResult ` | ||
-UpdateValidation { param($id) Invoke-VcfGetHostCommissionValidationByID -id $id } ` | ||
-UpdateValidationArguments $hostValidationResult.Id ` | ||
-ThrowOnError | ||
|
||
## Host commissioning | ||
$commisionTask = Invoke-VcfCommissionHosts -hostCommissionSpecs $hostCommissionSpecs | ||
$commisionTask = Wait-VcfTask $commisionTask -ThrowOnError | ||
|
||
|
||
############################################################################################################################ | ||
# Workload domain creation | ||
############################################################################################################################ | ||
|
||
# -------------------------------------------------------------------------------------------------------------------------- | ||
# Workload domain creation parameters | ||
|
||
$domainSpec = @{ | ||
DomainName = $DomainName | ||
OrgName = $OrgName | ||
VCenterSpec = @{ | ||
Name = "$DomainName-vc01" | ||
DatacenterName = "$DomainName-dc01" | ||
RootPassword = "VMware123!" | ||
NetworkDetailsSpec = @{ | ||
DnsName = "$DomainName-vc01.$domain" | ||
IpAddress = "10.0.0.40" | ||
SubnetMask = "255.255.255.0" | ||
Gateway = $gateway | ||
} | ||
} | ||
ComputeSpec = @{ | ||
ClusterSpecs = @( | ||
@{ | ||
DatastoreSpec = @{ | ||
VSanDatastoreSpec = @{ | ||
DatastoreName = "$DomainName-ds01" | ||
FailuresToTolerate = 1 | ||
LicenseKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" | ||
} | ||
} | ||
NetworkSpec = @{ | ||
VdsSpecs = @( | ||
@{ | ||
Name = "$DomainName-vds01" | ||
PortGroups = @( | ||
@{ | ||
Name = 'vSAN' | ||
TransportType = 'VSAN' | ||
} | ||
@{ | ||
Name = 'management' | ||
TransportType = 'MANAGEMENT' | ||
} | ||
@{ | ||
Name = 'vmotion' | ||
TransportType = 'VMOTION' | ||
} | ||
) | ||
} | ||
@{ | ||
Name = "$DomainName-vds02" | ||
IsUsedByNsxt = $true | ||
} | ||
) | ||
NsxClusterSpec = @{ | ||
NsxTClusterSpec = @{ | ||
GeneveVlanId = 0 | ||
} | ||
} | ||
} | ||
Name = "$DomainName-cl01" | ||
} | ||
) | ||
} | ||
NsxTSpec = @{ | ||
NsxManagerSpecs = @( | ||
@{ | ||
Name = "$domainName-nsx01a" | ||
NetworkDetailsSpec = @{ | ||
DnsName = "$domainName-nsx01a.$domain" | ||
IpAddress = "10.0.0.41" | ||
SubnetMask = "255.255.255.0" | ||
Gateway = $gateway | ||
} | ||
} | ||
@{ | ||
Name = "$domainName-nsx01b" | ||
NetworkDetailsSpec = @{ | ||
DnsName = "$domainName-nsx01b.$domain" | ||
IpAddress = "10.0.0.42" | ||
SubnetMask = "255.255.255.0" | ||
Gateway = $gateway | ||
} | ||
} | ||
@{ | ||
Name = "$domainName-nsx01c" | ||
NetworkDetailsSpec = @{ | ||
DnsName = "$domainName-nsx01c.$domain" | ||
IpAddress = "10.0.0.43" | ||
SubnetMask = "255.255.255.0" | ||
Gateway = $gateway | ||
} | ||
} | ||
) | ||
FormFactor = 'large' | ||
LicenseKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' | ||
NSXManagerAdminPassword = "VMware123!123" | ||
Vip = '10.0.0.44' | ||
VipFqdn = "$domainName-nsx01.$domain" | ||
} | ||
} | ||
# -------------------------------------------------------------------------------------------------------------------------- | ||
|
||
## Workload domain spec construction | ||
$esxiFqdns = $esxiHosts | Select-Object -ExpandProperty Fqdn | ||
$VcfHost = Invoke-VcfGetHosts -status "UNASSIGNED_USEABLE" | ` | ||
Select-Object -ExpandProperty Elements | ` | ||
Where-Object { $esxiFqdns -contains $_.Fqdn } | ||
|
||
$ComputeSpec = Initialize-VcfComputeSpec -ClusterSpecs ( | ||
$domainSpec.ComputeSpec.ClusterSpecs | ForEach-Object { | ||
$_clusterSpec = $_ | ||
|
||
Initialize-VcfClusterSpec ` | ||
-DatastoreSpec ( | ||
Initialize-VcfDatastoreSpec ` | ||
-VsanDatastoreSpec ( | ||
Initialize-VcfVsanDatastoreSpec ` | ||
-DatastoreName $_.DatastoreSpec.VSanDatastoreSpec.DatastoreName ` | ||
-FailuresToTolerate $_.DatastoreSpec.VSanDatastoreSpec.FailuresToTolerate ` | ||
-LicenseKey $_.DatastoreSpec.VSanDatastoreSpec.LicenseKey | ||
)) ` | ||
-HostSpecs ( | ||
$VcfHost | ForEach-Object { | ||
$esxiHost = $esxiHosts | Where-Object { $_.Fqdn -eq $_.Fqdn } | Select-Object -First 1 | ||
|
||
Initialize-VcfHostSpec ` | ||
-Id $_.Id ` | ||
-LicenseKey $esxiHost.LicenseKey ` | ||
-HostNetworkSpec ( | ||
Initialize-VcfHostNetworkSpec -VmNics @( | ||
lyuboasenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Initialize-VcfVmNic -Id 'vmnic0' -VdsName $_clusterSpec.NetworkSpec.VdsSpecs[0].Name | ||
Initialize-VcfVmNic -Id 'vmnic1' -VdsName $_clusterSpec.NetworkSpec.VdsSpecs[0].Name | ||
Initialize-VcfVmNic -Id 'vmnic2' -VdsName $_clusterSpec.NetworkSpec.VdsSpecs[1].Name | ||
Initialize-VcfVmNic -Id 'vmnic3' -VdsName $_clusterSpec.NetworkSpec.VdsSpecs[1].Name | ||
)) | ||
} | ||
) ` | ||
-Name $_.Name ` | ||
-NetworkSpec ( | ||
Initialize-VcfNetworkSpec ` | ||
-NsxClusterSpec ( | ||
Initialize-VcfNsxClusterSpec -NsxTClusterSpec ( | ||
Initialize-VcfNsxTClusterSpec ` | ||
-GeneveVlanId $_.NetworkSpec.NsxClusterSpec.NsxTClusterSpec.GeneveVlanId | ||
) | ||
) ` | ||
-VdsSpecs @( | ||
Initialize-VcfVdsSpec -Name $_.NetworkSpec.VdsSpecs[0].Name ` | ||
lyuboasenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-PortGroupSpecs ( | ||
$_.NetworkSpec.VdsSpecs[0].PortGroups | ForEach-Object { | ||
Initialize-VcfPortgroupSpec ` | ||
-Name $_.Name ` | ||
-TransportType $_.TransportType | ||
}) | ||
Initialize-VcfVdsSpec -Name $_.NetworkSpec.VdsSpecs[1].Name ` | ||
-IsUsedByNsxt $_.NetworkSpec.VdsSpecs[1].IsUsedByNsxt | ||
lyuboasenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)) | ||
}) | ||
|
||
|
||
$DomainCreationSpec = Initialize-VcfDomainCreationSpec ` | ||
-ComputeSpec $ComputeSpec ` | ||
-DomainName $domainSpec.DomainName ` | ||
-NsxTSpec ( | ||
Initialize-VcfNsxTSpec ` | ||
-FormFactor $domainSpec.NsxTSpec.FormFactor ` | ||
-LicenseKey $domainSpec.NsxTSpec.LicenseKey ` | ||
-NsxManagerAdminPassword $domainSpec.NsxTSpec.NSXManagerAdminPassword ` | ||
-NsxManagerSpecs ( | ||
$domainSpec.NsxTSpec.NsxManagerSpecs | ForEach-Object { | ||
Initialize-VcfNsxManagerSpec ` | ||
-Name $_.Name ` | ||
-NetworkDetailsSpec ( | ||
Initialize-VcfNetworkDetailsSpec ` | ||
-DnsName $_.NetworkDetailsSpec.DnsName ` | ||
-IpAddress $_.NetworkDetailsSpec.IpAddress ` | ||
-SubnetMask $_.NetworkDetailsSpec.SubnetMask ` | ||
-Gateway $_.NetworkDetailsSpec.Gateway) | ||
} | ||
) ` | ||
-Vip $domainSpec.NsxTSpec.Vip ` | ||
-VipFqdn $domainSpec.NsxTSpec.VipFqdn) ` | ||
-OrgName $domainSpec.OrgName ` | ||
-VcenterSpec ( | ||
Initialize-VcfVcenterSpec ` | ||
-DatacenterName $domainSpec.VCenterSpec.DatacenterName ` | ||
-Name $domainSpec.VCenterSpec.Name ` | ||
-NetworkDetailsSpec ( | ||
Initialize-VcfNetworkDetailsSpec ` | ||
-DnsName $domainSpec.VCenterSpec.NetworkDetailsSpec.DnsName ` | ||
-IpAddress $domainSpec.VCenterSpec.NetworkDetailsSpec.IpAddress ` | ||
-SubnetMask $domainSpec.VCenterSpec.NetworkDetailsSpec.SubnetMask ` | ||
-Gateway $domainSpec.VCenterSpec.NetworkDetailsSpec.Gateway | ||
) ` | ||
-RootPassword $domainSpec.VCenterSpec.RootPassword) | ||
|
||
# Workload domain spec validation | ||
$domainValidationResult = Invoke-VcfValidateDomainCreationSpec -domainCreationSpec $DomainCreationSpec | ||
$domainValidationResult = Wait-VcfValidation ` | ||
-Validation $domainValidationResult ` | ||
-ThrowOnError | ||
|
||
# Workload domain creation | ||
$creationTask = Invoke-VcfCreateDomain -domainCreationSpec $DomainCreationSpec | ||
$creationTask = Wait-VcfTask $creationTask -ThrowOnError | ||
|
||
Disconnect-VcfSddcManagerServer $sddcConn |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.