Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run command to restart HA on a cluster #276

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions Microsoft.AVS.Management/Microsoft.AVS.Management.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,135 +10,135 @@

# Script module or binary module file associated with this manifest.
RootModule = 'Microsoft.AVS.Management.psm1'

# Version number of this module.
ModuleVersion = '7.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '84d7f529-e6a8-4b7e-99b4-dafc636ffad2'

# Author of this module
Author = 'Microsoft'

# Company or vendor of this module
CompanyName = 'Microsoft'

# Copyright statement for this module
Copyright = '(c) Microsoft. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Various cmdlets for adminstrator level tasks in managing Azure VMware Solutions'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.4'

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'VMware.vSphere.SsoAdmin'; RequiredVersion = '1.3.9'; },
@{ModuleName = 'VMware.VimAutomation.Core'; RequiredVersion = '13.2.0.22643732'; },
@{ModuleName = 'VMware.VimAutomation.Storage'; RequiredVersion = '13.2.0.22643728'; },
RequiredModules = @(@{ModuleName = 'VMware.vSphere.SsoAdmin'; RequiredVersion = '1.3.9'; },
@{ModuleName = 'VMware.VimAutomation.Core'; RequiredVersion = '13.2.0.22643732'; },
@{ModuleName = 'VMware.VimAutomation.Storage'; RequiredVersion = '13.2.0.22643728'; },
@{ModuleName = 'Posh-SSH'; RequiredVersion = '3.1.3'; })

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
ScriptsToProcess = 'Classes.ps1'

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Set-VMStoragePolicy', 'Set-LocationStoragePolicy',
'Set-ClusterDefaultStoragePolicy', 'Get-StoragePolicies',
'New-LDAPIdentitySource', 'Debug-LDAPSIdentitySources',
'New-LDAPSIdentitySource', 'Update-IdentitySourceCertificates',
'Update-IdentitySourceCredential', 'Get-ExternalIdentitySources',
'Remove-ExternalIdentitySources', 'Add-GroupToCloudAdmins',
'Remove-GroupFromCloudAdmins', 'Get-CloudAdminGroups',
'Set-ToolsRepo', 'Set-vSANCompressDedupe', 'New-AVSStoragePolicy',
'Remove-AVSStoragePolicy', 'Set-CustomDRS',
FunctionsToExport = 'Set-VMStoragePolicy', 'Set-LocationStoragePolicy',
'Set-ClusterDefaultStoragePolicy', 'Get-StoragePolicies',
'New-LDAPIdentitySource', 'Debug-LDAPSIdentitySources',
'New-LDAPSIdentitySource', 'Update-IdentitySourceCertificates',
'Update-IdentitySourceCredential', 'Get-ExternalIdentitySources',
'Remove-ExternalIdentitySources', 'Add-GroupToCloudAdmins',
'Remove-GroupFromCloudAdmins', 'Get-CloudAdminGroups',
'Set-ToolsRepo', 'Set-vSANCompressDedupe', 'New-AVSStoragePolicy',
'Remove-AVSStoragePolicy', 'Set-CustomDRS',
'Set-AVSVSANClusterUNMAPTRIM', 'Get-AVSVSANClusterUNMAPTRIM',
'Remove-CustomRole'
'Remove-CustomRole', 'Restart-ClusterHA'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'VMware','PowerCLI','Azure','AVS'

# A URL to the license for this module.
# LicenseUri = ''

# A URL to the main website for this project.
ProjectUri = 'https://github.com/Azure/Microsoft.AVS.Management'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}
47 changes: 47 additions & 0 deletions Microsoft.AVS.Management/Microsoft.AVS.Management.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2628,3 +2628,50 @@ function Remove-CustomRole {
}
}

<#
.Synopsis
This function allows the customer to restart HA on a cluster. This might be needed to clear HA alarms.
.EXAMPLE
Once the function is imported: Restart-ClusterHA -cluster_name "Cluster-1"
#>
function Restart-ClusterHA {
[AVSAttribute(30, UpdatesSDDC = $false)]
param(
[Parameter(Mandatory = $true,
HelpMessage = "What cluster to restart HA on.")]
[String]
$cluster_name
)

# Get the cluster object
try {
$cluster = Get-Cluster -Name $cluster_name -ErrorAction Stop
}
catch {
Write-Error "Cluster $cluster_name not found."
return
}

$ha_status = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we evaluate whether HA is enabled first to ascertain what action should be taken? As in, if previous run command failed for whatever reason, couldn't it be reasoned that our default action should be to turn on HA if we see that it is disabled?

Also, if we enable this, we should have monitoring in place to catch any SDDC's that have HA disabled for an extended period of time. If nothing, but to have a point of reference should customer suffer from an actual HA event, but were disabled when such event occurred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have this as an internal geneva action?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commandlet could be exposed as a Geneva Action if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@et1975 I've been asking if Geneva and Run commands could share code but hadn't found a way. How can I do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gungazoo Let's take that to Teams, this is a public repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zsoldier -- Since it is the customer cycling it, I would say continue if HA is disabled. We should have a monitor if HA is disabled for a period of time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we have a monitor prior to this, I'm ok with proceeding.


# Disable HA
$ha_status = ($cluster | Set-Cluster -HAEnabled:$false -Confirm:$false).HAEnabled

if ($ha_status -eq $true) {
Write-Error "Failed to disable HA on cluster $cluster_name"
return
}

# Enable HA
$ha_status = ""
$ha_status = ($cluster | Set-Cluster -HAEnabled:$true -Confirm:$false).HAEnabled

if ($ha_status -eq $false) {
# Try again to restart HA
$ha_status = ($cluster | Set-Cluster -HAEnabled:$true -Confirm:$false).HAEnabled
if ($ha_status -eq $false) {
Write-Error "Failed to enable HA on cluster $cluster_name"
return
}
}
}