Bug fixes for na_ontap_cluster_ha.pya (#44188)

pull/43711/head
Chris Archibald 6 years ago committed by John R Barker
parent 9858f41628
commit 9dac00fabe

@ -12,7 +12,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = '''
author: "Suhas Bangalore Shekar (bsuhas@netapp.com), Archana Ganesan (garchana@netapp.com)"
author: NetApp Ansible Team (ng-ansibleteam@netapp.com)
description:
- "Enable or disable HA on a cluster"
extends_documentation_fragment:
@ -44,6 +44,8 @@ import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
from ansible.module_utils.netapp_module import NetAppModule
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@ -61,9 +63,9 @@ class NetAppOntapClusterHA(object):
argument_spec=self.argument_spec,
supports_check_mode=True
)
parameters = self.module.params
# set up state variable
self.state = parameters['state']
self.na_helper = NetAppModule()
self.parameters = self.na_helper.set_parameters(self.module.params)
if HAS_NETAPP_LIB is False:
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):
"""
Enable or disable HA on cluster
:return: None
"""
cluster_ha_modify = netapp_utils.zapi.NaElement.create_node_with_children(
'cluster-ha-modify', **{'ha-configured': configure})
@ -84,22 +87,38 @@ class NetAppOntapClusterHA(object):
% (configure, to_native(error)),
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):
"""
Apply action to cluster HA
"""
changed = False
results = netapp_utils.get_cserver(self.server)
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
netapp_utils.ems_log_event("na_ontap_cluster", cserver)
if self.state == 'present':
netapp_utils.ems_log_event("na_ontap_cluster_ha", cserver)
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")
changed = True
elif self.state == 'absent':
elif cd_action == 'delete':
self.modify_cluster_ha("false")
changed = True
self.module.exit_json(changed=changed)
self.module.exit_json(changed=self.na_helper.changed)
def main():

Loading…
Cancel
Save