Skip to content

Commit

Permalink
Code Stabilizaiton and various fixes
Browse files Browse the repository at this point in the history
Making "-Type" for log messages the default formatting
Fix few issues in the WLD Startup/Shutdown sequence. Refining Messages. Added TODOs
Remove unused code and minor fixes
Fixes for: variable reuse, log file generation, remove wrong "multi-cluster" implementation
Updating changelog and dependencies

Signed-off-by: Ivaylo Ivanov <iivanov@vmware.com>
  • Loading branch information
joisika committed Aug 26, 2024
1 parent 1b48c6e commit 4c47d19
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 406 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
389 changes: 25 additions & 364 deletions SampleScripts/PowerManagement-ManagementDomain.ps1

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions VMware.CloudFoundation.PowerManagement.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'VMware.CloudFoundation.PowerManagement.psm1'

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

# 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
33 changes: 18 additions & 15 deletions VMware.CloudFoundation.PowerManagement.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ Function Set-VsanClusterPowerStatus {
.PARAMETER pass
The password to authenticate to vCenter Server.
.PARAMETER clustername
.PARAMETER clusterName
The name of the vSAN cluster on which the power settings are to be applied.
.PARAMETER mgmt
Expand All @@ -623,9 +623,9 @@ Function Set-VsanClusterPowerStatus {
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user,
[Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$pass,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$clustername,
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$clusterName,
[Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$mgmt,
[Parameter (Mandatory = $true)] [ValidateSet("clusterPoweredOff", "clusterPoweredOn")] [String]$PowerStatus
[Parameter (Mandatory = $true)] [ValidateSet("clusterPoweredOff", "clusterPoweredOn")] [String]$powerStatus
)

$pass = Get-Password -User $user -Password $pass
Expand All @@ -650,38 +650,38 @@ Function Set-VsanClusterPowerStatus {
$spec = [VMware.Vsan.Views.PerformClusterPowerActionSpec]::new()

$spec.powerOffReason = "Shutdown through VMware Cloud Foundation script"
$spec.targetPowerStatus = $PowerStatus

$cluster = Get-Cluster $clustername
$spec.targetPowerStatus = $powerStatus

$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
$sleepTime = 10 # in seconds
$sleepTime = 30 # in seconds
if (-Not $mgmt) {
do {
$task = Get-Task -Id $powerActionTask
if (-Not ($task.State -EQ "Error")) {
Write-PowerManagementLogMessage -Type INFO -Message "$PowerStatus task is $($task.PercentComplete)% completed."
Write-PowerManagementLogMessage -Type INFO -Message "$powerStatus task is $($task.PercentComplete)% completed."
}
Start-Sleep -s $sleepTime
$counter += $sleepTime
} while ($task.State -EQ "Running" -and ($counter -lt 1800))

if ($task.State -EQ "Error") {
if ($task.ExtensionData.Info.Error.Fault.FaultMessage -like "VMware.Vim.LocalizableMessage") {
Write-PowerManagementLogMessage -Type ERROR -Message "'$($PowerStatus)' task exited with a localized error message. Go to the vSphere Client for details and to take the necessary actions."
Write-PowerManagementLogMessage -Type ERROR -Message "'$($powerStatus)' task exited with a localized error message. Go to the vSphere Client for details and to take the necessary actions."
} else {
Write-PowerManagementLogMessage -Type WARN -Message "'$($PowerStatus)' task exited with the Message:$($task.ExtensionData.Info.Error.Fault.FaultMessage) and Error: $($task.ExtensionData.Info.Error)."
Write-PowerManagementLogMessage -Type WARN -Message "'$($powerStatus)' task exited with the Message:$($task.ExtensionData.Info.Error.Fault.FaultMessage) and Error: $($task.ExtensionData.Info.Error)."
Write-PowerManagementLogMessage -Type ERROR -Message "Go to the vSphere Client for details and to take the necessary actions."
}
}

if ($task.State -EQ "Success") {
Write-PowerManagementLogMessage -Type INFO -Message "$PowerStatus task is completed successfully."
Write-PowerManagementLogMessage -Type INFO -Message "$powerStatus task is completed successfully."
} else {
Write-PowerManagementLogMessage -Type ERROR -Message "$PowerStatus task is blocked in $($task.State) state."
Write-PowerManagementLogMessage -Type ERROR -Message "$powerStatus task is blocked in $($task.State) state."
}
}
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null
Expand Down Expand Up @@ -1738,7 +1738,7 @@ Function Set-VsphereHA {
$retryCount++
# Get running tasks
Start-Sleep -s 5
$runningTasks = get-task -Status Running
$runningTasks = Get-Task -Status Running
if (($runningTasks -match "Update vSAN configuration") -or ($runningTasks -match "Configuring vSphere HA")) {
Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability configuration changes are not applied. Sleeping for $SecondsDelay seconds..."
Start-Sleep -s $SecondsDelay
Expand Down Expand Up @@ -1772,7 +1772,7 @@ Function Set-VsphereHA {
$retryCount++
# Get running tasks
Start-Sleep -s 5
$runningTasks = get-task -Status Running
$runningTasks = Get-Task -Status Running
if (($runningTasks -match "Update vSAN configuration") -or ($runningTasks -match "Configuring vSphere HA")) {
Write-PowerManagementLogMessage -Type INFO -Message "vSphere High Availability configuration changes are not applied. Sleeping for $SecondsDelay seconds..."
Start-Sleep -s $SecondsDelay
Expand Down Expand Up @@ -2423,10 +2423,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 4c47d19

Please sign in to comment.