diff options
author | Rene Moser <mail@renemoser.net> | 2015-05-03 14:34:25 +0200 |
---|---|---|
committer | Rene Moser <mail@renemoser.net> | 2015-05-03 14:34:25 +0200 |
commit | af74d7f1a961f2d1cccb06f1d911864c16ef9e86 (patch) | |
tree | 80521448f302b1a1155b358f8fe6dfaf71f3e333 | |
parent | 034ac8ae78553678716682cd4cd68cfb61873fe9 (diff) | |
download | ansible-af74d7f1a961f2d1cccb06f1d911864c16ef9e86.tar.gz |
cloudstack: add get_domain() and get_account() to utils
-rw-r--r-- | lib/ansible/module_utils/cloudstack.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 7ea02d1be7..2396c49cae 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -48,6 +48,8 @@ class AnsibleCloudStack: self.module = module self._connect() + self.domain = None + self.account = None self.project = None self.ip_address = None self.zone = None @@ -73,7 +75,7 @@ class AnsibleCloudStack: else: self.cs = CloudStack(**read_config()) - + # TODO: rename to has_changed() def _has_changed(self, want_dict, current_dict, only_keys=None): for key, value in want_dict.iteritems(): @@ -245,6 +247,42 @@ class AnsibleCloudStack: self.module.fail_json(msg="Hypervisor '%s' not found" % hypervisor) + def get_account(self, key=None): + if self.account: + return self._get_by_key(key, self.account) + + account = self.module.params.get('account') + if not account: + return None + + args = {} + args['name'] = account + args['listall'] = True + accounts = self.cs.listAccounts(**args) + if accounts: + self.account = accounts['account'][0] + return self._get_by_key(key, self.account) + self.module.fail_json(msg="Account '%s' not found" % account) + + + def get_domain(self, key=None): + if self.domain: + return self._get_by_key(key, self.domain) + + domain = self.module.params.get('domain') + if not domain: + return None + + args = {} + args['name'] = domain + args['listall'] = True + domain = self.cs.listDomains(**args) + if domains: + self.domain = domains['domain'][0] + return self._get_by_key(key, self.domain) + self.module.fail_json(msg="Domain '%s' not found" % domain) + + def get_tags(self, resource=None): existing_tags = self.cs.listTags(resourceid=resource['id']) if existing_tags: @@ -309,7 +347,7 @@ class AnsibleCloudStack: self.capabilities = capabilities['capability'] return self._get_by_key(key, self.capabilities) - + # TODO: rename to poll_job() def _poll_job(self, job=None, key=None): if 'jobid' in job: while True: |