Skip to content

Commit

Permalink
feat: add workload vcenter check (#90)
Browse files Browse the repository at this point in the history
Added a workload domain vCenter Server check to `PowerManagement-ManagmentDomain.ps1` so that we ask if user wants to move forward if workload domain vCenter Server instances are still powered on.

Ref: #46

Signed-off-by: Jared Burns <[email protected]>
  • Loading branch information
burnsjared0415 authored Feb 12, 2024
1 parent da3090c commit 43ad68b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

> Release Date: Not Released
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 a workload domain vCenter Server check to `PowerManagement-ManagmentDomain.ps1` to check if workload domain vCenter Server instances are still powered on before starting the shutdown of the management domain. [GH-90](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/90)

Refactor:

- Replaced the use of `Test-NetConnection` to with `Test-EndpointConnection` from the PowerShell module `PowerValidatedSolutions`. [GH-85](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/85)
- Replaced current if statement `nsxtedgeNodes` to check for Virtual Machines running on Overlay Network. [GH-86] (https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/86)
- 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
- Replaced current if statement `nsxtEdgeNodes` to check for virtual machines running on an NSX overlay network. [GH-86] (https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/86)

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)
- Added `PowerValidatedSolutions` v2.8.0 as a module dependency. [GH-38](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/38)
- Updated `Write-PowerManagementLogMessage` to set colour for message types. This will allow for all references to use colour based on function. [GH-89](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/89)
- 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
28 changes: 28 additions & 0 deletions SampleScripts/PowerManagement-ManagementDomain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,34 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
}
}
}
if (Test-VCFConnection -server $server) {
if (Test-VCFAuthentication -server $server -user $user -pass $pass) {
$allWorkloadvCenters = @()
$allWorkloadvCenters = (Get-VCFWorkloadDomain | Select-object type -ExpandProperty vcenters | Where-Object { $_.type -eq "VI" }).fqdn
if ($allWorkloadvCenters) {
$domain = Get-VCFWorkloadDomain | Select-Object name, type | Where-Object { $_.type -eq "MANAGEMENT" }
if (($vcfVcenterDetails = Get-vCenterServerDetail -server $server -user $user -pass $pass -domain $domain.name)) {
if (Test-vSphereConnection -server $($vcfVcenterDetails.fqdn)) {
if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) {
$allWorkloadvCenters | ForEach-Object {
$vm = $_.Split('.')[0]
$isPoweredOn = (Get-VM | Select-Object Name, PowerState | Where-Object { $_.name -eq $vm }).PowerState
if ($isPoweredOn -eq "PoweredOn") {
$answer = Read-Host -Prompt "Workload domain vCenter Server instance $vm is powered on. Do you want to continue shutdown of the management domain? Y/N"
if ( $answer -eq 'N') {
Write-PowerManagementLogMessage -Type WARNING "Please shutdown the workload domain vCenter Server instance $vm and retry."
Exit
} else {
Write-PowerManagementLogMessage -Type INFO "Continuing with the shutdown of the management domain."
}
}
}
}
}
}
}
}
}

Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch all powered-on virtual machines from server $($vcServer.fqdn)..."
[Array]$allvms = Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -silence
Expand Down
2 changes: 1 addition & 1 deletion 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.1003'
ModuleVersion = '1.4.1.1004'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down

0 comments on commit 43ad68b

Please sign in to comment.