summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/cloud/cloudstack
diff options
context:
space:
mode:
authorRené Moser <mail@renemoser.net>2018-08-11 09:22:14 +0200
committerGitHub <noreply@github.com>2018-08-11 09:22:14 +0200
commit041fcb2435e780d3482febe651311ad7efbfce3b (patch)
treeecf4e3c057e2540027b543af6a90ee7a070ecc04 /lib/ansible/modules/cloud/cloudstack
parentc1f41ee6070c2c416bfa44f743306a0e4749099c (diff)
downloadansible-041fcb2435e780d3482febe651311ad7efbfce3b.tar.gz
cs_pod: workaround for 4.11 API break (#43944)
Diffstat (limited to 'lib/ansible/modules/cloud/cloudstack')
-rw-r--r--lib/ansible/modules/cloud/cloudstack/cs_pod.py72
1 files changed, 38 insertions, 34 deletions
diff --git a/lib/ansible/modules/cloud/cloudstack/cs_pod.py b/lib/ansible/modules/cloud/cloudstack/cs_pod.py
index 2f79782b15..fc7503b8cc 100644
--- a/lib/ansible/modules/cloud/cloudstack/cs_pod.py
+++ b/lib/ansible/modules/cloud/cloudstack/cs_pod.py
@@ -1,22 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# (c) 2016, René Moser <mail@renemoser.net>
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+# Copyright (c) 2016, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
@@ -67,8 +54,8 @@ extends_documentation_fragment: cloudstack
'''
EXAMPLES = '''
-# Ensure a pod is present
-- local_action:
+- name: Ensure a pod is present
+ local_action:
module: cs_pod
name: pod1
zone: ch-zrh-ix-01
@@ -76,22 +63,22 @@ EXAMPLES = '''
gateway: 10.100.10.1
netmask: 255.255.255.0
-# Ensure a pod is disabled
-- local_action:
+- name: Ensure a pod is disabled
+ local_action:
module: cs_pod
name: pod1
zone: ch-zrh-ix-01
state: disabled
-# Ensure a pod is enabled
-- local_action:
+- name: Ensure a pod is enabled
+ local_action:
module: cs_pod
name: pod1
zone: ch-zrh-ix-01
state: enabled
-# Ensure a pod is absent
-- local_action:
+- name: Ensure a pod is absent
+ local_action:
module: cs_pod
name: pod1
zone: ch-zrh-ix-01
@@ -179,22 +166,25 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
def get_pod(self):
if not self.pod:
- args = {}
+ args = {
+ 'zoneid': self.get_zone(key='id')
+ }
uuid = self.module.params.get('id')
if uuid:
args['id'] = uuid
- args['zoneid'] = self.get_zone(key='id')
- pods = self.query_api('listPods', **args)
- if pods:
- self.pod = pods['pod'][0]
- return self.pod
-
- args['name'] = self.module.params.get('name')
- args['zoneid'] = self.get_zone(key='id')
+ else:
+ args['name'] = self.module.params.get('name')
+
pods = self.query_api('listPods', **args)
if pods:
- self.pod = pods['pod'][0]
+ for pod in pods['pod']:
+ if not args['name']:
+ self.pod = self._transform_ip_list(pod)
+ break
+ elif args['name'] == pod['name']:
+ self.pod = self._transform_ip_list(pod)
+ break
return self.pod
def present_pod(self):
@@ -246,6 +236,20 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
self.query_api('deletePod', **args)
return pod
+ def _transform_ip_list(self, resource):
+ """ Workaround for 4.11 return API break """
+ keys = ['endip', 'startip']
+ if resource:
+ for key in keys:
+ if key in resource and isinstance(resource[key], list):
+ resource[key] = resource[key][0]
+ return resource
+
+ def get_result(self, pod):
+ pod = self._transform_ip_list(pod)
+ super(AnsibleCloudStackPod, self).get_result(pod)
+ return self.result
+
def main():
argument_spec = cs_argument_spec()