From e620e2760927eb1cedbf7505542ed94191d6881b Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Tue, 4 Jun 2019 10:52:16 +0530 Subject: [PATCH] PR to fix the bug 57215 & 56300 under Nios Host_Record module (#57221) * fix bug 57215 & 56300 Signed-off-by: Sumit Jaiswal * fix bug 57215 & 56300 Signed-off-by: Sumit Jaiswal * shippable error fix Signed-off-by: Sumit Jaiswal * review comment fix Signed-off-by: Sumit Jaiswal --- .../module_utils/net_tools/nios/api.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/net_tools/nios/api.py b/lib/ansible/module_utils/net_tools/nios/api.py index 6a88bb095c3..9bcd510b81d 100644 --- a/lib/ansible/module_utils/net_tools/nios/api.py +++ b/lib/ansible/module_utils/net_tools/nios/api.py @@ -265,17 +265,34 @@ class WapiModule(WapiBase): else: proposed_object[key] = self.module.params[key] + # If configure_by_dns is set to False, then delete the default dns set in the param else throw exception + if not proposed_object.get('configure_for_dns') and proposed_object.get('view') == 'default'\ + and ib_obj_type == NIOS_HOST_RECORD: + del proposed_object['view'] + elif not proposed_object.get('configure_for_dns') and proposed_object.get('view') != 'default'\ + and ib_obj_type == NIOS_HOST_RECORD: + self.module.fail_json(msg='DNS Bypass is not allowed if DNS view is set other than \'default\'') + if ib_obj_ref: if len(ib_obj_ref) > 1: for each in ib_obj_ref: - if ('ipv4addr' in each) and ('ipv4addr' in proposed_object)\ - and each['ipv4addr'] == proposed_object['ipv4addr']: + # To check for existing A_record with same name with input A_record by IP + if each.get('ipv4addr') and each.get('ipv4addr') == proposed_object.get('ipv4addr'): current_object = each + # To check for existing Host_record with same name with input Host_record by IP + elif each.get('ipv4addrs')[0].get('ipv4addr') and each.get('ipv4addrs')[0].get('ipv4addr')\ + == proposed_object.get('ipv4addrs')[0].get('ipv4addr'): + current_object = each + # Else set the current_object with input value + else: + current_object = obj_filter + ref = None else: current_object = ib_obj_ref[0] if 'extattrs' in current_object: current_object['extattrs'] = flatten_extattrs(current_object['extattrs']) - ref = current_object.pop('_ref') + if current_object.get('_ref'): + ref = current_object.pop('_ref') else: current_object = obj_filter ref = None