diff --git a/changelogs/fragments/61090-cloudstack-facts-info.yaml b/changelogs/fragments/61090-cloudstack-facts-info.yaml new file mode 100644 index 00000000000..2c5f3acae3c --- /dev/null +++ b/changelogs/fragments/61090-cloudstack-facts-info.yaml @@ -0,0 +1,3 @@ +minor_changes: +- The ``cs_instance_facts`` module has been deprecated. Use ``cs_instance_info`` instead. +- The ``cs_zone_facts`` module has been deprecated. Use ``cs_zone_info`` instead. diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.9.rst b/docs/docsite/rst/porting_guides/porting_guide_2.9.rst index 81bab7420e2..da602ec92a3 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_2.9.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_2.9.rst @@ -117,6 +117,10 @@ Deprecation notices The following modules will be removed in Ansible 2.13. Please update update your playbooks accordingly. +* cs_instance_facts use :ref:`cs_instance_info ` instead. + +* cs_zone_facts use :ref:`cs_zone_info ` instead. + * digital_ocean_sshkey_facts use :ref:`digital_ocean_sshkey_info ` instead. * junos_interface use :ref:`junos_interfaces ` instead. diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 61c148938e4..85a53b6b6e7 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -628,22 +628,27 @@ class AnsibleCloudStack: time.sleep(2) return job - def get_result(self, resource): + def update_result(self, resource, result=None): + if result is None: + result = dict() if resource: returns = self.common_returns.copy() returns.update(self.returns) for search_key, return_key in returns.items(): if search_key in resource: - self.result[return_key] = resource[search_key] + result[return_key] = resource[search_key] # Bad bad API does not always return int when it should. for search_key, return_key in self.returns_to_int.items(): if search_key in resource: - self.result[return_key] = int(resource[search_key]) + result[return_key] = int(resource[search_key]) if 'tags' in resource: - self.result['tags'] = resource['tags'] - return self.result + result['tags'] = resource['tags'] + return result + + def get_result(self, resource): + return self.update_result(resource, self.result) def get_result_and_facts(self, facts_name, resource): result = self.get_result(resource) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py b/lib/ansible/modules/cloud/cloudstack/_cs_instance_facts.py similarity index 98% rename from lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py rename to lib/ansible/modules/cloud/cloudstack/_cs_instance_facts.py index 78e4f304b0f..6f9567448ac 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py +++ b/lib/ansible/modules/cloud/cloudstack/_cs_instance_facts.py @@ -9,7 +9,7 @@ __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['stableinterface'], + 'status': ['deprecated'], 'supported_by': 'community'} @@ -19,6 +19,10 @@ module: cs_instance_facts short_description: Gathering facts from the API of instances from Apache CloudStack based clouds. description: - Gathering facts from the API of an instance. +deprecated: + removed_in: "2.13" + why: Transformed into an info module. + alternative: Use M(cs_instance_info) instead. version_added: '2.1' author: René Moser (@resmo) options: diff --git a/lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py b/lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py similarity index 96% rename from lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py rename to lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py index 92c815e9575..d0663b586ab 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py +++ b/lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py @@ -5,7 +5,7 @@ # 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'], + 'status': ['deprecated'], 'supported_by': 'community'} @@ -16,6 +16,10 @@ short_description: Gathering facts of zones from Apache CloudStack based clouds. description: - Gathering facts from the API of a zone. - Sets Ansible facts accessable by the key C(cloudstack_zone) and since version 2.6 also returns results. +deprecated: + removed_in: "2.13" + why: Transformed into an info module. + alternative: Use M(cs_zone_info) instead. version_added: '2.1' author: René Moser (@resmo) options: diff --git a/lib/ansible/modules/cloud/cloudstack/cs_instance_info.py b/lib/ansible/modules/cloud/cloudstack/cs_instance_info.py new file mode 100644 index 00000000000..ea5435c6b3c --- /dev/null +++ b/lib/ansible/modules/cloud/cloudstack/cs_instance_info.py @@ -0,0 +1,378 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# (c) 2016, René Moser +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'community'} + + +DOCUMENTATION = ''' +--- +module: cs_instance_info +short_description: Gathering information from the API of instances from Apache CloudStack based clouds. +description: + - Gathering information from the API of an instance. +version_added: '2.9' +author: René Moser (@resmo) +options: + name: + description: + - Name or display name of the instance. + - If not specified, all instances are returned + type: str + required: false + domain: + description: + - Domain the instance is related to. + type: str + account: + description: + - Account the instance is related to. + type: str + project: + description: + - Project the instance is related to. + type: str +extends_documentation_fragment: cloudstack +''' + +EXAMPLES = ''' +- name: Gather instance information + cs_instance_info: + name: web-vm-1 + delegate_to: localhost + register: vm + +- name: Show the returned results of the registered variable + debug: + msg: "{{ vm }}" + +- name: Gather information from all instances + cs_instance_info: + delegate_to: localhost + register: vms + +- name: Show information on all instances + debug: + msg: "{{ vms }}" +''' + +RETURN = ''' +--- +instances: + description: A list of matching instances. + type: list + returned: success + contains: + id: + description: UUID of the instance. + returned: success + type: str + sample: 04589590-ac63-4ffc-93f5-b698b8ac38b6 + name: + description: Name of the instance. + returned: success + type: str + sample: web-01 + display_name: + description: Display name of the instance. + returned: success + type: str + sample: web-01 + group: + description: Group name of the instance is related. + returned: success + type: str + sample: web + created: + description: Date of the instance was created. + returned: success + type: str + sample: 2014-12-01T14:57:57+0100 + password_enabled: + description: True if password setting is enabled. + returned: success + type: bool + sample: true + password: + description: The password of the instance if exists. + returned: success + type: str + sample: Ge2oe7Do + ssh_key: + description: Name of SSH key deployed to instance. + returned: success + type: str + sample: key@work + domain: + description: Domain the instance is related to. + returned: success + type: str + sample: example domain + account: + description: Account the instance is related to. + returned: success + type: str + sample: example account + project: + description: Name of project the instance is related to. + returned: success + type: str + sample: Production + default_ip: + description: Default IP address of the instance. + returned: success + type: str + sample: 10.23.37.42 + public_ip: + description: Public IP address with instance via static NAT rule. + returned: success + type: str + sample: 1.2.3.4 + iso: + description: Name of ISO the instance was deployed with. + returned: success + type: str + sample: Debian-8-64bit + template: + description: Name of template the instance was deployed with. + returned: success + type: str + sample: Debian-8-64bit + service_offering: + description: Name of the service offering the instance has. + returned: success + type: str + sample: 2cpu_2gb + zone: + description: Name of zone the instance is in. + returned: success + type: str + sample: ch-gva-2 + state: + description: State of the instance. + returned: success + type: str + sample: Running + security_groups: + description: Security groups the instance is in. + returned: success + type: list + sample: '[ "default" ]' + affinity_groups: + description: Affinity groups the instance is in. + returned: success + type: list + sample: '[ "webservers" ]' + tags: + description: List of resource tags associated with the instance. + returned: success + type: list + sample: '[ { "key": "foo", "value": "bar" } ]' + hypervisor: + description: Hypervisor related to this instance. + returned: success + type: str + sample: KVM + host: + description: Host the instance is running on. + returned: success and instance is running + type: str + sample: host01.example.com + version_added: '2.6' + instance_name: + description: Internal name of the instance (ROOT admin only). + returned: success + type: str + sample: i-44-3992-VM + volumes: + description: List of dictionaries of the volumes attached to the instance. + returned: success + type: list + sample: '[ { name: "ROOT-1369", type: "ROOT", size: 10737418240 }, { name: "data01, type: "DATADISK", size: 10737418240 } ]' + nic: + description: List of dictionaries of the instance nics. + returned: success + type: complex + version_added: '2.8' + contains: + broadcasturi: + description: The broadcast uri of the nic. + returned: success + type: str + sample: vlan://2250 + gateway: + description: The gateway of the nic. + returned: success + type: str + sample: 10.1.2.1 + id: + description: The ID of the nic. + returned: success + type: str + sample: 5dc74fa3-2ec3-48a0-9e0d-6f43365336a9 + ipaddress: + description: The ip address of the nic. + returned: success + type: str + sample: 10.1.2.3 + isdefault: + description: True if nic is default, false otherwise. + returned: success + type: bool + sample: true + isolationuri: + description: The isolation uri of the nic. + returned: success + type: str + sample: vlan://2250 + macaddress: + description: The mac address of the nic. + returned: success + type: str + sample: 06:a2:03:00:08:12 + netmask: + description: The netmask of the nic. + returned: success + type: str + sample: 255.255.255.0 + networkid: + description: The ID of the corresponding network. + returned: success + type: str + sample: 432ce27b-c2bb-4e12-a88c-a919cd3a3017 + networkname: + description: The name of the corresponding network. + returned: success + type: str + sample: network1 + traffictype: + description: The traffic type of the nic. + returned: success + type: str + sample: Guest + type: + description: The type of the network. + returned: success + type: str + sample: Shared +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.cloudstack import AnsibleCloudStack, cs_argument_spec + + +class AnsibleCloudStackInstanceInfo(AnsibleCloudStack): + + def __init__(self, module): + super(AnsibleCloudStackInstanceInfo, self).__init__(module) + self.returns = { + 'group': 'group', + 'hypervisor': 'hypervisor', + 'instancename': 'instance_name', + 'publicip': 'public_ip', + 'passwordenabled': 'password_enabled', + 'password': 'password', + 'serviceofferingname': 'service_offering', + 'isoname': 'iso', + 'templatename': 'template', + 'keypair': 'ssh_key', + 'hostname': 'host', + } + + def get_instances(self): + instance_name = self.module.params.get('name') + + args = { + 'account': self.get_account(key='name'), + 'domainid': self.get_domain(key='id'), + 'projectid': self.get_project(key='id'), + 'fetch_list': True, + } + # Do not pass zoneid, as the instance name must be unique across zones. + instances = self.query_api('listVirtualMachines', **args) + if not instance_name: + return instances or [] + if instances: + for v in instances: + if instance_name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]: + return [v] + return [] + + def get_volumes(self, instance): + volume_details = [] + if instance: + args = { + 'account': self.get_account(key='name'), + 'domainid': self.get_domain(key='id'), + 'projectid': self.get_project(key='id'), + 'virtualmachineid': instance['id'], + 'fetch_list': True, + } + + volumes = self.query_api('listVolumes', **args) + if volumes: + for vol in volumes: + volume_details.append({'size': vol['size'], 'type': vol['type'], 'name': vol['name']}) + return volume_details + + def run(self): + instances = self.get_instances() + if self.module.params.get('name') and not instances: + self.module.fail_json(msg="Instance not found: %s" % self.module.params.get('name')) + return { + 'instances': [self.update_result(resource) for resource in instances] + } + + def update_result(self, instance, result=None): + result = super(AnsibleCloudStackInstanceInfo, self).update_result(instance, result) + if instance: + if 'securitygroup' in instance: + security_groups = [] + for securitygroup in instance['securitygroup']: + security_groups.append(securitygroup['name']) + result['security_groups'] = security_groups + if 'affinitygroup' in instance: + affinity_groups = [] + for affinitygroup in instance['affinitygroup']: + affinity_groups.append(affinitygroup['name']) + result['affinity_groups'] = affinity_groups + if 'nic' in instance: + for nic in instance['nic']: + if nic['isdefault'] and 'ipaddress' in nic: + result['default_ip'] = nic['ipaddress'] + result['nic'] = instance['nic'] + volumes = self.get_volumes(instance) + if volumes: + result['volumes'] = volumes + return result + + +def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + name=dict(), + domain=dict(), + account=dict(), + project=dict(), + )) + + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + acs_instance_info = AnsibleCloudStackInstanceInfo(module=module) + cs_instance_info = acs_instance_info.run() + module.exit_json(**cs_instance_info) + + +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/cloud/cloudstack/cs_zone_info.py b/lib/ansible/modules/cloud/cloudstack/cs_zone_info.py new file mode 100644 index 00000000000..cf8a0eddd28 --- /dev/null +++ b/lib/ansible/modules/cloud/cloudstack/cs_zone_info.py @@ -0,0 +1,212 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016, René Moser +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'community'} + + +DOCUMENTATION = ''' +--- +module: cs_zone_info +short_description: Gathering information about zones from Apache CloudStack based clouds. +description: + - Gathering information from the API of a zone. +version_added: '2.9' +author: René Moser (@resmo) +options: + zone: + description: + - Name of the zone. + - If not specified, all zones are returned + type: str + aliases: [ name ] +extends_documentation_fragment: cloudstack +''' + +EXAMPLES = ''' +- name: Gather information from a zone + cs_zone_info: + zone: ch-gva-1 + register: zone + delegate_to: localhost + +- name: Show the returned results of the registered variable + debug: + msg: "{{ zone }}" + +- name: Gather information from all zones + cs_zone_info: + register: zones + delegate_to: localhost + +- name: Show information on all zones + debug: + msg: "{{ zones }}" +''' + +RETURN = ''' +--- +zones: + description: A list of matching zones. + type: list + returned: success + contains: + id: + description: UUID of the zone. + returned: success + type: str + sample: 04589590-ac63-4ffc-93f5-b698b8ac38b6 + name: + description: Name of the zone. + returned: success + type: str + sample: zone01 + dns1: + description: First DNS for the zone. + returned: success + type: str + sample: 8.8.8.8 + dns2: + description: Second DNS for the zone. + returned: success + type: str + sample: 8.8.4.4 + internal_dns1: + description: First internal DNS for the zone. + returned: success + type: str + sample: 8.8.8.8 + internal_dns2: + description: Second internal DNS for the zone. + returned: success + type: str + sample: 8.8.4.4 + dns1_ipv6: + description: First IPv6 DNS for the zone. + returned: success + type: str + sample: "2001:4860:4860::8888" + dns2_ipv6: + description: Second IPv6 DNS for the zone. + returned: success + type: str + sample: "2001:4860:4860::8844" + allocation_state: + description: State of the zone. + returned: success + type: str + sample: Enabled + domain: + description: Domain the zone is related to. + returned: success + type: str + sample: ROOT + network_domain: + description: Network domain for the zone. + returned: success + type: str + sample: example.com + network_type: + description: Network type for the zone. + returned: success + type: str + sample: basic + local_storage_enabled: + description: Local storage offering enabled. + returned: success + type: bool + sample: false + securitygroups_enabled: + description: Security groups support is enabled. + returned: success + type: bool + sample: false + guest_cidr_address: + description: Guest CIDR address for the zone + returned: success + type: str + sample: 10.1.1.0/24 + dhcp_provider: + description: DHCP provider for the zone + returned: success + type: str + sample: VirtualRouter + zone_token: + description: Zone token + returned: success + type: str + sample: ccb0a60c-79c8-3230-ab8b-8bdbe8c45bb7 + tags: + description: List of resource tags associated with the zone. + returned: success + type: dict + sample: [ { "key": "foo", "value": "bar" } ] +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.cloudstack import ( + AnsibleCloudStack, + cs_argument_spec, +) + + +class AnsibleCloudStackZoneInfo(AnsibleCloudStack): + + def __init__(self, module): + super(AnsibleCloudStackZoneInfo, self).__init__(module) + self.returns = { + 'dns1': 'dns1', + 'dns2': 'dns2', + 'internaldns1': 'internal_dns1', + 'internaldns2': 'internal_dns2', + 'ipv6dns1': 'dns1_ipv6', + 'ipv6dns2': 'dns2_ipv6', + 'domain': 'network_domain', + 'networktype': 'network_type', + 'securitygroupsenabled': 'securitygroups_enabled', + 'localstorageenabled': 'local_storage_enabled', + 'guestcidraddress': 'guest_cidr_address', + 'dhcpprovider': 'dhcp_provider', + 'allocationstate': 'allocation_state', + 'zonetoken': 'zone_token', + } + + def get_zone(self): + if self.module.params['zone']: + zones = [super(AnsibleCloudStackZoneInfo, self).get_zone()] + else: + zones = self.query_api('listZones') + if zones: + zones = zones['zone'] + else: + zones = [] + return { + 'zones': [self.update_result(resource) for resource in zones] + } + + +def main(): + argument_spec = cs_argument_spec() + argument_spec.update(dict( + zone=dict(type='str', aliases=['name']), + )) + + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + acs_zone_info = AnsibleCloudStackZoneInfo(module=module) + result = acs_zone_info.get_zone() + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/cs_instance/tasks/host.yml b/test/integration/targets/cs_instance/tasks/host.yml index c0614a1624c..051448f264a 100644 --- a/test/integration/targets/cs_instance/tasks/host.yml +++ b/test/integration/targets/cs_instance/tasks/host.yml @@ -13,11 +13,12 @@ state: stopped - name: setup zone facts - cs_zone_facts: + cs_zone_info: name: "{{ cs_common_zone_basic }}" + register: zone_info - name: setup find the host name - shell: cs listHosts type=routing zoneid="{{ cloudstack_zone.id }}" + shell: cs listHosts type=routing zoneid="{{ zone_info.zones[0].id }}" args: chdir: "{{ playbook_dir }}" register: host diff --git a/test/integration/targets/cs_instance/tasks/present.yml b/test/integration/targets/cs_instance/tasks/present.yml index 7edf54bed3c..81b770331de 100644 --- a/test/integration/targets/cs_instance/tasks/present.yml +++ b/test/integration/targets/cs_instance/tasks/present.yml @@ -85,8 +85,8 @@ - instance.ssh_key == "{{ cs_resource_prefix }}-sshkey" - not instance.tags -- name: gather host facts of running instance - cs_instance_facts: +- name: gather host infos of running instance + cs_instance_info: name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" - name: test running instance not updated in check mode diff --git a/test/integration/targets/cs_instance_facts/tasks/main.yml b/test/integration/targets/cs_instance_facts/tasks/main.yml deleted file mode 100644 index b7824f1b6a7..00000000000 --- a/test/integration/targets/cs_instance_facts/tasks/main.yml +++ /dev/null @@ -1,86 +0,0 @@ ---- -- name: setup ssh key - cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey - register: sshkey -- name: verify setup ssh key - assert: - that: - - sshkey is successful - -- name: setup affinity group - cs_affinitygroup: name={{ cs_resource_prefix }}-ag - register: ag -- name: verify setup affinity group - assert: - that: - - ag is successful - -- name: setup security group - cs_securitygroup: name={{ cs_resource_prefix }}-sg - register: sg -- name: verify setup security group - assert: - that: - - sg is successful - -- name: setup instance - cs_instance: - name: "{{ cs_resource_prefix }}-vm" - template: "{{ test_cs_instance_template }}" - service_offering: "{{ test_cs_instance_offering_1 }}" - affinity_group: "{{ cs_resource_prefix }}-ag" - security_group: "{{ cs_resource_prefix }}-sg" - ssh_key: "{{ cs_resource_prefix }}-sshkey" - tags: [] - register: instance -- name: verify create instance - assert: - that: - - instance is successful - -- name: test instance facts in check mode - cs_instance_facts: - name: "{{ cs_resource_prefix }}-vm" - register: instance_facts - check_mode: true -- name: verify test instance facts in check mode - assert: - that: - - instance_facts is successful - - instance_facts is not changed - - instance_facts.id == instance.id - - instance_facts.domain == instance.domain - - instance_facts.account == instance.account - - instance_facts.zone == instance.zone - - instance_facts.name == instance.name - - instance_facts.service_offering == instance.service_offering - - instance_facts.host != "" - - cloudstack_instance.id == instance.id - - cloudstack_instance.domain == instance.domain - - cloudstack_instance.account == instance.account - - cloudstack_instance.zone == instance.zone - - cloudstack_instance.name == instance.name - - cloudstack_instance.service_offering == instance.service_offering - -- name: test instance facts - cs_instance_facts: - name: "{{ cs_resource_prefix }}-vm" - register: instance_facts -- name: verify test instance facts - assert: - that: - - instance_facts is successful - - instance_facts is not changed - - instance_facts.id == instance.id - - instance_facts.domain == instance.domain - - instance_facts.account == instance.account - - instance_facts.zone == instance.zone - - instance_facts.name == instance.name - - instance_facts.service_offering == instance.service_offering - - instance_facts.host != "" - - cloudstack_instance.id == instance.id - - cloudstack_instance.domain == instance.domain - - cloudstack_instance.account == instance.account - - cloudstack_instance.zone == instance.zone - - cloudstack_instance.name == instance.name - - cloudstack_instance.service_offering == instance.service_offering diff --git a/test/integration/targets/cs_instance_facts/aliases b/test/integration/targets/cs_instance_info/aliases similarity index 100% rename from test/integration/targets/cs_instance_facts/aliases rename to test/integration/targets/cs_instance_info/aliases diff --git a/test/integration/targets/cs_instance_facts/defaults/main.yml b/test/integration/targets/cs_instance_info/defaults/main.yml similarity index 100% rename from test/integration/targets/cs_instance_facts/defaults/main.yml rename to test/integration/targets/cs_instance_info/defaults/main.yml diff --git a/test/integration/targets/cs_instance_facts/meta/main.yml b/test/integration/targets/cs_instance_info/meta/main.yml similarity index 100% rename from test/integration/targets/cs_instance_facts/meta/main.yml rename to test/integration/targets/cs_instance_info/meta/main.yml diff --git a/test/integration/targets/cs_instance_info/tasks/main.yml b/test/integration/targets/cs_instance_info/tasks/main.yml new file mode 100644 index 00000000000..d041ffe0d7a --- /dev/null +++ b/test/integration/targets/cs_instance_info/tasks/main.yml @@ -0,0 +1,91 @@ +--- +- name: setup ssh key + cs_sshkeypair: name={{ cs_resource_prefix }}-sshkey + register: sshkey +- name: verify setup ssh key + assert: + that: + - sshkey is successful + +- name: setup affinity group + cs_affinitygroup: name={{ cs_resource_prefix }}-ag + register: ag +- name: verify setup affinity group + assert: + that: + - ag is successful + +- name: setup security group + cs_securitygroup: name={{ cs_resource_prefix }}-sg + register: sg +- name: verify setup security group + assert: + that: + - sg is successful + +- name: setup instance + cs_instance: + name: "{{ cs_resource_prefix }}-vm" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + tags: [] + register: instance +- name: verify create instance + assert: + that: + - instance is successful + +- name: test instance info in check mode + cs_instance_info: + name: "{{ cs_resource_prefix }}-vm" + register: instance_info + check_mode: true +- name: verify test instance info in check mode + assert: + that: + - instance_info is successful + - instance_info is not changed + - instance_info.instances[0].id == instance.id + - instance_info.instances[0].domain == instance.domain + - instance_info.instances[0].account == instance.account + - instance_info.instances[0].zone == instance.zone + - instance_info.instances[0].name == instance.name + - instance_info.instances[0].service_offering == instance.service_offering + - instance_info.instances[0].host != "" + +- name: test instance info + cs_instance_info: + name: "{{ cs_resource_prefix }}-vm" + register: instance_info +- name: verify test instance info + assert: + that: + - instance_info is successful + - instance_info is not changed + - instance_info.instances[0].id == instance.id + - instance_info.instances[0].domain == instance.domain + - instance_info.instances[0].account == instance.account + - instance_info.instances[0].zone == instance.zone + - instance_info.instances[0].name == instance.name + - instance_info.instances[0].service_offering == instance.service_offering + - instance_info.instances[0].host != "" + +- name: test instance info for all instances + cs_instance_info: + register: instance_info +- name: verify test instance info + assert: + that: + - instance_info is successful + - instance_info is not changed + - instance_info.instances | length > 0 + - '"id" in instance_info.instances[0]' + - '"domain" in instance_info.instances[0]' + - '"account" in instance_info.instances[0]' + - '"zone" in instance_info.instances[0]' + - '"name" in instance_info.instances[0]' + - '"service_offering" in instance_info.instances[0]' + - '"host" in instance_info.instances[0]' diff --git a/test/integration/targets/cs_volume/tasks/extract_upload.yml b/test/integration/targets/cs_volume/tasks/extract_upload.yml index d80bb025747..5dc701873b5 100644 --- a/test/integration/targets/cs_volume/tasks/extract_upload.yml +++ b/test/integration/targets/cs_volume/tasks/extract_upload.yml @@ -52,11 +52,11 @@ - instance is successful - instance.state == 'Stopped' -- name: setup get instance facts - cs_instance_facts: +- name: setup get instance info + cs_instance_info: name: "{{ test_cs_instance_3 }}" register: instance -- name: verify setup get instance facts +- name: verify setup get instance info assert: that: - instance is successful @@ -65,7 +65,7 @@ cs_volume: zone: "{{ cs_common_zone_adv }}" state: extracted - name: "{{ instance.volumes[0].name }}" + name: "{{ instance.instances[0].volumes[0].name }}" check_mode: yes register: extracted_vol - name: verify test extract volume in check mode @@ -74,14 +74,14 @@ - extracted_vol is successful - extracted_vol is changed - extracted_vol.state == "Ready" - - extracted_vol.name == "{{ instance.volumes[0].name }}" + - extracted_vol.name == "{{ instance.instances[0].volumes[0].name }}" - extracted_vol.url is not defined - name: test extract volume cs_volume: zone: "{{ cs_common_zone_adv }}" state: extracted - name: "{{ instance.volumes[0].name }}" + name: "{{ instance.instances[0].volumes[0].name }}" register: extracted_vol - name: verify test extract volume assert: @@ -89,7 +89,7 @@ - extracted_vol is successful - extracted_vol is changed - extracted_vol.state == "DOWNLOAD_URL_CREATED" - - extracted_vol.name == "{{ instance.volumes[0].name }}" + - extracted_vol.name == "{{ instance.instances[0].volumes[0].name }}" - extracted_vol.url is defined - name: test upload volume with missing param diff --git a/test/integration/targets/cs_zone_facts/tasks/main.yml b/test/integration/targets/cs_zone_facts/tasks/main.yml deleted file mode 100644 index d275101724d..00000000000 --- a/test/integration/targets/cs_zone_facts/tasks/main.yml +++ /dev/null @@ -1,75 +0,0 @@ ---- -- name: setup zone is present - cs_zone: - name: "{{ cs_resource_prefix }}-zone" - dns1: 8.8.8.8 - dns2: 8.8.4.4 - network_type: Basic - register: zone -- name: verify setup zone is present - assert: - that: - - zone is successful - -- name: get facts from zone in check mode - cs_zone_facts: - name: "{{ cs_resource_prefix }}-zone" - register: zone - check_mode: yes -- name: verify get facts from zone in check mode - assert: - that: - - zone is successful - - zone is not changed - - zone.dns1 == "8.8.8.8" - - zone.dns2 == "8.8.4.4" - - zone.internal_dns1 == "8.8.8.8" - - zone.internal_dns2 == "8.8.4.4" - - zone.local_storage_enabled == false - - zone.network_type == "Basic" - - zone.zone_token != "" - - zone.securitygroups_enabled == true - - zone.dhcp_provider == "VirtualRouter" - - zone.local_storage_enabled == false - # Ansible Facts - - cloudstack_zone.dns1 == "8.8.8.8" - - cloudstack_zone.dns2 == "8.8.4.4" - - cloudstack_zone.internal_dns1 == "8.8.8.8" - - cloudstack_zone.internal_dns2 == "8.8.4.4" - - cloudstack_zone.local_storage_enabled == false - - cloudstack_zone.network_type == "Basic" - - cloudstack_zone.zone_token != "" - - cloudstack_zone.securitygroups_enabled == true - - cloudstack_zone.dhcp_provider == "VirtualRouter" - - cloudstack_zone.local_storage_enabled == false - -- name: get facts from zone - cs_zone_facts: - name: "{{ cs_resource_prefix }}-zone" - register: zone -- name: verify get facts from zone - assert: - that: - - zone is successful - - zone is not changed - - zone.dns1 == "8.8.8.8" - - zone.dns2 == "8.8.4.4" - - zone.internal_dns1 == "8.8.8.8" - - zone.internal_dns2 == "8.8.4.4" - - zone.local_storage_enabled == false - - zone.network_type == "Basic" - - zone.zone_token != "" - - zone.securitygroups_enabled == true - - zone.dhcp_provider == "VirtualRouter" - - zone.local_storage_enabled == false - # Ansible Facts - - cloudstack_zone.dns1 == "8.8.8.8" - - cloudstack_zone.dns2 == "8.8.4.4" - - cloudstack_zone.internal_dns1 == "8.8.8.8" - - cloudstack_zone.internal_dns2 == "8.8.4.4" - - cloudstack_zone.local_storage_enabled == false - - cloudstack_zone.network_type == "Basic" - - cloudstack_zone.zone_token != "" - - cloudstack_zone.securitygroups_enabled == true - - cloudstack_zone.dhcp_provider == "VirtualRouter" - - cloudstack_zone.local_storage_enabled == false diff --git a/test/integration/targets/cs_zone_facts/aliases b/test/integration/targets/cs_zone_info/aliases similarity index 100% rename from test/integration/targets/cs_zone_facts/aliases rename to test/integration/targets/cs_zone_info/aliases diff --git a/test/integration/targets/cs_zone_facts/meta/main.yml b/test/integration/targets/cs_zone_info/meta/main.yml similarity index 100% rename from test/integration/targets/cs_zone_facts/meta/main.yml rename to test/integration/targets/cs_zone_info/meta/main.yml diff --git a/test/integration/targets/cs_zone_info/tasks/main.yml b/test/integration/targets/cs_zone_info/tasks/main.yml new file mode 100644 index 00000000000..74dccf80622 --- /dev/null +++ b/test/integration/targets/cs_zone_info/tasks/main.yml @@ -0,0 +1,73 @@ +--- +- name: setup zone is present + cs_zone: + name: "{{ cs_resource_prefix }}-zone" + dns1: 8.8.8.8 + dns2: 8.8.4.4 + network_type: Basic + register: zone +- name: verify setup zone is present + assert: + that: + - zone is successful + +- name: get info from zone in check mode + cs_zone_info: + name: "{{ cs_resource_prefix }}-zone" + register: zone + check_mode: yes +- name: verify get info from zone in check mode + assert: + that: + - zone is successful + - zone is not changed + - zone.zones[0].dns1 == "8.8.8.8" + - zone.zones[0].dns2 == "8.8.4.4" + - zone.zones[0].internal_dns1 == "8.8.8.8" + - zone.zones[0].internal_dns2 == "8.8.4.4" + - zone.zones[0].local_storage_enabled == false + - zone.zones[0].network_type == "Basic" + - zone.zones[0].zone_token != "" + - zone.zones[0].securitygroups_enabled == true + - zone.zones[0].dhcp_provider == "VirtualRouter" + - zone.zones[0].local_storage_enabled == false + +- name: get info from zone + cs_zone_info: + name: "{{ cs_resource_prefix }}-zone" + register: zone +- name: verify get info from zone + assert: + that: + - zone is successful + - zone is not changed + - zone.zones[0].dns1 == "8.8.8.8" + - zone.zones[0].dns2 == "8.8.4.4" + - zone.zones[0].internal_dns1 == "8.8.8.8" + - zone.zones[0].internal_dns2 == "8.8.4.4" + - zone.zones[0].local_storage_enabled == false + - zone.zones[0].network_type == "Basic" + - zone.zones[0].zone_token != "" + - zone.zones[0].securitygroups_enabled == true + - zone.zones[0].dhcp_provider == "VirtualRouter" + - zone.zones[0].local_storage_enabled == false + +- name: get info from all zones + cs_zone_info: + register: zones +- name: verify get info from all zones + assert: + that: + - zones is successful + - zones is not changed + - zones.zones | length > 0 + - '"dns1" in zone.zones[0]' + - '"dns2" in zone.zones[0]' + - '"internal_dns1" in zone.zones[0]' + - '"internal_dns2" in zone.zones[0]' + - '"local_storage_enabled" in zone.zones[0]' + - '"network_type" in zone.zones[0]' + - '"zone_token" in zone.zones[0]' + - '"securitygroups_enabled" in zone.zones[0]' + - '"dhcp_provider" in zone.zones[0]' + - '"local_storage_enabled" in zone.zones[0]' diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index fd55397148d..3d32bb24b9d 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -1366,9 +1366,9 @@ lib/ansible/modules/cloud/cloudstack/cs_vpn_gateway.py future-import-boilerplate lib/ansible/modules/cloud/cloudstack/cs_vpn_gateway.py metaclass-boilerplate lib/ansible/modules/cloud/cloudstack/cs_zone.py future-import-boilerplate lib/ansible/modules/cloud/cloudstack/cs_zone.py metaclass-boilerplate -lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py future-import-boilerplate -lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py metaclass-boilerplate -lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py validate-modules:doc-missing-type +lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py future-import-boilerplate +lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py metaclass-boilerplate +lib/ansible/modules/cloud/cloudstack/_cs_zone_facts.py validate-modules:doc-missing-type lib/ansible/modules/cloud/digital_ocean/_digital_ocean.py validate-modules:undocumented-parameter lib/ansible/modules/cloud/digital_ocean/_digital_ocean.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/cloud/digital_ocean/_digital_ocean.py validate-modules:doc-missing-type