Skip to content

Commit

Permalink
fix: stabilizaiton fixes (#110)
Browse files Browse the repository at this point in the history
fix: stabilizaiton fixes

 - Fixed issues in the WLD Startup/Shutdown sequence.
 - Polished messages.
 - Added TODOs
 - Removed unused code
 - Implemented various fixes: variable reuse, log file generation, remove wrong "multi-cluster" implementation
 - Updated changelog, dependencies, documentation

Signed-off-by: Ivaylo Ivanov <[email protected]>
  • Loading branch information
joisika authored Aug 27, 2024
1 parent 1b48c6e commit 224da33
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ Bugfix:
- Added support to `PowerManagement-ManagmentDomain.ps1` and `PowerManagement-WorkloadDomain.ps1` for vSAN File Services to be excluded from customer virtual machines. [GH-95](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/95)
- Added exit to Tanzu Code in `PowerManagement-WorkloadDomain.ps1`[GH-97](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/97)
- Added support to `PowerManagement-ManagmentDomain.ps1` and `PowerManagement-WorkloadDomain.ps1` for testing ESXi host connection before SSH connection. [GH-98](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/98)
- Fix for issue [#101](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/issues/101)[GH-106](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/106)
- Fix for issue [#104](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/issues/104)[GH-106](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/106)

Enhancement:

- Added check for VMware Aria Operations for Logs deployment and shutdown if it exists. [GH-87](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/87)
- Added check to verify if workload domain vCenter Server instances are still powered on before starting the shutdown of the management domain to `PowerManagement-ManagmentDomain.ps1`. [GH-90](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/90)
- Added check for virtual machines running on an NSX overlay segment to `PowerManagement-ManagmentDomain.ps1`. [GH-86](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/86)
- Added support for more than one cluster in management domain for shut down and start up to `PowerManagement-ManagmentDomain.ps1`. [GH-93](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/93)
- Various improvements in workflows, log messages, file syntax. [GH-106](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/106) and [GH-107](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/107)

Refactor:

- Replaced the use of `Test-NetConnection` with `Test-EndpointConnection` from the PowerShell module dependency `PowerValidatedSolutions`. [GH-85](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/85)
- Updated `PowerManagement-ManagmentDomain.ps1` to allow for FQDN or IP address of SDDC Manager. [GH-92](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/92)
- Removed obsolete and not used code in the sample scripts.
- Apply common formatting for the files. [GH-107](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/107)

Chore:

- Updated `PowerVCF` from v2.3.0 to v2.4.0. [GH-85](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/85)
- Updated `PowerVCF` from v2.3.0 to v2.4.1. [GH-108](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/108)
- Added `PowerValidatedSolutions` v2.8.0 as a PowerShell module dependency. [GH-38](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/38)
- Updated `PowerValidatedSolutions` from v2.8.0 to 2.11.0. [GH-108](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/108)
- Updated `Write-PowerManagementLogMessage` to set color for message types. This will allow for all references to use color based on function. [GH-89](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/89)

## v1.4.0
Expand Down
49 changes: 26 additions & 23 deletions SampleScripts/PowerManagement-ManagementDomain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ Function Get-Password {

#EndRegion Non Exported Functions ######
##########################################################################

$pass = Get-Password -User $user -Password $pass
if(($PSBoundParameters.ContainsKey("shutdown") -or $PSBoundParameters.ContainsKey("genJson"))) {
$pass = Get-Password -User $user -Password $pass
}

# Error Handling (script scope function)
Function Debug-CatchWriterForPowerManagement {
Expand Down Expand Up @@ -157,10 +158,6 @@ Try {
Exit
}

# Temp workaround for a "$pass" variable reuse in the script
# TODO - fix usage of "pass" variable in the script
$sddcManagerPassword = $pass

# Shutdown procedure and json generation
if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKey("genjson")) {
Try {
Expand Down Expand Up @@ -361,7 +358,6 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe

$cluster = Get-VCFCluster | Where-Object { $_.id -eq ($workloadDomain.clusters.id) }

>>>(bug:Missing command)
$var = @{}
$var["Domain"] = @{}
$var["Domain"]["name"] = $workloadDomain.name
Expand Down Expand Up @@ -435,13 +431,13 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
$esxi_block["name"] = $esxDetails.name
$esxi_block["fqdn"] = $esxDetails.fqdn
$esxi_block["user"] = $esxDetails.username
$Pass = $esxDetails.password
if ($Pass) {
$PassEncrypted = $Pass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
$esxiPass = $esxDetails.password
if ($esxiPass) {
$esxiPassEncrypted = $esxiPass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
} else {
$PassEncrypted = $null
$esxiPassEncrypted = $null
}
$esxi_block["password"] = $Pass_encrypted
$esxi_block["password"] = $esxiPassEncrypted
$var["Hosts"] += $esxi_block
}

Expand All @@ -458,10 +454,14 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
}
$nsxtManagerVIP | Add-Member -Type NoteProperty -Name adminPassword -Value $nsxmgrPass
$nsxtNodesFQDN = $nsxtCluster.nodes.fqdn
$nsxtManagerVIP | Add-Member -Type NoteProperty -Name adminPassword -Value $nsxmgrPass
$nsxtNodesFQDN = $nsxtCluster.nodes.fqdn
$nsxtNodes = @()
foreach ($node in $nsxtNodesFQDN) {
foreach ($node in $nsxtNodesFQDN) {
[Array]$nsxtNodes += $node.Split(".")[0]
[Array]$vcfVMs += $node.Split(".")[0]
[Array]$vcfVMs += $node.Split(".")[0]
}
$var["NsxtManager"] = @{}
$var["NsxtManager"]["vipfqdn"] = $nsxtManagerFQDN
Expand All @@ -471,6 +471,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe

# Gather NSX-T Edge Node Details
$nsxtManagerPowerOnVMs = 0
$nsxtManagerPowerOnVMs = 0
foreach ($nsxtManager in $nsxtNodes) {
$state = Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -pattern $nsxtManager -exactMatch -silence
if ($state) { $nsxtManagerPowerOnVMs += 1 }
Expand All @@ -483,12 +484,11 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager VMs have been stopped. NSX Edge VMs will not be handled automatically."
} else {
Try {
Write-Output "adminpssword: $nsxtManagerVIP.adminPassword"
Write-PowerManagementLogMessage -Type INFO -Message "NSX Manager VMs are in running state. Trying to fetch information about the NSX Edge VMs..."
[Array]$edgeNodes = (Get-EdgeNodeFromNSXManager -server $nsxtManagerFQDN -user $nsxtManagerVIP.adminUser -pass $nsxtManagerVIP.adminPassword -VCfqdn $VcServer.fqdn)
$edgeNodesToString = $edgeNodes -join ","
Write-PowerManagementLogMessage -Type INFO -Message "The NSX Edge VMs are $edgeNodesToString."
} Catch {
} catch {
Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Cannot fetch NSX Edge nodes information from NSX Manager '$nsxtManagerFQDN'. Exiting!"
}
}
Expand Down Expand Up @@ -593,8 +593,6 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
}

if (Test-VCFConnection -server $server) {
# TODO - remove this temp fix for multiple useage of "$pass"
$pass = $sddcManagerPassword
if (Test-VCFAuthentication -server $server -user $user -pass $pass) {
$allWorkloadvCenters = @()
$allWorkloadvCenters = (Get-VCFWorkloadDomain | Select-Object type -ExpandProperty vcenters | Where-Object { $_.type -eq "VI" }).fqdn
Expand Down Expand Up @@ -634,8 +632,8 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
}

Write-PowerManagementLogMessage -Type INFO -Message "Fetching all powered on vSAN File Services virtual machines from vCenter Server instance $($vcenter)..."
[Array]$vsanfsvms += Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -pattern "(vSAN File)" -silence
foreach ($vm in $vsanfsvms) {
[Array]$vsanFsVMs += Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -pattern "(vSAN File)" -silence
foreach ($vm in $vsanFsVMs) {
[Array]$vcfVMs += $vm
}

Expand Down Expand Up @@ -740,9 +738,12 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
foreach ($segment in $nsx_segments) {
$segmentName = $segment.display_name
$cloudVMs = Get-VM | Get-NetworkAdapter | Where-Object { $_.NetworkName -eq $segmentName } | Select-Object Parent
$cloudVMs = Get-VM | Get-NetworkAdapter | Where-Object { $_.NetworkName -eq $segmentName } | Select-Object Parent
}
$vmList = $cloudVMs.Parent
$vmList = $cloudVMs.Parent
$stopExecuted = $false
foreach ($vm in $vmList) {
foreach ($vm in $vmList) {
$vmName = $vm.Name
$powerState = $vm.PowerState
Expand Down Expand Up @@ -924,13 +925,14 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe

$counter = 0
$sleepTime = 60 # in seconds

while ($counter -lt 1800) {
$maxSecondsToWait = 1800 # 30 minutes
#TODO - Add better reporting which hosts are still up
while ($counter -lt $maxSecondsToWait) {
$successCount = 0
#Verify if all ESXi hosts are down in here to conclude End of Shutdown sequence
foreach ($esxiNode in $esxiWorkloadDomain) {
if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) {
Write-PowerManagementLogMessage -Type WARNING -Message "Some hosts are still up. Sleeping for 60 seconds before next check..."
Write-PowerManagementLogMessage -Type WARNING -Message "Some hosts are still up. '$($esxiNode.fqdn)' responded. Sleeping for 60 seconds before next check..."
break
} else {
$successCount++
Expand Down Expand Up @@ -1206,6 +1208,7 @@ if ($PsBoundParameters.ContainsKey("startup")) {

#Startup the SDDC Manager Virtual Machine in the Management Workload Domain
Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $sddcmVMName -timeout 600
# TODO - Add check for SDDC Manager status

# Startup the NSX Manager Nodes in the Management Workload Domain
Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtNodes -timeout 600
Expand Down Expand Up @@ -1371,10 +1374,10 @@ if ($PsBoundParameters.ContainsKey("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 in management domain, disable it at this point."
Write-PowerManagementLogMessage -Type WARNING -Message "If you have enabled SSH for the ESXi hosts in management domain, 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 management domain, enable it back at this point."
Write-PowerManagementLogMessage -Type WARNING -Message "If you have disabled lockdown mode for the ESXi hosts in management domain, enable it back at this point."
}
Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################"
Write-PowerManagementLogMessage -Type INFO -Message "End of the startup sequence!"
Expand Down
12 changes: 6 additions & 6 deletions VMware.CloudFoundation.PowerManagement.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

# Module manifest for module 'VMware.CloudFoundation.PowerManagement'
# Generated by: Broadcom
# Generated on: 2024-04-04
# Generated on: 2024-08-27

@{

# Script module or binary module file associated with this manifest.
RootModule = 'VMware.CloudFoundation.PowerManagement.psm1'

# Version number of this module.
ModuleVersion = '1.4.1.1010'
ModuleVersion = '1.4.1.1011'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -32,7 +32,7 @@
Description = 'PowerShell Module for VMware Cloud Foundation Power Management'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '7.2.0'
PowerShellVersion = '7.4.0'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
Expand All @@ -53,19 +53,19 @@
RequiredModules = @(
@{
ModuleName = 'VMware.PowerCLI'
ModuleVersion = '12.5.0'
ModuleVersion = '13.3.0'
}
@{
ModuleName = 'Posh-SSH'
ModuleVersion = '3.0.8'
}
@{
ModuleName = 'PowerVCF'
ModuleVersion = '2.4.0'
ModuleVersion = '2.4.1'
}
@{
ModuleName = 'PowerValidatedSolutions'
ModuleVersion = '2.8.0'
ModuleVersion = '2.11.0'
}
)

Expand Down
8 changes: 5 additions & 3 deletions VMware.CloudFoundation.PowerManagement.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ Function Set-VsanClusterPowerStatus {

$cluster = Get-Cluster $clustername


# TODO - Add check if there is task ID returned
$powerActionTask = $vsanClusterPowerSystem.PerformClusterPowerAction($cluster.ExtensionData.MoRef, $spec)
$task = Get-Task -Id $powerActionTask
$counter = 0
Expand Down Expand Up @@ -2211,7 +2211,6 @@ Function Get-EdgeNodeFromNSXManager {
} else {
Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check the console output for more details."
}

} else {
Write-PowerManagementLogMessage -Type ERROR -Message "Connection to '$server' has failed. Check your environment and try again"
}
Expand Down Expand Up @@ -2423,10 +2422,13 @@ Function Write-PowerManagementLogMessage {
} else {
Write-Host -ForegroundColor $colour " $type $message"
}
$logContent = '[' + $timeStamp + '] ' + $type + ' ' + $message

if ($type -match "ERROR") {
Write-Error -Message $Message
}

$logContent = '[' + $timeStamp + '] ' + $type + ' ' + $message
Add-Content -Path $logFile $logContent
}
Export-ModuleMember -Function Write-PowerManagementLogMessage

Expand Down
6 changes: 1 addition & 5 deletions docs/snippets/import-module-local-linux.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
Import-Module -Name VMware.PowerCLI
Import-Module -Name PowerVCF
Import-Module -Name PowerValidatedSolutions
Import-Module -Name Posh-SSH
Import-Module -Name VMware.CloudFoundation.PowerManagement
Import-Module -Name VMware.CloudFoundation.PowerManagement
4 changes: 0 additions & 4 deletions docs/snippets/import-module.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
Import-Module -Name VMware.PowerCLI
Import-Module -Name PowerVCF
Import-Module -Name PowerValidatedSolutions
Import-Module -Name Posh-SSH
Import-Module -Name VMware.CloudFoundation.PowerManagement
6 changes: 3 additions & 3 deletions docs/snippets/install-module.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name VMware.PowerCLI -MinimumVersion 13.1.0 -Repository PSGallery
Install-Module -Name PowerVCF -MinimumVersion 2.4.0 -Repository PSGallery
Install-Module -Name PowerValidatedSolutions -MinimumVersion 2.8.0 -Repository PSGallery
Install-Module -Name VMware.PowerCLI -MinimumVersion 13.3.0 -Repository PSGallery
Install-Module -Name PowerVCF -MinimumVersion 2.4.1 -Repository PSGallery
Install-Module -Name PowerValidatedSolutions -MinimumVersion 2.11.0 -Repository PSGallery
Install-Module -Name Posh-SSH -MinimumVersion 3.0.8 -Repository PSGallery
Install-Module -Name VMware.CloudFoundation.PowerManagement -Repository PSGallery
6 changes: 3 additions & 3 deletions docs/snippets/save-module-local-linux.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Save-Module -Name VMware.PowerCLI -MinimumVersion 13.1.0 -Path /home/modules -Repository PSGallery
Save-Module -Name PowerVCF -MinimumVersion 2.4.0 -Path /home/modules -Repository PSGallery
Save-Module -Name PowerValidatedSolutions -MinimumVersion 2.8.0 -Path /home/modules -Repository PSGallery
Save-Module -Name VMware.PowerCLI -MinimumVersion 13.3.0 -Path /home/modules -Repository PSGallery
Save-Module -Name PowerVCF -MinimumVersion 2.4.1 -Path /home/modules -Repository PSGallery
Save-Module -Name PowerValidatedSolutions -MinimumVersion 2.11.0 -Path /home/modules -Repository PSGallery
Save-Module -Name Posh-SSH -MinimumVersion 3.0.8 -Path /home/modules -Repository PSGallery
Save-Module -Name VMware.CloudFoundation.PowerManagement -Path /home/modules -Repository PSGallery
6 changes: 3 additions & 3 deletions docs/snippets/save-module-local-windows.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Save-Module -Name VMware.PowerCLI -MinimumVersion 13.1.0 -Path F:\Module\ -Repository PSGallery
Save-Module -Name PowerVCF -MinimumVersion 2.4.0 -Path F:\Module\ -Repository PSGallery
Save-Module -Name PowerValidatedSolutions -MinimumVersion 2.8.0 -Path F:\Module\ -Repository PSGallery
Save-Module -Name VMware.PowerCLI -MinimumVersion 13.3.0 -Path F:\Module\ -Repository PSGallery
Save-Module -Name PowerVCF -MinimumVersion 2.4.1 -Path F:\Module\ -Repository PSGallery
Save-Module -Name PowerValidatedSolutions -MinimumVersion 2.11.0 -Path F:\Module\ -Repository PSGallery
Save-Module -Name Posh-SSH -MinimumVersion 3.0.8 -Path F:\Module\ -Repository PSGallery
Save-Module -Name VMware.CloudFoundation.PowerManagement -Path F:\Module\ -Repository PSGallery

0 comments on commit 224da33

Please sign in to comment.