From b9b1e294d7151aa2b0dbeeb597a7a2e3c80ecbed Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 10 Jun 2015 21:22:57 +0200 Subject: [PATCH 1/2] cloudstack: add get_or_failback() --- lib/ansible/module_utils/cloudstack.py | 8 ++++++++ v1/ansible/module_utils/cloudstack.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 13d4c59a014..5b67c745c4b 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -77,6 +77,14 @@ class AnsibleCloudStack: else: self.cs = CloudStack(**read_config()) + + def get_or_fallback(self, key=None, fallback_key=None): + value = self.module.params.get(key) + if not value: + value = self.module.params.get(fallback_key) + return value + + # TODO: for backward compatibility only, remove if not used anymore def _has_changed(self, want_dict, current_dict, only_keys=None): return self.has_changed(want_dict=want_dict, current_dict=current_dict, only_keys=only_keys) diff --git a/v1/ansible/module_utils/cloudstack.py b/v1/ansible/module_utils/cloudstack.py index 13d4c59a014..5b67c745c4b 100644 --- a/v1/ansible/module_utils/cloudstack.py +++ b/v1/ansible/module_utils/cloudstack.py @@ -77,6 +77,14 @@ class AnsibleCloudStack: else: self.cs = CloudStack(**read_config()) + + def get_or_fallback(self, key=None, fallback_key=None): + value = self.module.params.get(key) + if not value: + value = self.module.params.get(fallback_key) + return value + + # TODO: for backward compatibility only, remove if not used anymore def _has_changed(self, want_dict, current_dict, only_keys=None): return self.has_changed(want_dict=want_dict, current_dict=current_dict, only_keys=only_keys) From 79527235307935c3867cd8c8120d86df2c7d801f Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 26 Jun 2015 09:24:02 +0200 Subject: [PATCH 2/2] cloudstack: fix domain name is not unique, use full path --- lib/ansible/module_utils/cloudstack.py | 7 ++++--- v1/ansible/module_utils/cloudstack.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 5b67c745c4b..752defec2b6 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -274,12 +274,13 @@ class AnsibleCloudStack: return None args = {} - args['name'] = domain args['listall'] = True domains = self.cs.listDomains(**args) if domains: - self.domain = domains['domain'][0] - return self._get_by_key(key, self.domain) + for d in domains['domain']: + if d['path'].lower() in [ domain.lower(), "root/" + domain.lower(), "root" + domain.lower() ]: + self.domain = d + return self._get_by_key(key, self.domain) self.module.fail_json(msg="Domain '%s' not found" % domain) diff --git a/v1/ansible/module_utils/cloudstack.py b/v1/ansible/module_utils/cloudstack.py index 5b67c745c4b..752defec2b6 100644 --- a/v1/ansible/module_utils/cloudstack.py +++ b/v1/ansible/module_utils/cloudstack.py @@ -274,12 +274,13 @@ class AnsibleCloudStack: return None args = {} - args['name'] = domain args['listall'] = True domains = self.cs.listDomains(**args) if domains: - self.domain = domains['domain'][0] - return self._get_by_key(key, self.domain) + for d in domains['domain']: + if d['path'].lower() in [ domain.lower(), "root/" + domain.lower(), "root" + domain.lower() ]: + self.domain = d + return self._get_by_key(key, self.domain) self.module.fail_json(msg="Domain '%s' not found" % domain)