diff options
author | Chris Archibald <carchi@netapp.com> | 2019-03-06 17:20:00 +0100 |
---|---|---|
committer | John R Barker <john@johnrbarker.com> | 2019-03-06 17:20:00 +0100 |
commit | 9c5464944973f77ceb9fd680680b32f1e1a24823 (patch) | |
tree | 69e442163232d02b68d4be634b05d6075fcb2cd9 | |
parent | Add option for tower inventory to give general metadata (#52747) (diff) | |
download | ansible-9c5464944973f77ceb9fd680680b32f1e1a24823.tar.xz ansible-9c5464944973f77ceb9fd680680b32f1e1a24823.zip |
Bug Fix: na_elementsw_cluster_pair.py check if clusters are allready paired (#52379)
* Revert "changes to clusteR"
This reverts commit 33ee1b71e4bc8435fb315762a871f8c4cb6c5f80.
* Revert "Revert "changes to clusteR""
This reverts commit f1104a37b42886aebb4d2b2ab27c91c96d97858a.
* bug fix
* bug fixes
* bug fix
-rw-r--r-- | lib/ansible/modules/storage/netapp/na_elementsw_cluster_pair.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/ansible/modules/storage/netapp/na_elementsw_cluster_pair.py b/lib/ansible/modules/storage/netapp/na_elementsw_cluster_pair.py index 998f20abe2..f00d843e94 100644 --- a/lib/ansible/modules/storage/netapp/na_elementsw_cluster_pair.py +++ b/lib/ansible/modules/storage/netapp/na_elementsw_cluster_pair.py @@ -127,16 +127,26 @@ class ElementSWClusterPair(object): self.dest_elem = netapp_utils.create_sf_connection(module=self.module) self.dest_elementsw_helper = NaElementSWModule(self.dest_elem) - def check_if_already_paired(self): + def check_if_already_paired(self, paired_clusters, hostname): + for pair in paired_clusters.cluster_pairs: + if pair.mvip == hostname: + return pair.cluster_pair_id + return None + + def get_src_pair_id(self): """ Check for idempotency """ # src cluster and dest cluster exist paired_clusters = self.elem.list_cluster_pairs() - for pair in paired_clusters.cluster_pairs: - if pair.mvip == self.parameters['dest_mvip']: - return pair.cluster_pair_id - return None + return self.check_if_already_paired(paired_clusters, self.parameters['dest_mvip']) + + def get_dest_pair_id(self): + """ + Getting destination cluster_pair_id + """ + paired_clusters = self.dest_elem.list_cluster_pairs() + return self.check_if_already_paired(paired_clusters, self.parameters['hostname']) def pair_clusters(self): """ @@ -152,13 +162,13 @@ class ElementSWClusterPair(object): self.parameters['dest_mvip']), exception=to_native(err)) - def unpair_clusters(self, pair_id): + def unpair_clusters(self, pair_id_source, pair_id_dest): """ Delete cluster pair """ try: - self.elem.remove_cluster_pair(cluster_pair_id=pair_id) - self.dest_elem.remove_cluster_pair(cluster_pair_id=pair_id) + self.elem.remove_cluster_pair(cluster_pair_id=pair_id_source) + self.dest_elem.remove_cluster_pair(cluster_pair_id=pair_id_dest) except solidfire.common.ApiServerError as err: self.module.fail_json(msg="Error unpairing cluster %s and %s" % (self.parameters['hostname'], @@ -169,13 +179,16 @@ class ElementSWClusterPair(object): """ Call create / delete cluster pair methods """ - pair_id = self.check_if_already_paired() + pair_id_source = self.get_src_pair_id() + # If already paired, find the cluster_pair_id of destination cluster + if pair_id_source: + pair_id_dest = self.get_dest_pair_id() # calling helper to determine action - cd_action = self.na_helper.get_cd_action(pair_id, self.parameters) + cd_action = self.na_helper.get_cd_action(pair_id_source, self.parameters) if cd_action == "create": self.pair_clusters() elif cd_action == "delete": - self.unpair_clusters(pair_id) + self.unpair_clusters(pair_id_source, pair_id_dest) self.module.exit_json(changed=self.na_helper.changed) |