Skip to content

Commit

Permalink
Fixinf few issues in the WLD Startup/Shutdown sequence. Refining Mess…
Browse files Browse the repository at this point in the history
…ages. Added TODOs
  • Loading branch information
joisika committed Jul 31, 2024
1 parent 1edc1f6 commit f65cf00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
36 changes: 23 additions & 13 deletions SampleScripts/PowerManagement-WorkloadDomain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ Try {
$nxtClusterEdgeNodes = @()
if ($statusOfNsxtClusterVMs -ne 'running') {
Write-PowerManagementLogMessage -Type WARNING -Message "The NSX Manager VMs have been stopped. The NSX Edge VMs will not be handled in an automatic way."
Write-PowerManagementLogMessage -Type WARNING -Message "The NSX Manager VMs have been stopped. We could not check if this NSX Manager is spanned across Workload Domains."
} else {
Try {
[Array]$nsxtEdgeNodes = Get-EdgeNodeFromNSXManager -server $nsxtMgrFQDN -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword -VCfqdn $vcServer.fqdn
Expand All @@ -394,21 +395,22 @@ Try {
} catch {
Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Unable to fetch NSX Edge node information from NSX Manager '$nsxtMgrFQDN'. Exiting!"
}

# This variable holds True of False based on if NSX is spanned across workloads or not.
$nsxtSpannedAcrossWldVc = Get-NSXTComputeManagers -server $nsxtMgrFQDN -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword
$NSXTSpannedAcrossWld = $nsxtSpannedAcrossWldVc.count -gt 1
}

$vcfVMs_string = $vcfVMs -join "; "

# This variable holds True of False based on if NSX is spanned across workloads or not.
$nsxtSpannedAcrossWldVc = Get-NSXTComputeManagers -server $nsxtMgrFQDN -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword
$NSXTSpannedAcrossWld = $nsxtSpannedAcrossWldVc.count -gt 1

# From here the looping of all clusters begin.
$count = $sddcClusterDetails.count
$index = 1
$DownCount = 0
$lastElement = $false


# TODO Add check if clusters are vSAN or not.
# TODO Add support for non-vSAN clusters.
foreach ($cluster in $clusterDetails) {
foreach ($clusterDetail in $sddcClusterDetails) {
if ($ClusterStatusMapping[$clusterDetail.name] -eq 'DOWN') {
Expand All @@ -425,13 +427,15 @@ Try {
Continue
}

Write-PowerManagementLogMessage -Type INFO -Message "Processing cluster '$($cluster.name)'..."

$esxiDetails = $esxiWorkloadCluster[$cluster.name]

# Check the SDDC Manager version if VCF >=4.5 or vcf4.5
$vcfVersion = Get-VCFManager | Select-Object version | Select-String -Pattern '\d+\.\d+' -AllMatches | ForEach-Object { $_.matches.groups[0].value }
if ([float]$vcfVersion -lt [float]4.5) {
# For versions prior VCF 4.5
# Check if SSH is enabled on the esxi hosts before proceeding with startup procedure
# Check if SSH is enabled on the esxi hosts before proceeding with shutdown procedure
Try {
foreach ($esxiNode in $esxiWorkloadDomain) {
if (Test-VsphereConnection -server $esxiNode) {
Expand Down Expand Up @@ -468,6 +472,7 @@ Try {

$clusterVcfVMs = @()
$clusterVclsVMs = @()
# TODO If not specific cluster is passed - we should check for customer VMs in all clusters. In this way we will fail early if there are some VMs running and not managed by VCF.
Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch information about all powered-on virtual machines for the specified vSphere cluster $($cluster.name)..."
[Array]$clusterAllVMs = Get-VMToClusterMapping -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -folder "VM" -powerstate "poweredon"
Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch information about all powered-on vCLS virtual machines for a the specified vSphere cluster $($cluster.name)..."
Expand Down Expand Up @@ -824,8 +829,10 @@ Try {
}
foreach ($cluster in $clusterDetails) {
$esxiDetails = $esxiWorkloadCluster[$cluster.name]
# We are starting all vCenter Servers, since we need to get NSX details. SDDC Manager needs VC connection to build this knowlage
Write-PowerManagementLogMessage -Type INFO -Message "Trying to see if all vCenter Servers in a workload domain are already started"
# TODO - Do not run this for each cluster - we need to run it once per WLD.
# We are starting all vCenter Servers, since we need to get NSX details. SDDC Manager needs VC connection to build this knowledge.
# NSX Manager should be started after the VC, so if NSX manager is spanned across WLDs, we need to start all VCs.
Write-PowerManagementLogMessage -Type INFO -Message "Checking if all vCenter Servers in all workload domains are started."
$serviceStatus = 0
foreach ($wldVC in $allWldVCs) {
$vcStarted = (Get-VMsWithPowerStatus -server $mgmtVcServer.fqdn -user $mgmtVcUser -pass $mgmtVcPass -powerstate "poweredon" -pattern $wldVC.Split(".")[0] -silence).count
Expand Down Expand Up @@ -876,6 +883,7 @@ Try {
Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server has been started successfully."
if ([float]$vcfVersion -gt [float]4.4) {
#Start ESXi hosts here
# TODO - Check if this workaround is needed for VCF 5.1 and newer.
Write-Host ""
$warningString = ""
if ($sddcClusterDetails.count -eq 1) {
Expand Down Expand Up @@ -917,9 +925,10 @@ Try {
# Check if Lockdown Mode is enabled on ESXi hosts
Test-LockdownMode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name
# Start vSAN Cluster wizard
# TODO - Add check if the cluster is vSAN or not.
Set-VsanClusterPowerStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -PowerStatus clusterPoweredOn

# Check if host are out of maintainence mode after cluster restart
# Check if host are out of maintenance mode after cluster restart
foreach ($esxiNode in $esxiDetails) {
$hostConnectionState = Get-MaintenanceMode -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password
if ($hostConnectionState -eq "Maintenance") {
Expand Down Expand Up @@ -954,9 +963,10 @@ Try {
}
}
# Workaround for IAM service not starting vCLS VMs
# TODO Check if this is still required for VCF 5.1 and newer. This workaround have an issue with Non vSAN Clusters.
foreach ($cluster in $clusterDetails) {
# Startup vSphere Cluster Services Virtual Machines in Virtual Infrastructure Workload Domain
Set-Retreatmode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode disable
Set-RetreatMode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode disable
Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS startup will take some time. Please wait! "
}

Expand Down Expand Up @@ -1082,18 +1092,18 @@ Try {
$vcfVMs_string = ($clusterVcfVMs | Select-Object -Unique) -join "; "

Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################"
Write-PowerManagementLogMessage -Type INFO -Message "The following components have been started: $vcfVMs_string , "
Write-PowerManagementLogMessage -Type INFO -Message "The following components have been started: $vcfVMs_string ."
if ([float]$vcfVersion -lt [float]4.5) {
Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability has been enabled by the script. Disable it per your environment's design."
}
Write-PowerManagementLogMessage -Type INFO -Message "Check the list above and start any additional VMs, that are required, before you proceed with workload startup!"
Write-PowerManagementLogMessage -Type INFO -Message "Use the following command to automatically start VMs"
Write-PowerManagementLogMessage -Type INFO -Message "Start-CloudComponent -server $($vcServer.fqdn) -user $vcUser -pass $vcPass -nodes <comma separated customer vms list> -timeout 600"
if ([float]$vcfVersion -lt [float]4.5) {
Write-PowerManagementLogMessage -Type INFO -Message "If you have enabled SSH for the ESXi hosts through SDDC manager, disable it at this point."
Write-PowerManagementLogMessage -Type WARNING -Message "If you have enabled SSH for the ESXi hosts through SDDC manager, disable it at this point."
}
if ([float]$vcfVersion -gt [float]4.4) {
Write-PowerManagementLogMessage -Type INFO -Message "If you have disabled lockdown mode for the ESXi hosts in workload cluster, you can enable it at this point."
Write-PowerManagementLogMessage -Type WARNING -Message "If you have disabled lockdown mode for the ESXi hosts in workload cluster, you can enable it at this point."
}
Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################"
Write-PowerManagementLogMessage -Type INFO -Message "End of startup sequence for the cluster '$($cluster.name)'!"
Expand Down
2 changes: 1 addition & 1 deletion VMware.CloudFoundation.PowerManagement.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ Function Get-MaintenanceMode {
}
Connect-VIServer -Server $server -Protocol https -User $user -Password $pass | Out-Null
if ($DefaultVIServer.Name -eq $server) {
Write-PowerManagementLogMessage -Type INFO -Message "Connected to server '$server' and attempting to $state maintenance mode..."
$hostStatus = (Get-VMHost -Server $server)
Write-PowerManagementLogMessage -Type INFO -Message "Connected to server '$server'. The connection status is '$($hostStatus.ConnectionState)'."
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null
return $hostStatus.ConnectionState
} else {
Expand Down

0 comments on commit f65cf00

Please sign in to comment.