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

vmware_cluster_ha - add set of heartbeat datastores #1732

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions changelogs/fragments/1732-vmware_cluster_ha.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- vmware_cluster_ha - Add the possibility to set the heartbeat datastores of an cluster. (https://github.com/ansible-collections/community.vmware/pull/1732)
45 changes: 45 additions & 0 deletions plugins/modules/vmware_cluster_ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@
- A dictionary of advanced HA settings.
default: {}
type: dict
heartbeat_datastores:
description:
- A list of the heartbeat datastores.
- If list ist [] then all datastores of the cluster will be set as heartbeat_datastores.
type: list
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
type: list
version_added: '3.8.0'
type: list

elements: str
heartbeat_datastore_candidate_policy:
description:
- Heartbeat datastore selection policy
- allFeasibleDs -> Automatically select datastores accessible from the hosts. Causes that C(heartbeat_datastores) will be ignored.
- userSelectedDs -> Use datastores only from the specified list.
- allFeasibleDsWithUserPreference -> Use datastores from the specified list and complement automatically if needed.
type: str
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
type: str
version_added: '3.8.0'
type: str

choices: ['allFeasibleDs', 'userSelectedDs', 'allFeasibleDsWithUserPreference']
apd_response:
description:
- VM storage protection setting for storage failures categorized as All Paths Down (APD).
Expand Down Expand Up @@ -256,6 +270,7 @@
vmware_argument_spec,
wait_for_task,
option_diff,
find_datastore_by_name,
)
from ansible.module_utils._text import to_native

Expand Down Expand Up @@ -293,6 +308,22 @@ def __init__(self, module):
else:
self.changed_advanced_settings = None

if self.params.get('heartbeat_datastore_candidate_policy') == "allFeasibleDs":
self.heartbeat_datastores_var = None
else:
self.heartbeat_datastores_var = self.params.get('heartbeat_datastores')

if self.heartbeat_datastores_var == []:
self.heartbeat_datastores = self.cluster.datastore
else:
self.heartbeat_datastores = []
for ds_name in (self.heartbeat_datastores_var or []):
ds = find_datastore_by_name(self.content, ds_name, self.datacenter)
if ds is None:
self.module.fail_json(msg="Datastore %s does not exist." % ds_name)
else:
self.heartbeat_datastores.append(ds)

def get_failover_hosts(self):
"""
Get failover hosts for failover_host_admission_control policy
Expand Down Expand Up @@ -324,6 +355,10 @@ def check_ha_config_diff(self):
das_config.vmMonitoring != self.params.get("ha_vm_monitoring")
or das_config.hostMonitoring != self.params.get("ha_host_monitoring")
or das_config.admissionControlEnabled != self.ha_admission_control
or self.params.get("heartbeat_datastore_candidate_policy") # Only needed if no default value is there
and das_config.heartbeat_datastore_candidate_policy != self.params.get("heartbeat_datastore_candidate_policy")
or self.heartbeat_datastores_var # Only needed if no default value is there
and len([ds for ds in das_config.heartbeatDatastore if ds.name not in set(ds.name for ds in self.heartbeat_datastores)]) != 0
or das_config.defaultVmSettings.restartPriority
!= self.params.get("ha_restart_priority")
or das_config.defaultVmSettings.isolationResponse
Expand Down Expand Up @@ -447,6 +482,12 @@ def configure_ha(self):
cluster_config_spec.dasConfig.hostMonitoring = self.params.get('ha_host_monitoring')
cluster_config_spec.dasConfig.vmMonitoring = self.params.get('ha_vm_monitoring')

if self.params.get("heartbeat_datastore_candidate_policy"):
cluster_config_spec.dasConfig.hBDatastoreCandidatePolicy = self.params.get("heartbeat_datastore_candidate_policy")

if self.heartbeat_datastores_var:
cluster_config_spec.dasConfig.heartbeatDatastore = self.heartbeat_datastores

if self.changed_advanced_settings:
cluster_config_spec.dasConfig.option = self.changed_advanced_settings

Expand Down Expand Up @@ -482,6 +523,10 @@ def main():
default='none',
choices=['none', 'powerOff', 'shutdown']),
advanced_settings=dict(type='dict', default=dict(), required=False),
heartbeat_datastores=dict(type='list', elements='str', required=False),
heartbeat_datastore_candidate_policy=dict(type='str',
required=False,
choices=['allFeasibleDs', 'userSelectedDs', 'allFeasibleDsWithUserPreference']),
# HA VM Monitoring related parameters
ha_vm_monitoring=dict(type='str',
choices=['vmAndAppMonitoring', 'vmMonitoringOnly', 'vmMonitoringDisabled'],
Expand Down