Skip to content

Commit

Permalink
refactor: replace use of Test-NetConnection
Browse files Browse the repository at this point in the history
`Test-NetConnection` is only supported for Windows Powershell Desktop not PowerShell 7.

- Updated the `Test-NetConnection` to `Test-EndpointConnection` from `PowerValidatedSolutions`.

- Updated all documentation to add `PowerValidatedSolutions` as a module dependency.

- Updated copyright to 2023-2024.

Signed-off-by: Jared Burns <[email protected]>
  • Loading branch information
burnsjared0415 authored and tenthirtyam committed Jan 19, 2024
1 parent dcddc5f commit 5dc1407
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 69 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Release History

## v1.4.1

> Release Date: Not Released
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)

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)

## v1.4.0

> Release Date: 2023-12-05
Enhancement:

- Added support for VMware Cloud Foundation 5.0 on Dell VxRail.
- Added support for VMware Cloud Foundation 5.0 on Dell VxRail. [GH-75](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/75)

## v1.3.0

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright 2023 Broadcom. All Rights Reserved.
Copyright 2023-2024 Broadcom. All Rights Reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Broadcom. All Rights Reserved.
# Copyright 2023-2024 Broadcom. All Rights Reserved.
# SPDX-License-Identifier: BSD-2

docs-install:
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PowerShell Module for VMware Cloud Foundation Power Management
Copyright 2023 Broadcom. All Rights Reserved.
Copyright 2023-2024 Broadcom. All Rights Reserved.

This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in
compliance with the BSD-2 License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For more detailed information, refer to the [contribution guidelines][contributi

## License

Copyright 2023 Broadcom. All Rights Reserved.
Copyright 2023-2024 Broadcom. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
23 changes: 12 additions & 11 deletions SampleScripts/PowerManagement-ManagementDomain.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2023-2024 Broadcom. All Rights Reserved.
# SPDX-License-Identifier: BSD-2

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
Expand All @@ -7,8 +10,7 @@
.NOTES
===============================================================================================================
.Created By: Gary Blake / Sowjanya V
.Group: Cloud Infrastructure Business Group (CIBG)
.Organization: VMware
.Organization: Broadcom
.Version: 1.1 (Build 1000)
.Date: 2022-08-12
===============================================================================================================
Expand Down Expand Up @@ -85,10 +87,8 @@ Function Get-Password {
#EndRegion Non Exported Functions ######
##########################################################################


$pass = Get-Password -User $user -Password $pass


# Error Handling (script scope function)
Function Debug-CatchWriterForPowerManagement {
Param (
Expand Down Expand Up @@ -178,7 +178,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
Try {
# Check connection to SDDC Manager
Write-PowerManagementLogMessage -Type INFO -Message "Attempting to connect to VMware Cloud Foundation to gather system details."
if (!(Test-NetConnection -ComputerName $server -Port 443).TcpTestSucceeded) {
if (!(Test-EndpointConnection -server $server -Port 443)) {
Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or the power state of '$server'." -Colour Red
Exit
}
Expand Down Expand Up @@ -219,7 +219,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
$vcPass = (Get-VCFCredential | Where-Object { $_.accountType -eq "SYSTEM" -and $_.credentialType -eq "SSO" -and $_.resource.resourceId -eq $($workloadDomain.ssoId) }).password
}
# Test if VC is reachable, if it is already stopped, we could not continue with the shutdown sequence in automatic way.
if (-Not (Test-NetConnection -ComputerName $vcServer.fqdn -Port 443).TcpTestSucceeded ) {
if (-Not (Test-EndpointConnection -server $vcServer.fqdn -Port 443) ) {
Write-PowerManagementLogMessage -Type WARNING -Message "Could not connect to $($vcServer.fqdn)! The script could not continue without a connection to the management vCenter Server. " -Colour Cyan
Write-PowerManagementLogMessage -Type ERROR -Message "Please check the current state and resolve the issue or continue with the shutdown operation by following the documentation of VMware Cloud Foundation. Exiting!" -Colour Red
Exit
Expand Down Expand Up @@ -344,7 +344,8 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
Connect-VIServer -server $vcServer.fqdn -user $vcUser -password $vcPass | Out-Null
$sddcManagerIP = (Test-NetConnection -ComputerName $server).RemoteAddress.IPAddressToString
#$sddcManagerIP = (Test-NetConnection -ComputerName $server).RemoteAddress.IPAddressToString
$sddcManagerIP = (Get-VCFManager | Select-Object ipAddress).ipAddress
$sddcmVMName = (Get-VM * | Where-Object { $_.Guest.IPAddress -eq $sddcManagerIP }).Name
$vcHost = (get-vm | where Name -eq $vcServer.fqdn.Split(".")[0] | Select-Object VMHost).VMHost.Name
$vcHostUser = (Get-VCFCredential -resourceType ESXI -resourceName $vcHost | Where-Object { $_.accountType -eq "USER" }).username
Expand Down Expand Up @@ -444,7 +445,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
if ($DefaultVIServers) {
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
if (( Test-NetConnection -ComputerName $vcServer.fqdn -Port 443 ).TcpTestSucceeded) {
if ( Test-EndpointConnection -server $vcServer.fqdn -Port 443 ) {
Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$($vcServer.fqdn)' ..."
Connect-VIServer -Server $vcServer.fqdn -Protocol https -User $vcUser -Password $vcPass -ErrorVariable $vcConnectError | Out-Null
if ($DefaultVIServer.Name -eq $vcServer.fqdn) {
Expand Down Expand Up @@ -668,7 +669,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe
$successcount = 0
#Verify if all ESXi hosts are down in here to conclude End of Shutdown sequence
foreach ($esxiNode in $esxiWorkloadDomain) {
if ((Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
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..." -Colour cyan
break
} else {
Expand Down Expand Up @@ -774,7 +775,7 @@ if ($PsBoundParameters.ContainsKey("startup")) {

# Startup workflow starts here
# Check if VC is running - if so, skip ESXi operations
if (-Not (Test-NetConnection -ComputerName $vcServer.fqdn -Port 443 -WarningAction SilentlyContinue ).TcpTestSucceeded ) {
if (-Not (Test-EndpointConnection -server $vcServer.fqdn -Port 443 -WarningAction SilentlyContinue )) {
Write-PowerManagementLogMessage -Type INFO -Message "Could not connect to $($vcServer.fqdn). Starting vSAN..."
if ([float]$vcfVersion -gt [float]4.4) {
#TODO add check if hosts are up and running. If so, do not display this message
Expand All @@ -798,7 +799,7 @@ if ($PsBoundParameters.ContainsKey("startup")) {
}

foreach ($esxiNode in $esxiWorkloadDomain) {
if (!(Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) {
Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red
Exit
}
Expand Down
32 changes: 16 additions & 16 deletions SampleScripts/PowerManagement-WorkloadDomain.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2023-2024 Broadcom. All Rights Reserved.
# SPDX-License-Identifier: BSD-2

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
Expand All @@ -7,8 +10,7 @@
.NOTES
===============================================================================================================
.Created By: Gary Blake / Sowjanya V
.Group: Cloud Infrastructure Business Group (CIBG)
.Organization: VMware
.Organization: Broadcom
.Version: 1.1 (Build 1000)
.Date: 2022-08-12
===============================================================================================================
Expand Down Expand Up @@ -79,10 +81,8 @@ Function Get-Password {
#EndRegion Non Exported Functions ######
##########################################################################


$pass = Get-Password -User $user -Password $pass


# Error Handling (script scope function)
Function Debug-CatchWriterForPowerManagement {
Param (
Expand Down Expand Up @@ -125,7 +125,7 @@ Try {
Write-PowerManagementLogMessage -Type INFO -Message "Setting up the log file to path $logfile" -Colour Yellow
if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage -Colour Yellow }

if (!(Test-NetConnection -ComputerName $server -Port 443).TcpTestSucceeded) {
if (!(Test-EndpointConnection -server $server -Port 443)) {
Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with SDDC Manager ($server). Check the FQDN or IP address or power state of the '$server'." -Colour Red
Exit
}
Expand Down Expand Up @@ -263,7 +263,7 @@ Try {
if ($DefaultVIServers) {
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
if ((Test-NetConnection -ComputerName $vcServer.fqdn -Port 443 ).TcpTestSucceeded) {
if (Test-EndpointConnection -server $vcServer.fqdn -Port 443 ) {
Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$($vcServer.fqdn)' ..."
Connect-VIServer -Server $vcServer.fqdn -Protocol https -User $vcUser -Password $vcPass -ErrorVariable $vcConnectError | Out-Null
if ($DefaultVIServer.Name -eq $vcServer.fqdn) {
Expand Down Expand Up @@ -315,7 +315,7 @@ Try {
if ($DefaultVIServers) {
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
if (( Test-NetConnection -ComputerName $vcServer.fqdn -Port 443 ).TcpTestSucceeded) {
if ( Test-EndpointConnection -server $vcServer.fqdn -Port 443 ) {
Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$($vcServer.fqdn)' ..."
Connect-VIServer -Server $vcServer.fqdn -Protocol https -User $vcUser -Password $vcPass -ErrorVariable $vcConnectError | Out-Null
if ($DefaultVIServer.Name -eq $vcServer.fqdn) {
Expand Down Expand Up @@ -449,7 +449,7 @@ Try {
}
} else {
foreach ($esxiNode in $esxiDetails) {
if (!(Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) {
Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red
Exit
}
Expand Down Expand Up @@ -501,7 +501,7 @@ Try {
if ($DefaultVIServers) {
Disconnect-VIServer -Server * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null
}
if (( Test-NetConnection -ComputerName $vcServer.fqdn -Port 443 ).TcpTestSucceeded) {
if ( Test-EndpointConnection -server $vcServer.fqdn -Port 443 ) {
Write-PowerManagementLogMessage -Type INFO -Message "Connecting to '$($vcServer.fqdn)' ..."
Connect-VIServer -Server $vcServer.fqdn -Protocol https -User $vcUser -Password $vcPass -ErrorVariable $vcConnectError | Out-Null
if ($DefaultVIServer.Name -eq $vcServer.fqdn) {
Expand Down Expand Up @@ -550,7 +550,7 @@ Try {
}

## Gather NSX Edge Node Details from NSX-T Manager
if ((Test-NetConnection -ComputerName $vcServer.fqdn -Port 443).TcpTestSucceeded) {
if (Test-EndpointConnection -server $vcServer.fqdn -Port 443) {
if ($nxtClusterEdgeNodes) {
Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nxtClusterEdgeNodes -timeout 600
}
Expand All @@ -573,7 +573,7 @@ Try {
if ($VCnode -eq ($vcServer.fqdn)) {
continue
} else {
$checkServer = (Test-NetConnection -ComputerName $VCnode -Port 443).TcpTestSucceeded
$checkServer = (Test-EndpointConnection -server $VCnode -Port 443)
if ($checkServer) {
$allothervcdown = $false
break
Expand All @@ -596,7 +596,7 @@ Try {
## The below block was supposed to be only for verison < 4.5, but due to the bug in 4.5
## vcls vms are not handled automatically though expected in vcf4.5
## Shut Down the vSphere Cluster Services Virtual Machines in the Virtual Infrastructure Workload Domain
if ((Test-NetConnection -ComputerName $vcServer.fqdn -Port 443).TcpTestSucceeded) {
if (Test-EndpointConnection -server $vcServer.fqdn -Port 443) {
Set-Retreatmode -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -mode enable
}
else {
Expand Down Expand Up @@ -625,7 +625,7 @@ Try {
}

# Check the health and sync status of the vSAN cluster
if ((Test-NetConnection -ComputerName $vcServer.fqdn -Port 443).TcpTestSucceeded) {
if (Test-EndpointConnection -server $vcServer.fqdn -Port 443) {
if ([float]$vcfVersion -gt [float]4.4) {
$RemoteVMs = @()
$RemoteVMs = Get-poweronVMsOnRemoteDS -server $vcServer.fqdn -user $vcUser -pass $vcPass -clustertocheck $cluster.name
Expand Down Expand Up @@ -723,7 +723,7 @@ Try {
$successcount = 0
#Verify if all ESXi hosts are down in here to conclude End of Shutdown sequence
foreach ($esxiNode in $esxiDetails) {
if ((Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) {
Write-PowerManagementLogMessage -Type WARNING -Message "$($esxiNode.fqdn) is still up. Sleeping for $sleepTime seconds before next check..." -Colour Yellow
} else {
$successcount++
Expand All @@ -742,7 +742,7 @@ Try {
# vSAN shutdown wizard automation.
Set-VsanClusterPowerStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -PowerStatus clusterPoweredOff
foreach ($esxiNode in $esxiDetails) {
if ((Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
if (Test-EndpointConnection -server $esxiNode.fqdn -Port 443) {
Write-PowerManagementLogMessage -Type ERROR -Message "$($esxiNode.fqdn) is still up. Check the FQDN or IP address, or the power state of the '$($esxiNode.fqdn)'." -Colour Red
Exit
}
Expand Down Expand Up @@ -920,7 +920,7 @@ Try {

$esxiDetails = $esxiWorkloadCluster[$cluster.name]
foreach ($esxiNode in $esxiDetails) {
if (!(Test-NetConnection -ComputerName $esxiNode.fqdn -Port 443).TcpTestSucceeded) {
if (!(Test-EndpointConnection -server $esxiNode.fqdn -Port 443)) {
Write-PowerManagementLogMessage -Type ERROR -Message "Cannot communicate with the host $($esxiNode.fqdn). Check the FQDN or IP address, or the power state of '$($esxiNode.fqdn)'." -Colour Red
Exit
}
Expand Down
12 changes: 8 additions & 4 deletions VMware.CloudFoundation.PowerManagement.psd1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Broadcom. All Rights Reserved.
# Copyright 2023-2024 Broadcom. All Rights Reserved.
# SPDX-License-Identifier: BSD-2

# Module manifest for module 'VMware.CloudFoundation.PowerManagement'
Expand All @@ -11,7 +11,7 @@
RootModule = 'VMware.CloudFoundation.PowerManagement.psm1'

# Version number of this module.
ModuleVersion = '1.4.0.1001'
ModuleVersion = '1.4.1.1000'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -26,7 +26,7 @@
CompanyName = 'Broadcom'

# Copyright statement for this module
Copyright = 'Copyright 2023 Broadcom. All Rights Reserved.'
Copyright = 'Copyright 2023-2024 Broadcom. All Rights Reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell Module for VMware Cloud Foundation Power Management'
Expand Down Expand Up @@ -57,7 +57,11 @@
}
@{
ModuleName = 'PowerVCF';
ModuleVersion = '2.3.0'
ModuleVersion = '2.4.0'
}
@{
ModuleName = 'PowerValidatedSolutions';
ModuleVersion = '2.8.0'
}
)

Expand Down
Loading

0 comments on commit 5dc1407

Please sign in to comment.