From 8989abb814d54efbd341cc67741d9e360e57b56a Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Thu, 11 May 2023 18:14:24 +0200 Subject: [PATCH 1/7] Add the possibility to set the heartbeat datastores of an cluster --- plugins/modules/vmware_cluster_ha.py | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py index d9896caa24..9066f2ddec 100644 --- a/plugins/modules/vmware_cluster_ha.py +++ b/plugins/modules/vmware_cluster_ha.py @@ -43,7 +43,7 @@ - Whether HA restarts virtual machines after a host fails. - If set to C(enabled), HA restarts virtual machines after a host fails. - If set to C(disabled), HA does not restart virtual machines after a host fails. - - If C(enable) is set to C(false), then this value is ignored. + - If C(enable) is set to C(False), then this value is ignored. type: str choices: [ 'enabled', 'disabled' ] default: 'enabled' @@ -53,7 +53,7 @@ - If set to C(vmAndAppMonitoring), HA response to both virtual machine and application heartbeat failure. - If set to C(vmMonitoringDisabled), virtual machine health monitoring is disabled. - If set to C(vmMonitoringOnly), HA response to virtual machine heartbeat failure. - - If C(enable) is set to C(false), then this value is ignored. + - If C(enable) is set to C(False), then this value is ignored. type: str choices: ['vmAndAppMonitoring', 'vmMonitoringOnly', 'vmMonitoringDisabled'] default: 'vmMonitoringDisabled' @@ -170,6 +170,11 @@ - A dictionary of advanced HA settings. default: {} type: dict + heartbeat_datastores: + description: + - A list of the heartbeat datastores. + type: list + elements: str apd_response: description: - VM storage protection setting for storage failures categorized as All Paths Down (APD). @@ -220,7 +225,7 @@ password: "{{ vcenter_password }}" datacenter_name: DC0 cluster_name: "{{ cluster_name }}" - enable: true + enable: True ha_vm_monitoring: vmMonitoringOnly delegate_to: localhost @@ -233,7 +238,7 @@ cluster_name: cluster enable: true reservation_based_admission_control: - auto_compute_percentages: false + auto_compute_percentages: False failover_level: 1 cpu_failover_resources_percent: 50 memory_failover_resources_percent: 50 @@ -256,6 +261,7 @@ vmware_argument_spec, wait_for_task, option_diff, + find_datastore_by_name, ) from ansible.module_utils._text import to_native @@ -293,6 +299,15 @@ def __init__(self, module): else: self.changed_advanced_settings = None + self.heartbeat_datastore_names = self.params.get('heartbeat_datastores') or [] + self.heartbeat_datastores = [] + for ds_name in self.heartbeat_datastore_names: + 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 @@ -324,6 +339,7 @@ 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 [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 @@ -447,6 +463,11 @@ 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.heartbeat_datastores: + cluster_config_spec.dasConfig.heartbeatDatastore = self.heartbeat_datastores + else: + cluster_config_spec.dasConfig.heartbeatDatastore = self.cluster.configurationEx.dasConfig.heartbeatDatastore + if self.changed_advanced_settings: cluster_config_spec.dasConfig.option = self.changed_advanced_settings @@ -482,6 +503,7 @@ 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), # HA VM Monitoring related parameters ha_vm_monitoring=dict(type='str', choices=['vmAndAppMonitoring', 'vmMonitoringOnly', 'vmMonitoringDisabled'], From a8799c4704d059ef46300f01cbc7c21a48b0a62c Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Thu, 11 May 2023 18:17:52 +0200 Subject: [PATCH 2/7] Add the changelog File --- changelogs/fragments/-vmware_cluster_ha.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/-vmware_cluster_ha.yaml diff --git a/changelogs/fragments/-vmware_cluster_ha.yaml b/changelogs/fragments/-vmware_cluster_ha.yaml new file mode 100644 index 0000000000..55570b71ac --- /dev/null +++ b/changelogs/fragments/-vmware_cluster_ha.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - vmware_cluster_ha - Add the possibility to set the heartbeat datastores of an cluster. \ No newline at end of file From e343d4c58ed057efb52cbc57fecea020ee25697c Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Thu, 11 May 2023 19:29:40 +0200 Subject: [PATCH 3/7] replace False/True with false/true --- plugins/modules/vmware_cluster_ha.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py index 9066f2ddec..560d569b31 100644 --- a/plugins/modules/vmware_cluster_ha.py +++ b/plugins/modules/vmware_cluster_ha.py @@ -43,7 +43,7 @@ - Whether HA restarts virtual machines after a host fails. - If set to C(enabled), HA restarts virtual machines after a host fails. - If set to C(disabled), HA does not restart virtual machines after a host fails. - - If C(enable) is set to C(False), then this value is ignored. + - If C(enable) is set to C(false), then this value is ignored. type: str choices: [ 'enabled', 'disabled' ] default: 'enabled' @@ -53,7 +53,7 @@ - If set to C(vmAndAppMonitoring), HA response to both virtual machine and application heartbeat failure. - If set to C(vmMonitoringDisabled), virtual machine health monitoring is disabled. - If set to C(vmMonitoringOnly), HA response to virtual machine heartbeat failure. - - If C(enable) is set to C(False), then this value is ignored. + - If C(enable) is set to C(false), then this value is ignored. type: str choices: ['vmAndAppMonitoring', 'vmMonitoringOnly', 'vmMonitoringDisabled'] default: 'vmMonitoringDisabled' @@ -225,7 +225,7 @@ password: "{{ vcenter_password }}" datacenter_name: DC0 cluster_name: "{{ cluster_name }}" - enable: True + enable: true ha_vm_monitoring: vmMonitoringOnly delegate_to: localhost @@ -238,7 +238,7 @@ cluster_name: cluster enable: true reservation_based_admission_control: - auto_compute_percentages: False + auto_compute_percentages: false failover_level: 1 cpu_failover_resources_percent: 50 memory_failover_resources_percent: 50 From 981647e69020fa2ac7354fadbae36562d4098bed Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Fri, 12 May 2023 09:48:32 +0200 Subject: [PATCH 4/7] Add the Pull Request Nr --- changelogs/fragments/-vmware_cluster_ha.yaml | 3 --- changelogs/fragments/1732-vmware_cluster_ha.yaml | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 changelogs/fragments/-vmware_cluster_ha.yaml create mode 100644 changelogs/fragments/1732-vmware_cluster_ha.yaml diff --git a/changelogs/fragments/-vmware_cluster_ha.yaml b/changelogs/fragments/-vmware_cluster_ha.yaml deleted file mode 100644 index 55570b71ac..0000000000 --- a/changelogs/fragments/-vmware_cluster_ha.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -minor_changes: - - vmware_cluster_ha - Add the possibility to set the heartbeat datastores of an cluster. \ No newline at end of file diff --git a/changelogs/fragments/1732-vmware_cluster_ha.yaml b/changelogs/fragments/1732-vmware_cluster_ha.yaml new file mode 100644 index 0000000000..41be3748c0 --- /dev/null +++ b/changelogs/fragments/1732-vmware_cluster_ha.yaml @@ -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) From 4744cda9b7fcfa4fc254b1e2b5d2d43922ba9c86 Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Tue, 23 May 2023 15:37:41 +0200 Subject: [PATCH 5/7] Missing ask for len --- plugins/modules/vmware_cluster_ha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py index 560d569b31..e684bba371 100644 --- a/plugins/modules/vmware_cluster_ha.py +++ b/plugins/modules/vmware_cluster_ha.py @@ -339,7 +339,7 @@ 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 [ds for ds in das_config.heartbeatDatastore if ds.name not in set(ds.name for ds in self.heartbeat_datastores)] != 0 + or 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 From e81508660892f29567ec10bb929b42085c4bfa63 Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Wed, 21 Jun 2023 17:20:03 +0200 Subject: [PATCH 6/7] add the thing @mariolenz wanted and the posibility to set the hb ds candidate policy --- plugins/modules/vmware_cluster_ha.py | 47 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py index e684bba371..4997e4250f 100644 --- a/plugins/modules/vmware_cluster_ha.py +++ b/plugins/modules/vmware_cluster_ha.py @@ -173,8 +173,17 @@ 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 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 + choices: ['allFeasibleDs', 'userSelectedDs', 'allFeasibleDsWithUserPreference'] apd_response: description: - VM storage protection setting for storage failures categorized as All Paths Down (APD). @@ -299,14 +308,21 @@ def __init__(self, module): else: self.changed_advanced_settings = None - self.heartbeat_datastore_names = self.params.get('heartbeat_datastores') or [] - self.heartbeat_datastores = [] - for ds_name in self.heartbeat_datastore_names: - 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) + 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.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): """ @@ -339,7 +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 len([ds for ds in das_config.heartbeatDatastore if ds.name not in set(ds.name for ds in self.heartbeat_datastores)]) != 0 + 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 @@ -463,10 +482,11 @@ 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.heartbeat_datastores: + 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 - else: - cluster_config_spec.dasConfig.heartbeatDatastore = self.cluster.configurationEx.dasConfig.heartbeatDatastore if self.changed_advanced_settings: cluster_config_spec.dasConfig.option = self.changed_advanced_settings @@ -504,6 +524,9 @@ def main(): 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'], From 97f93abbfd8937594e4d4b3ff6b9419cf0a97daf Mon Sep 17 00:00:00 2001 From: "nina.loser" Date: Thu, 22 Jun 2023 09:38:31 +0200 Subject: [PATCH 7/7] self to much --- plugins/modules/vmware_cluster_ha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py index 4997e4250f..5787843942 100644 --- a/plugins/modules/vmware_cluster_ha.py +++ b/plugins/modules/vmware_cluster_ha.py @@ -317,7 +317,7 @@ def __init__(self, module): self.heartbeat_datastores = self.cluster.datastore else: self.heartbeat_datastores = [] - for ds_name in (self.self.heartbeat_datastores_var or []): + 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)