mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 11:10:21 -07:00
Bug fixes for na_ontap_cluster_ha.pya (#44188)
This commit is contained in:
parent
9858f41628
commit
9dac00fabe
1 changed files with 30 additions and 11 deletions
|
@ -12,7 +12,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
author: "Suhas Bangalore Shekar (bsuhas@netapp.com), Archana Ganesan (garchana@netapp.com)"
|
author: NetApp Ansible Team (ng-ansibleteam@netapp.com)
|
||||||
description:
|
description:
|
||||||
- "Enable or disable HA on a cluster"
|
- "Enable or disable HA on a cluster"
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
|
@ -44,6 +44,8 @@ import traceback
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
import ansible.module_utils.netapp as netapp_utils
|
import ansible.module_utils.netapp as netapp_utils
|
||||||
|
from ansible.module_utils.netapp_module import NetAppModule
|
||||||
|
|
||||||
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
|
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,9 +63,9 @@ class NetAppOntapClusterHA(object):
|
||||||
argument_spec=self.argument_spec,
|
argument_spec=self.argument_spec,
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
parameters = self.module.params
|
|
||||||
# set up state variable
|
self.na_helper = NetAppModule()
|
||||||
self.state = parameters['state']
|
self.parameters = self.na_helper.set_parameters(self.module.params)
|
||||||
|
|
||||||
if HAS_NETAPP_LIB is False:
|
if HAS_NETAPP_LIB is False:
|
||||||
self.module.fail_json(msg="the python NetApp-Lib module is required")
|
self.module.fail_json(msg="the python NetApp-Lib module is required")
|
||||||
|
@ -73,6 +75,7 @@ class NetAppOntapClusterHA(object):
|
||||||
def modify_cluster_ha(self, configure):
|
def modify_cluster_ha(self, configure):
|
||||||
"""
|
"""
|
||||||
Enable or disable HA on cluster
|
Enable or disable HA on cluster
|
||||||
|
:return: None
|
||||||
"""
|
"""
|
||||||
cluster_ha_modify = netapp_utils.zapi.NaElement.create_node_with_children(
|
cluster_ha_modify = netapp_utils.zapi.NaElement.create_node_with_children(
|
||||||
'cluster-ha-modify', **{'ha-configured': configure})
|
'cluster-ha-modify', **{'ha-configured': configure})
|
||||||
|
@ -84,22 +87,38 @@ class NetAppOntapClusterHA(object):
|
||||||
% (configure, to_native(error)),
|
% (configure, to_native(error)),
|
||||||
exception=traceback.format_exc())
|
exception=traceback.format_exc())
|
||||||
|
|
||||||
|
def get_cluster_ha_enabled(self):
|
||||||
|
"""
|
||||||
|
Get current cluster HA details
|
||||||
|
:return: dict if enabled, None if disabled
|
||||||
|
"""
|
||||||
|
cluster_ha_get = netapp_utils.zapi.NaElement('cluster-ha-get')
|
||||||
|
try:
|
||||||
|
result = self.server.invoke_successfully(cluster_ha_get,
|
||||||
|
enable_tunneling=True)
|
||||||
|
except netapp_utils.zapi.NaApiError as error:
|
||||||
|
self.module.fail_json(msg='Error fetching cluster HA details',
|
||||||
|
exception=traceback.format_exc())
|
||||||
|
cluster_ha_info = result.get_child_by_name('attributes').get_child_by_name('cluster-ha-info')
|
||||||
|
if cluster_ha_info.get_child_content('ha-configured') == 'true':
|
||||||
|
return {'ha-configured': True}
|
||||||
|
return None
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
"""
|
"""
|
||||||
Apply action to cluster HA
|
Apply action to cluster HA
|
||||||
"""
|
"""
|
||||||
changed = False
|
|
||||||
results = netapp_utils.get_cserver(self.server)
|
results = netapp_utils.get_cserver(self.server)
|
||||||
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
|
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
|
||||||
netapp_utils.ems_log_event("na_ontap_cluster", cserver)
|
netapp_utils.ems_log_event("na_ontap_cluster_ha", cserver)
|
||||||
if self.state == 'present':
|
current = self.get_cluster_ha_enabled()
|
||||||
|
cd_action = self.na_helper.get_cd_action(current, self.parameters)
|
||||||
|
if cd_action == 'create':
|
||||||
self.modify_cluster_ha("true")
|
self.modify_cluster_ha("true")
|
||||||
changed = True
|
elif cd_action == 'delete':
|
||||||
elif self.state == 'absent':
|
|
||||||
self.modify_cluster_ha("false")
|
self.modify_cluster_ha("false")
|
||||||
changed = True
|
|
||||||
|
|
||||||
self.module.exit_json(changed=changed)
|
self.module.exit_json(changed=self.na_helper.changed)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue