mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
module_utils/manageiq: add find_collection_resource_or_fail
This commit is contained in:
@@ -149,3 +149,17 @@ class ManageIQ(object):
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg="failed to find resource {error}".format(error=e))
|
||||
return vars(entity)
|
||||
|
||||
def find_collection_resource_or_fail(self, collection_name, **params):
|
||||
""" Searches the collection resource by the collection name and the param passed.
|
||||
|
||||
Returns:
|
||||
the resource as an object if it exists in manageiq, Fail otherwise.
|
||||
"""
|
||||
resource = self.find_collection_resource_by(collection_name, **params)
|
||||
if resource:
|
||||
return resource
|
||||
else:
|
||||
msg = "{collection_name} where {params} does not exist in manageiq".format(
|
||||
collection_name=collection_name, params=str(params))
|
||||
self.module.fail_json(msg=msg)
|
||||
|
||||
Reference in New Issue
Block a user