module_utils/basic: add generic method for checking for missing params when argspec can not be used.

This commit is contained in:
Rene Moser 2016-02-04 22:54:03 +01:00
parent c3dd0213ef
commit 11522b22c3

View file

@ -1584,6 +1584,19 @@ class AnsibleModule(object):
print(self.jsonify(kwargs))
sys.exit(1)
def fail_on_missing_params(self, required_params=None):
''' This is for checking for required params when we can not check via argspec because we
need more information than is simply given in the argspec.
'''
if not required_params:
return
missing_params = []
for required_param in required_params:
if not self.params.get(required_param):
missing_params.append(required_param)
if missing_params:
self.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
def digest_from_file(self, filename, algorithm):
''' Return hex digest of local file for a digest_method specified by name, or None if file is not present. '''
if not os.path.exists(filename):