summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ansible/modules/cloud/cloudstack/cs_pod.py72
-rw-r--r--test/integration/targets/cs_pod/tasks/main.yml49
2 files changed, 61 insertions, 60 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()
diff --git a/test/integration/targets/cs_pod/tasks/main.yml b/test/integration/targets/cs_pod/tasks/main.yml
index 62d7fe7f0a..6c9bf47bd9 100644
--- a/test/integration/targets/cs_pod/tasks/main.yml
+++ b/test/integration/targets/cs_pod/tasks/main.yml
@@ -90,8 +90,7 @@
cs_pod:
name: "{{ cs_resource_prefix }}-pod"
zone: "{{ cs_resource_prefix }}-zone"
- start_ip: 10.100.10.102
- gateway: 10.100.10.1
+ gateway: 10.100.10.2
netmask: 255.255.255.0
register: pod
check_mode: true
@@ -110,8 +109,7 @@
cs_pod:
name: "{{ cs_resource_prefix }}-pod"
zone: "{{ cs_resource_prefix }}-zone"
- start_ip: 10.100.10.102
- gateway: 10.100.10.1
+ gateway: 10.100.10.2
netmask: 255.255.255.0
register: pod
- name: verify test update pod
@@ -119,9 +117,9 @@
that:
- pod is changed
- pod.allocation_state == "Enabled"
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -129,8 +127,7 @@
cs_pod:
name: "{{ cs_resource_prefix }}-pod"
zone: "{{ cs_resource_prefix }}-zone"
- start_ip: 10.100.10.102
- gateway: 10.100.10.1
+ gateway: 10.100.10.2
netmask: 255.255.255.0
register: pod
- name: verify test update pod idempotence
@@ -138,9 +135,9 @@
that:
- pod is not changed
- pod.allocation_state == "Enabled"
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -157,9 +154,9 @@
- pod is changed
- pod.allocation_state == "Enabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -175,9 +172,9 @@
- pod is changed
- pod.allocation_state == "Disabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -193,9 +190,9 @@
- pod is not changed
- pod.allocation_state == "Disabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -212,9 +209,9 @@
- pod is changed
- pod.allocation_state == "Disabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -230,9 +227,9 @@
- pod is changed
- pod.allocation_state == "Enabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -249,9 +246,9 @@
- pod is not changed
- pod.allocation_state == "Enabled"
- pod.id == pod_origin.id
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -268,9 +265,9 @@
- pod is changed
- pod.id == pod_origin.id
- pod.allocation_state == "Enabled"
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"
@@ -286,9 +283,9 @@
- pod is changed
- pod.id == pod_origin.id
- pod.allocation_state == "Enabled"
- - pod.start_ip == "10.100.10.102"
+ - pod.start_ip == "10.100.10.101"
- pod.end_ip == "10.100.10.254"
- - pod.gateway == "10.100.10.1"
+ - pod.gateway == "10.100.10.2"
- pod.netmask == "255.255.255.0"
- pod.zone == "{{ cs_resource_prefix }}-zone"