From 88540d3cdcef13775664b83b717b32c41137dd38 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 24 Apr 2015 19:04:33 +0200 Subject: [PATCH] cloudstack: add _get_by_key() to utils Generic method to get the whole dict or just a singe value by key if found. --- lib/ansible/module_utils/cloudstack.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 627ef9655e2..9ef9d229ba7 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -69,6 +69,14 @@ class AnsibleCloudStack: self.cs = CloudStack(**read_config()) + def _get_by_key(self, key=None, my_dict={}): + if key: + if key in my_dict: + return my_dict[key] + self.module.fail_json(msg="Something went wrong: %s not found" % key) + return my_dict + + def get_project_id(self): if self.project_id: return self.project_id