From 1b4d41a9a941f19026ee09a6e5d1e9f850ece0a6 Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Wed, 14 Feb 2024 13:39:21 -0500 Subject: [PATCH 1/5] refactor: added code to allow for IP address on PowerManagement-ManagmentDomain.ps1 Replaced code in `PowerManagement-ManagmentDomain.ps1` updated `$vcfvms` to allow for ip address or FQDN. Signed-off-by: Jared Burns --- CHANGELOG.md | 6 +++++- VMware.CloudFoundation.PowerManagement.psd1 | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012847a..7651e36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,11 @@ 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) +- Updated `PowerManagement-ManagmentDomain.ps1` to check for virtual machines running on an NSX overlay segment. [GH-86](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/86) +- 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) +- Added support to `PowerManagement-ManagmentDomain.ps1` and `PowerManagement-WorkloadDomain.ps1` for vSAN File Services to be excluded from customer virtual machines [GH-94](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/94) Refactor: diff --git a/VMware.CloudFoundation.PowerManagement.psd1 b/VMware.CloudFoundation.PowerManagement.psd1 index ebd9bd0..7b99ef8 100644 --- a/VMware.CloudFoundation.PowerManagement.psd1 +++ b/VMware.CloudFoundation.PowerManagement.psd1 @@ -3,7 +3,7 @@ # Module manifest for module 'VMware.CloudFoundation.PowerManagement' # Generated by: Broadcom -# Generated on: 2024-02-07 +# Generated on: 2024-02-15 @{ @@ -11,7 +11,7 @@ RootModule = 'VMware.CloudFoundation.PowerManagement.psm1' # Version number of this module. - ModuleVersion = '1.4.1.1004' + ModuleVersion = '1.4.1.1007' # Supported PSEditions # CompatiblePSEditions = @() From 5bcf924837b568b6b66ec92b6a8c411508f9df7d Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Thu, 15 Feb 2024 09:16:05 -0500 Subject: [PATCH 2/5] refactor: update for fqdn or ip address (#92) Updated `PowerManagement-ManagmentDomain.ps1` to allow for FQDN or IP address of SDDC Manager. Signed-off-by: Jared Burns --- CHANGELOG.md | 6 +- .../PowerManagement-ManagementDomain.ps1 | 94 ++++++++----------- 2 files changed, 41 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7651e36..c0e1dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,13 +15,13 @@ Enhancement: 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 an NSX overlay network. [GH-86] (https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-power-management/pull/86) +- 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) 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) +- 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 `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 diff --git a/SampleScripts/PowerManagement-ManagementDomain.ps1 b/SampleScripts/PowerManagement-ManagementDomain.ps1 index 11f711e..7fc861b 100644 --- a/SampleScripts/PowerManagement-ManagementDomain.ps1 +++ b/SampleScripts/PowerManagement-ManagementDomain.ps1 @@ -134,24 +134,20 @@ Try { if (-Not $proceed) { Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence stopping script execution." Exit - } - else { + } else { if (($proceed -match "no") -or ($proceed -match "yes")) { if ($proceed -match "no") { Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'." Exit } - } - else { + } else { Write-PowerManagementLogMessage -Type WARNING -Message "Pass the right string, either 'Yes' or 'No'." Exit } } - Write-PowerManagementLogMessage -Type INFO -Message "'$inputFile' is checked for correctness, proceeding with the execution." } -} -Catch { +} Catch { Debug-CatchWriterForPowerManagement -object $_ } @@ -167,8 +163,7 @@ Try { Write-PowerManagementLogMessage -Type INFO -Message "Script used: $str1" Write-PowerManagementLogMessage -Type INFO -Message "Script syntax: $str2" if (-Not $null -eq $customerVmMessage) { Write-PowerManagementLogMessage -Type INFO -Message $customerVmMessage} -} -Catch { +} Catch { Debug-CatchWriterForPowerManagement -object $_ Exit } @@ -218,27 +213,36 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $vcUser = (Get-VCFCredential | Where-Object { $_.accountType -eq "SYSTEM" -and $_.credentialType -eq "SSO" -and $_.resource.resourceId -eq $($workloadDomain.ssoId) }).username $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. + + # Test if the vCenter Server instance is reachable, if it is already stopped, do not continue with the shutdown sequence in automatic way. 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. " 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!" Exit } + $status = Get-TanzuEnabledClusterStatus -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name + if ($status -eq $True) { Write-PowerManagementLogMessage -Type ERROR -Message "Currently we are not supporting VMware Tanzu enabled domains. Please try on other workload domains." Exit } + if ($vcPass) { $vcPass_encrypted = $vcPass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString - } - else { + } else { $vcPass_encrypted = $null } [Array]$allvms = @() [Array]$vcfvms = @() - [Array]$vcfvms += $server.Split(".")[0] + # Checks to see if the server parameter is provided as an IP address or FQDN. + if ($server -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$') { + $fqdn = (Get-VCFManager | Select-Object fqdn, ipAddress | Where-Object { $_.ipAddress -eq $server }).fqdn + [Array]$vcfvms += $fqdn.Split(".")[0] + } else { + [Array]$vcfvms += $server.Split(".")[0] + } [Array]$vcfvms += ($vcServer.fqdn).Split(".")[0] @@ -265,8 +269,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $Pass = $esxDetails.password if ($Pass) { $Pass_encrypted = $Pass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString - } - else { + } else { $Pass_encrypted = $null } $esxi_block["password"] = $Pass_encrypted @@ -281,8 +284,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $Pass = (Get-VCFCredential | Where-Object ({ $_.resource.resourceName -eq $nsxtMgrfqdn -and $_.credentialType -eq "API" })).password if ($Pass) { $Pass_encrypted = $Pass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString - } - else { + } else { $Pass_encrypted = $null } $nsxMgrVIP | Add-Member -Type NoteProperty -Name adminPassword -Value $Pass @@ -310,15 +312,13 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } if ($statusOfNsxtClusterVMs -ne 'running') { Write-PowerManagementLogMessage -Type WARNING -Message "NSX Manager VMs have been stopped. NSX Edge VMs will not be handled automatically." - } - else { + } else { Try { 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 $nsxtMgrfqdn -user $nsxMgrVIP.adminUser -pass $nsxMgrVIP.adminPassword -VCfqdn $VcServer.fqdn) $edgenodesstring = $edgeNodes -join "," Write-PowerManagementLogMessage -Type INFO -Message "The NSX Edge VMs are $edgenodesstring." - } - catch { + } catch { Write-PowerManagementLogMessage -Type ERROR -Message "Something went wrong! Cannot fetch NSX Edge nodes information from NSX Manager '$nsxtMgrfqdn'. Exiting!" } } @@ -352,7 +352,6 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $vcHostPass = (Get-VCFCredential -resourceType ESXI -resourceName $vcHost | Where-Object { $_.accountType -eq "USER" }).password $vcHostPass_encrypted = $vcHostPass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString Disconnect-VIServer * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null - } #Backup DRS Automation level settings into JSON file @@ -381,14 +380,12 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Write-PowerManagementLogMessage -Type INFO -Message "ManagementStartupInput.json is created in the $location path." Write-PowerManagementLogMessage -Type INFO -Message "#############################################################" Exit - } - else { + } else { Write-PowerManagementLogMessage -Type ERROR -Message "JSON file is not created. Check for permissions in the $location path" Exit } } - } - else { + } else { Write-PowerManagementLogMessage -Type ERROR -Message "Cannot obtain an access token from SDDC Manager ($server). Check your credentials." Exit } @@ -488,8 +485,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe [Array]$VMwareToolsNotRunningVMs += $vm } } - } - else { + } else { Write-PowerManagementLogMessage -Type ERROR -Message "Unable to connect to vCenter Server '$($vcServer.fqdn)'. Command returned the following error: '$vcConnectError'." } } @@ -513,8 +509,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Write-PowerManagementLogMessage -Type WARNING -Message "The list of Non VCF management VMs: '$customervms_string'." # Stop Customer VMs with one call to VC: Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $customervms -timeout 300 - } - else { + } else { Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is not passed to the script." Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down management VMs not managed by SDDC Manager: $($customervms_string) ." Write-PowerManagementLogMessage -Type ERROR -Message "The script cannot proceed unless these VMs are shut down manually or the -shutdownCustomerVm option is present. Take the necessary action and run the script again." @@ -595,8 +590,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe #Check the vSAN health before SDDC manager is stopped if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { #Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." - } - else { + } else { Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN cluster status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN health issues, run the script again." Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue the shutdown workflow by following the documentation of VMware Cloud Foundation. " Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." @@ -604,8 +598,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } if ((Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { #Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization is successful." - } - else { + } else { Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script... Wait until the vSAN object resynchronization is completed and run the script again." Exit } @@ -660,8 +653,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe #Testing VSAN health after SDDC manager is stopped if ( (Test-VsanHealth -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster health is good." - } - else { + } else { Write-PowerManagementLogMessage -Type WARNING -Message "The vSAN cluster isn't in a healthy state. Check the vSAN status in vCenter Server '$($vcServer.fqdn)'. After you resolve the vSAN issues, run the script again." Write-PowerManagementLogMessage -Type WARNING -Message "If the script has reached ESXi vSAN shutdown previously, this error is expected. Continue by following the documentation of VMware Cloud Foundation. " Write-PowerManagementLogMessage -Type ERROR -Message "The vSAN cluster isn't in a healthy state. Check the messages above for a solution." @@ -669,8 +661,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } if ((Test-VsanObjectResync -cluster $cluster.name -server $vcServer.fqdn -user $vcUser -pass $vcPass) -eq 0) { Write-PowerManagementLogMessage -Type INFO -Message "VSAN object resynchronization is successful." - } - else { + } else { Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Stopping the script. Wait until the vSAN object resynchronization is completed and run the script again." Exit } @@ -682,8 +673,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state." Write-PowerManagementLogMessage -Type WARNING -Message "Cannot proceed until the powered-on VMs are shut down. Shut them down them manually and continue with the shutdown operation by following documentation of VMware Cloud Foundation." Write-PowerManagementLogMessage -Type ERROR -Message "There are running VMs in environment: $($runningVMs). Exiting! " - } - else { + } else { Write-PowerManagementLogMessage -Type INFO -Message "There are no VMs in powered-on state. Hence, shutting down vCenter Server..." # Shutdown vCenter Server Stop-CloudComponent -server $vcHost -user $vcHostUser -pass $vcHostPass -pattern $vcServer.fqdn.Split(".")[0] -timeout 600 @@ -810,8 +800,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { if ($MgmtInput.Server.vchostpassword) { $vchostpassword = convertto-securestring -string $MgmtInput.Server.vchostpassword $vchostpassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($vchostpassword)))) - } - else { + } else { $vchostpassword = $null } $vcHostPass = $vchostpassword @@ -826,8 +815,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { if ($esxiHost.password) { $esxpassword = convertto-securestring -string $esxiHost.password $esxpassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($esxpassword)))) - } - else { + } else { $esxpassword = $null } $esxDetails | Add-Member -Type NoteProperty -Name password -Value $esxpassword @@ -842,8 +830,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { if ($MgmtInput.NsxtManager.password) { $nsxpassword = convertto-securestring -string $MgmtInput.NsxtManager.password $nsxpassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($nsxpassword)))) - } - else { + } else { $nsxpassword = $null } $nsxMgrVIP | Add-Member -Type NoteProperty -Name adminPassword -Value $nsxpassword @@ -869,8 +856,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { if (-Not $proceed) { Write-PowerManagementLogMessage -Type WARNING -Message "None of the options is selected. Default is 'No', hence, stopping script execution..." Exit - } - else { + } else { if (($proceed -match "no") -or ($proceed -match "yes")) { if ($proceed -match "no") { Write-PowerManagementLogMessage -Type WARNING -Message "Stopping script execution because the input is 'No'..." @@ -899,8 +885,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { Exit } } - } - catch { + } catch { Write-PowerManagementLogMessage -Type ERROR -Message "Cannot open an SSH connection to host $($esxiNode.fqdn). If SSH is not enabled, follow the steps in the documentation to enable it." } @@ -939,8 +924,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { Exit } } - } - else { + } else { Write-PowerManagementLogMessage -Type INFO -Message "vCenter Server '$($vcServer.fqdn)' is running. Skipping vSAN startup!" } @@ -1005,8 +989,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { if ([string]::IsNullOrEmpty($DrsAutomationLevel)) { Write-PowerManagementLogMessage -Type ERROR -Message "The DrsAutomationLevel value in the JSON file is empty. Exiting!" Exit - } - else { + } else { Set-DrsAutomationLevel -server $vcServer.fqdn -user $vcUser -pass $vcPass -cluster $cluster.name -level $DrsAutomationLevel } } @@ -1046,8 +1029,7 @@ if ($PsBoundParameters.ContainsKey("startup")) { # Startup the NSX Edge Nodes in the Management Workload Domain if ($nsxtEdgeNodes) { Start-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtEdgeNodes -timeout 600 - } - else { + } else { Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping startup..." } From 600b5c99d5ef37ddb600261ff07f39fce0f3aaab Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Wed, 14 Feb 2024 14:02:56 -0500 Subject: [PATCH 3/5] feat: Added support for multiple clusters in mgmt domain Added support to `PowerManagement-ManagmentDomain.ps1` for more than one cluster in management domain for shut down and start up. Signed-off-by: Jared Burns --- SampleScripts/PowerManagement-ManagementDomain.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/SampleScripts/PowerManagement-ManagementDomain.ps1 b/SampleScripts/PowerManagement-ManagementDomain.ps1 index 7fc861b..bad95d9 100644 --- a/SampleScripts/PowerManagement-ManagementDomain.ps1 +++ b/SampleScripts/PowerManagement-ManagementDomain.ps1 @@ -186,6 +186,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Write-PowerManagementLogMessage -Type INFO -Message "Gathering system details from the SDDC Manager inventory. It will take some time." $workloadDomain = Get-VCFWorkloadDomain | Where-Object { $_.type -eq "MANAGEMENT" } # Check if we have single cluster in the MGMT domain + $vcfVersion = Get-VCFManager | Select-Object version | Select-String -Pattern '\d+\.\d+' -AllMatches | ForEach-Object { $_.matches.groups[0].value } if ($workloadDomain.clusters.id.count -gt 1) { Write-PowerManagementLogMessage -Type ERROR -Message "There are multiple clusters in Management domain. This script supports only a single cluster per domain. Exiting!" Exit From 71e5e28bb8d269145931691db80d480deb50dcea Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Thu, 15 Feb 2024 14:11:12 -0500 Subject: [PATCH 4/5] feat: add support for multiple clusters in mgmt domain (#93) Added support to PowerManagement-ManagmentDomain.ps1 for more than one cluster in management domain for shut down and start up. Signed-off-by: Jared Burns --- CHANGELOG.md | 2 +- .../PowerManagement-ManagementDomain.ps1 | 313 +++++++++++++++++- 2 files changed, 300 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0e1dfd..d682e18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ Enhancement: 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) +- 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) Chore: diff --git a/SampleScripts/PowerManagement-ManagementDomain.ps1 b/SampleScripts/PowerManagement-ManagementDomain.ps1 index bad95d9..1ee21e8 100644 --- a/SampleScripts/PowerManagement-ManagementDomain.ps1 +++ b/SampleScripts/PowerManagement-ManagementDomain.ps1 @@ -188,11 +188,167 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe # Check if we have single cluster in the MGMT domain $vcfVersion = Get-VCFManager | Select-Object version | Select-String -Pattern '\d+\.\d+' -AllMatches | ForEach-Object { $_.matches.groups[0].value } if ($workloadDomain.clusters.id.count -gt 1) { - Write-PowerManagementLogMessage -Type ERROR -Message "There are multiple clusters in Management domain. This script supports only a single cluster per domain. Exiting!" - Exit + Write-PowerManagementLogMessage -Type INFO -Message "More than one cluster exists in the management domain." + $mgmtClusterIds = @() + $mgmtClusterIds = (Get-VCFWorkloadDomain | Select-Object Type -ExpandProperty clusters | Where-Object { $_.type -eq "MANAGEMENT" }).id + foreach ($clusterid in $mgmtClusterIds) { + $clusterid = (Get-VCFCluster | Select-Object name, id, isdefault | Where-Object { $_.id -eq $clusterid }) + $clustername = $Clusterid.name + if (!$isDefault) { + $answer = Read-Host -Prompt "Shutdown cluster $clustername. Do you want to continue? Y/N" + if ($answer -Match "N") { + Write-PowerManagementLogMessage -Type WARNING "Cancelling shutdown of $clustername. Exiting..." + Exit + } else { + Write-PowerManagementLogMessage -Type INFO "Shutting down $clustername..." + } + # Shut Down the vSphere Cluster Services Virtual Machines + $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) { + # Set DRS Automation Level to Manual in the Management Domain + Set-DrsAutomationLevel -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -level Manual + if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + $listofVmsnotvCLS = (Get-VM -Location $clustername | Select-Object Name, PowerState, @{N = "ToolsStatus"; E = { $_.ExtensionData.Guest.ToolsStatus } } | Where-Object { $_.name -inotmatch "vCLS" -and $_.PowerState -eq "PoweredOn" }) + $vmnames = $listofVmsnotvCLS.Name + $tools = $listofVmsnotvCLS.ToolsStatus + foreach ($vmname in $vmnames) { + if ($tools[$vmnames.IndexOf($vmname)] -eq "toolsOK") { + Stop-CloudComponent -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -nodes $vmname -timeout 300 + } else { + Write-Error "Unable to shutdown virtual machines $vmname. VMware Tools is not running, Please shutdown the virtual machines before retrying. Exiting..." + Exit + } + } + + # Shut Down the vSphere Cluster Services Virtual Machines + Set-Retreatmode -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -mode enable + $counter = 0 + $retries = 10 + Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS shutdown will take time. Please wait..." + + while ($counter -ne $retries) { + if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + $powerOnVMcount = (Get-VM -Location $clustername | Where-Object { $_.name -match "vCLS" }).count + if ( $powerOnVMcount ) { + Write-PowerManagementLogMessage -Type INFO -Message "Some vCLS virtual machines are still running. Sleeping for $sleepTime seconds until the next check..." + Start-Sleep -s $sleepTime + Break + } + } + } + if ($counter -eq $retries) { + Write-PowerManagementLogMessage -Type ERROR -Message "vCLS virtual machines were not shut down within the expected time. Exiting... " + Exit + } + + # Stop vSphere HA to avoid "orphaned" VMs during vSAN shutdown + if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + if (!$(Set-VsphereHA -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -disableHA)) { + Write-PowerManagementLogMessage -Type ERROR -Message "Unable to disable vSphere High Availability for cluster '$clustername'. Exiting..." + Exit + } + } + if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + $RemoteVMs = @() + $RemoteVMs = Get-poweronVMsOnRemoteDS $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -clustertocheck $clustername + Write-PowerManagementLogMessage -Type INFO -Message "All remote virtual machines are powered off." + } else { + Write-PowerManagementLogMessage -Type ERROR -Message "Some remote virtual machines are still powered-on : $($RemoteVMs.Name). Unable to proceed until these are are shutdown. Exiting..." + Exit + } + # Testing VSAN health + if ( (Test-VsanHealth -cluster $clustername -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) -eq 0) { + Write-PowerManagementLogMessage -Type INFO -Message "vSAN cluster is in a healthy state." + } else { + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN cluster is in an unhealthy state. Check the vSAN status in cluster '$($clustername)'. Retry after resolving the vSAN health state. Exiting..." + Exit + } + if ((Test-VsanObjectResync -cluster $clustername -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) -eq 0) { + Write-PowerManagementLogMessage -Type INFO -Message "vSAN object resynchronization successful." + } else { + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization is running. Retry after the vSAN object resynchronization is completed. Exiting..." + Exit + } + # Checks SSH Status, if SSH service is not started, SSH will be started + if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + if ([float]$vcfVersion -lt [float]4.5) { + # Disable cluster member updates from vCenter Server + $esxihosts = (Get-VCFHost | Select-Object fqdn -ExpandProperty cluster | Where-Object { $_.id -eq $clusterid.id }).fqdn + foreach ($esxi in $esxihosts) { + $password = (Get-VCFCredential -resourceName $esxi | Select-Object password) + $esxihostpassword = $password.password[1] + $status = Get-SSHEnabledStatus -server $esxi -user root -pass $esxihostpassword + if (!$status) { + if (Test-vSphereAuthentication -server $esxi -user root -pass $esxihostpassword) { + Get-VmHostService -VMHost $esxi | Where-Object { $_.key -eq "TSM-SSH" } | Start-VMHostService + Write-Output "Setting ESXi host $esxi to ignoreClusterMemberListUpdates..." + Invoke-EsxCommand -server $esxi -user root -pass $esxihostpassword -expected "Value of IgnoreClusterMemberListUpdates is 1" -cmd "esxcfg-advcfg -s 1 /VSAN/IgnoreClusterMemberListUpdates" + } + } else { + if (Test-vSphereAuthentication -server $esxi -user root -pass $esxihostpassword) { + Write-Output "Setting ESXi host $esxi to ignoreClusterMemberListUpdates..." + Invoke-EsxCommand -server $esxi -user root -pass $esxihostpassword -expected "Value of IgnoreClusterMemberListUpdates is 1" -cmd "esxcfg-advcfg -s 1 /VSAN/IgnoreClusterMemberListUpdates" + } + } + } + # Run vSAN cluster preparation on one ESXi host per cluster. + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 60 seconds before preparing ESXi hosts for vSAN shutdown..." + Start-Sleep -s 60 + $password = (Get-VCFCredential -resourceName $esxihosts[0] | Select-Object password) + $esxihostpassword = $password.password[1] + Invoke-EsxCommand -server $esxihosts[0] -user root -pass $esxihostpassword -expected "Cluster preparation is done" -cmd "python /usr/lib/vmware/vsan/bin/reboot_helper.py prepare" + # Putting hosts in maintenance mode + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 30 seconds before putting ESXi hosts in maintenance mode..." + Start-Sleep -s 30 + foreach ($esxiNode in $esxihosts) { + $password = (Get-VCFCredential -resourceName $esxi | Select-Object password) + $esxihostpassword = $password.password[1] + Set-MaintenanceMode -server $esxiNode -user root -pass $esxihostpassword -state ENABLE + } + # End of shutdown + Write-PowerManagementLogMessage -Type INFO -Message "End of the shutdown sequence!" + Write-PowerManagementLogMessage -Type INFO -Message "You can now shut down the ESXi hosts." + } else { + # vSAN shutdown wizard automation. + Set-VsanClusterPowerStatus -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -PowerStatus clusterPoweredOff -mgmt + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 60 seconds before checking ESXi hosts' shutdown status..." + Start-Sleep -s 60 + $counter = 0 + $sleepTime = 60 # in seconds + while ($counter -lt 1800) { + $successcount = 0 + # Verify all ESXi hosts are shut down to conclude the sequence + foreach ($esxiNode in $esxihosts) { + if (Test-VsphereConnection -server $esxiNode) { + Write-PowerManagementLogMessage -Type WARNING -Message "Some ESXi hosts are still up. Pausing for 60 seconds before next check..." + Break + } else { + $successcount++ + } + } + if ($successcount -eq $esxiWorkloadDomain.count) { + Write-PowerManagementLogMessage -Type INFO -Message "All ESXi hosts have been shut down successfully!" + Write-PowerManagementLogMessage -Type INFO -Message "Successfully completed the shutdown sequence!" + Exit + } else { + Start-Sleep -s $sleepTime + $counter += $sleepTime + } + } + } + } + } + } + } + } + } + } + } else { + Write-PowerManagementLogMessage -Type INFO -Message "A single cluister exists in the management domain." } - $cluster = Get-VCFCluster | Where-Object { $_.id -eq ($workloadDomain.clusters.id) } - $vcfVersion = Get-VCFManager | select version | Select-String -Pattern '\d+\.\d+' -AllMatches | ForEach-Object {$_.matches.groups[0].value} + $var = @{} $var["Domain"] = @{} @@ -243,7 +399,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe [Array]$vcfvms += $fqdn.Split(".")[0] } else { [Array]$vcfvms += $server.Split(".")[0] - } + } [Array]$vcfvms += ($vcServer.fqdn).Split(".")[0] @@ -432,8 +588,8 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe $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." + if ($answer -Match 'N') { + Write-PowerManagementLogMessage -Type ERROR "Please shutdown the workload domain vCenter Server instance $vm and retry. Exiting..." Exit } else { Write-PowerManagementLogMessage -Type INFO "Continuing with the shutdown of the management domain." @@ -445,7 +601,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } } - } + } 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 @@ -512,7 +668,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $customervms -timeout 300 } else { Write-PowerManagementLogMessage -Type WARNING -Message "Some VMs are still in powered-on state. -shutdownCustomerVm is not passed to the script." - Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down management VMs not managed by SDDC Manager: $($customervms_string) ." + Write-PowerManagementLogMessage -Type WARNING -Message "Hence not shutting down management VMs not managed by SDDC Manager: $($customervms_string) ." Write-PowerManagementLogMessage -Type ERROR -Message "The script cannot proceed unless these VMs are shut down manually or the -shutdownCustomerVm option is present. Take the necessary action and run the script again." Exit } @@ -530,7 +686,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe if (Test-vSphereConnection -server $($vcfVcenterDetails.fqdn)) { if (Test-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { Write-PowerManagementLogMessage -Type INFO -Message "Stopping the VMware Aria Operations for Logs nodes..." - Stop-CloudComponent -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -nodes $vmlist -timeout 600 + Stop-CloudComponent -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -nodes $vmlist -timeout 600 } } } @@ -538,7 +694,7 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } } - } + } # Check if there are any running Virtual Machines on the Overlay Networks before shutting down Edge Cluster. if ($nsxtEdgeNodes) { @@ -579,10 +735,10 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe } } } - } + } } } - + #Stop NSX Manager nodes Write-PowerManagementLogMessage -Type INFO -Message "Stopping the NSX Manager nodes..." Stop-CloudComponent -server $vcServer.fqdn -user $vcUser -pass $vcPass -nodes $nsxtNodes -timeout 600 @@ -1033,8 +1189,137 @@ if ($PsBoundParameters.ContainsKey("startup")) { } else { Write-PowerManagementLogMessage -Type WARNING -Message "No NSX Edge nodes present. Skipping startup..." } + if (-Not (Test-VCFConnection -server $server )) { + Write-PowerManagementLogMessage -Type INFO -Message "Could not connect to $server..." + } + if (Test-VCFAuthentication -server $server -user $user -pass $pass) { + $mgmtClusterIds = @() + $mgmtClusterIds = (Get-VCFWorkloadDomain | Select-Object Type -ExpandProperty clusters | Where-Object { $_.type -eq "MANAGEMENT" }).id + # Checks to see how many Clusters are in Management Domain + if ($mgmtClusterIds.Count -ge 2) { + foreach ($clusterid in $mgmtClusterIds) { + $clusterid = (Get-VCFCluster | Select-Object name, id, isdefault | Where-Object { $_.id -eq $clusterid }) + $clustername = $Clusterid.name + $isDefault = $clusterid.isDefault + if (!$isDefault) { + $answer = Read-Host -Prompt "Start up cluster $clustername, Do you want to continue? Y/N" + if ($answer -Match 'N') { + Write-PowerManagementLogMessage -Type WARNING "Cancelled start up of $clustername. Exiting..." + Exit + } else { + Write-PowerManagementLogMessage -Type INFO "Will Move Forward with start up of $clustername" + } + $esxihosts = (Get-VCFHost | Select-Object fqdn -ExpandProperty cluster | Where-Object { $_.id -eq $clusterid.id }).fqdn + foreach ($esxiNode in $esxihosts) { + if (-Not (Test-VsphereConnection -server $esxiNode)) { + Write-PowerManagementLogMessage -Type WARNING "ESXi host $esxiNode is not powered on...." + } else { + $password = (Get-VCFCredential -resourceName $esxiNode| Select-Object password) + $esxihostpassword = $password.password[1] + $status = Get-SSHEnabledStatus -server $esxiNode-user root -pass $esxihostpassword + if (!$status) { + if (Test-vSphereAuthentication -server $esxiNode-user root -pass $esxihostpassword) { + Get-VmHostService -VMHost $esxiNode | Where-Object { $_.key -eq "TSM-SSH" } | Start-VMHostService + Set-MaintenanceMode -server $esxiNode -user root -pass $esxihostpassword -state DISABLE + } + } else { + if (Test-vSphereAuthentication -server $esxiNode -user root -pass $esxihostpassword) { + Set-MaintenanceMode -server $esxiNode -user root -pass $esxihostpassword -state DISABLE + } + } + } + } + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 30 seconds while hosts come out of maintenance mode..." + Start-Sleep -s 30 + if ([float]$vcfVersion -lt [float]4.5) { + # Prepare the vSAN cluster for startup - Performed on a single host only + # We need some time before this step, setting hard sleep 30 sec + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 30 seconds before starting vSAN..." + $password = (Get-VCFCredential -resourceName $esxihosts[0] | Select-Object password) + $esxihostpassword = $password.password[1] + Invoke-EsxCommand -server $esxihosts[0] -user root -pass $esxihostpassword -expected "Cluster reboot/poweron is completed successfully!" -cmd "python /usr/lib/vmware/vsan/bin/reboot_helper.py recover" + # We need some time before this step, setting hard sleep 30 sec + Write-PowerManagementLogMessage -Type INFO -Message "Pausing for 30 seconds before enabling vSAN updates..." + Start-Sleep -s 30 + foreach ($esxi in $esxihosts) { + $password = (Get-VCFCredential -resourceName $esxi | Select-Object password) + $esxihostpassword = $password.password[1] + if (Test-vSphereAuthentication -server $esxi -user root -pass $esxihostpassword) { + Write-PowerManagementLogMessage -Type INFO -Message "Set hosts to ignoreClusterMemberListUpdates" + Invoke-EsxCommand -server $esxi -user root -pass $esxihostpassword -expected "Value of IgnoreClusterMemberListUpdates is 0" -cmd "esxcfg-advcfg -s 0 /VSAN/IgnoreClusterMemberListUpdates" + } + } + + Write-PowerManagementLogMessage -Type INFO -Message "Checking vSAN status of the ESXi hosts..." + foreach ($esxiNode in $esxihosts) { + $password = (Get-VCFCredential -resourceName $esxi | Select-Object password) + $esxihostpassword = $password.password[1] + Invoke-EsxCommand -server $esxiNode.fqdn -user $esxiNode.username -pass $esxiNode.password -expected "Local Node Health State: HEALTHY" -cmd "esxcli vsan cluster get" + } + } + $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-vSphereAuthentication -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) { + + # Start the vSAN cluster wizard. + if ([float]$vcfVersion -gt [float]4.5) { + # Lockdown mode check + Test-LockdownMode -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername + # Restart cluster using wizard + Set-VsanClusterPowerStatus -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -PowerStatus clusterPoweredOn + } + # Check vSAN Status + if ( (Test-VsanHealth -cluster $clustername -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) -ne 0) { + Write-PowerManagementLogMessage -Type WARNING -Message "vSAN cluster is in an unhealthy state. Check the vSAN status in cluster '$($clustername)'. Retry after resolving the vSAN health state. Exiting..." + Exit + } + if ( (Test-VsanObjectResync -cluster $clustername -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass) -ne 0) { + Write-PowerManagementLogMessage -Type ERROR -Message "vSAN object resynchronization failed. Check your environment and run the script again." + Exit + } + + # Start workflow for VCF prior version 4.5 + # Start vSphere HA + if (!$(Set-VsphereHA -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -enableHA)) { + Write-PowerManagementLogMessage -Type ERROR -Message "Unable to enable vSphere High Availability for cluster '$cluster'. Exiting..." + Exit + } - # End of startup + # Restore the DRS Automation Level to the mode backed up for Management Domain Cluster during shutdown + if ([string]::IsNullOrEmpty($DrsAutomationLevel)) { + Write-PowerManagementLogMessage -Type ERROR -Message "Unable to enable Drs Automation Level for cluster '$cluster'. Exiting..." + Exit + } else { + Set-DrsAutomationLevel -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -level $DrsAutomationLevel + } + + # Startup the vSphere Cluster Services Virtual Machines in the Management Workload Domain + Set-Retreatmode -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -cluster $clustername -mode disable + # Waiting for vCLS VMs to be started for ($retries*10) seconds + $counter = 0 + $retries = 10 + $sleepTime = 30 + while ($counter -ne $retries) { + $powerOnVMcount = (Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcfVcenterDetails.fqdn -user $vcfVcenterDetails.ssoAdmin -pass $vcfVcenterDetails.ssoAdminPass -pattern "(^vCLS-\w{8}-\w{4}-\w{4}-\w{4}-\w{12})|(^vCLS\s*\(\d+\))|(^vCLS\s*$)" -silence).count + if ( $powerOnVMcount -lt 3 ) { + Write-PowerManagementLogMessage -Type INFO -Message "vCLS retreat mode has been set. vCLS virtual machines startup will take some time. Please wait..." + Start-Sleep -s $sleepTime + $counter += 1 + } else { + Break + } + } + if ($counter -eq $retries) { + Write-PowerManagementLogMessage -Type ERROR -Message "vCLS virtual machines did not start within the expected time. Exiting..." + Exit + } + } + } + } + } + } + } + Write-PowerManagementLogMessage -Type INFO -Message "##################################################################################" if ([float]$vcfVersion -lt [float]4.5) { Write-PowerManagementLogMessage -Type INFO -Message "vSphere vSphere High Availability has been enabled by the script. Please disable it according to your environment's design." From 50b95fa793e7592d599ba201218af2b7a3844586 Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Thu, 15 Feb 2024 09:20:08 -0500 Subject: [PATCH 5/5] fix: added suport for vsan file services Added support to `PowerManagement-ManagmentDomain.ps1` and `PowerManagement-WorkloadDomain.ps1` for vSAN File Services to be excluded from customer virtual machines. Signed-off-by: Jared Burns --- SampleScripts/PowerManagement-ManagementDomain.ps1 | 6 ++++++ SampleScripts/PowerManagement-WorkloadDomain.ps1 | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/SampleScripts/PowerManagement-ManagementDomain.ps1 b/SampleScripts/PowerManagement-ManagementDomain.ps1 index 1ee21e8..9f43cc0 100644 --- a/SampleScripts/PowerManagement-ManagementDomain.ps1 +++ b/SampleScripts/PowerManagement-ManagementDomain.ps1 @@ -611,6 +611,12 @@ if ($PsBoundParameters.ContainsKey("shutdown") -or $PsBoundParameters.ContainsKe foreach ($vm in $vclsvms) { [Array]$vcfvms += $vm } + Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch all powered-on vSAN File Services virtual machines from server $($vcenter)..." + [Array]$vsanfsvms += Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -pattern "(vSAN File)" -silence + foreach ($vm in $vsanfsvms) { + [Array]$vcfvms += $vm + } + $customervms = $allvms | ? { $vcfvms -notcontains $_ } $vcfvms_string = $vcfvms -join "; " diff --git a/SampleScripts/PowerManagement-WorkloadDomain.ps1 b/SampleScripts/PowerManagement-WorkloadDomain.ps1 index 95f63de..a91164d 100644 --- a/SampleScripts/PowerManagement-WorkloadDomain.ps1 +++ b/SampleScripts/PowerManagement-WorkloadDomain.ps1 @@ -372,6 +372,11 @@ Try { foreach ($vm in $vclsvms) { [Array]$vcfvms += $vm } + Write-PowerManagementLogMessage -Type INFO -Message "Trying to fetch all powered-on vSAN File Services virtual machines from server $($vcenter)..." + [Array]$vsanfsvms += Get-VMsWithPowerStatus -powerstate "poweredon" -server $vcServer.fqdn -user $vcUser -pass $vcPass -pattern "(vSAN File)" -silence + foreach ($vm in $vsanfsvms) { + [Array]$vcfvms += $vm + } #Check if NSX-T manager VMs are running. If they are stopped skip NSX-T edge shutdown $nsxManagerPowerOnVMs = 0