From aa8648425bbf562f0b8d7e26a46f51c9ffb43b92 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
Date: Mon, 4 Oct 2021 14:06:43 -0300
Subject: [PATCH] templates: Use IPAAnsibleModule params_fail_used_invalid.

Modify new module templates to use IPAAnsibleModule method
`params_fail_used_invalid` to check for invalid parameter use for
a given state/action.
---
 utils/templates/ipamodule+member.py.in | 6 +-----
 utils/templates/ipamodule.py.in        | 6 +-----
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/utils/templates/ipamodule+member.py.in b/utils/templates/ipamodule+member.py.in
index 7e7ad8ea..d3438b1b 100644
--- a/utils/templates/ipamodule+member.py.in
+++ b/utils/templates/ipamodule+member.py.in
@@ -185,11 +185,7 @@ def main():
         if action == "$name":
             invalid.append("PARAMETER2")
 
-    for x in invalid:
-        if vars()[x] is not None:
-            ansible_module.fail_json(
-                msg="Argument '%s' can not be used with action "
-                "'%s' and state '%s'" % (x, action, state))
+    ansible_module.params_fail_used_invalid(invalid, state, action)
 
     # Init
 
diff --git a/utils/templates/ipamodule.py.in b/utils/templates/ipamodule.py.in
index b179a0b8..e305c976 100644
--- a/utils/templates/ipamodule.py.in
+++ b/utils/templates/ipamodule.py.in
@@ -151,11 +151,7 @@ def main():
             ansible_module.fail_json(msg="No name given.")
         invalid = ["PARAMETER1", "PARAMETER2"]
 
-    for x in invalid:
-        if vars()[x] is not None:
-            ansible_module.fail_json(
-                msg="Argument '%s' can not be used with state '%s'" %
-                (x, state))
+    ansible_module.params_fail_used_invalid(invalid, state)
 
     # Init
 
-- 
GitLab