diff --git a/meta/runtime.yml b/meta/runtime.yml index aaf5dafa..d0a7b282 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -4,6 +4,10 @@ action_groups: otc: - as_config - as_config_info + - dns_floating_ip_info + - dns_nameserver_info + - dns_recordset_info + - dns_zone_info - as_group - as_group_info - as_instance_info diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py new file mode 100644 index 00000000..98a1f793 --- /dev/null +++ b/plugins/modules/dns_floating_ip_info.py @@ -0,0 +1,144 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +module: dns_floating_ip_info +short_description: Get DNS PTR Records +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.2.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get DNS PTR Records from the OTC. +options: + address: + description: + - EIP address + type: str + description: + description: + - Description of the Record + type: str + id: + description: + - PTR record ID + type: str + ptrdname: + description: + - Domain name of the PTR record + type: str + status: + description: + - Resource status + type: str + ttl: + description: + - PTR record cache duration (in second) on a local DNS server + type: int + +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +ptr_records: + description: Get DNS PTR Records + type: complex + returned: On Success. + contains: + address: + description: EIP address + type: str + sample: "100.138.123.199" + description: + description: Description of the Record + type: str + sample: "MyRecord123" + id: + description: PTR record id + type: str + sample: "eu-de:fe864230-d3bc-4391-8a32-394c3e9ca22d" + ptrdname: + description: Domain name of the PTR record + type: str + sample: "example.com" + status: + description: Resource status + type: str + sample: "ACTIVE" + ttl: + description: PTR record cache duration (in second) on a local DNS server + type: int + sample: 300 + +''' + +EXAMPLES = ''' +# Get PRT Info: +- name: Getting Info + opentelekomcloud.cloud.dns_floating_ip_info: + description: "Test" + ptrdname: "example.com" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSFloatingIpInfoModule(OTCModule): + argument_spec = dict( + address=dict(required=False), + description=dict(required=False), + id=dict(required=False), + ptrdname=dict(required=False), + status=dict(required=False), + ttl=dict(required=False, type='int') + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + + query = {} + data = [] + + if self.params['address']: + query['address'] = self.params['address'] + if self.params['id']: + query['id'] = self.params['id'] + if self.params['ptrdname']: + query['ptrdname'] = self.params['ptrdname'] + if self.params['ttl']: + query['ttl'] = self.params['ttl'] + if self.params['description']: + query['description'] = self.params['description'] + if self.params['status']: + query['status'] = self.params['status'] + + for raw in self.conn.dns.floating_ips(**query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + + self.exit( + changed=False, + ptr_records=data + ) + + +def main(): + module = DNSFloatingIpInfoModule() + module() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py new file mode 100644 index 00000000..6df593bb --- /dev/null +++ b/plugins/modules/dns_nameserver_info.py @@ -0,0 +1,147 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +module: dns_nameserver_info +short_description: Get DNS Nameserver Infos +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.2.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get DNS Namerserver infos from the OTC. +options: + address: + description: + - IP address of a DNS Server + type: str + hostname: + description: + - Hostname of a DNS server + type: str + priority: + description: + - Priority of a name server + type: str + zone: + description: + - DNS Zone ID + type: str + required: true + +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +dns_nameservers: + description: List of DNS Nameservers + type: complex + returned: On Success. + contains: + address: + description: IP address of a DNS server + type: str + sample: "100.138.123.199" + hostname: + description: Hostname of a DNS server + type: str + sample: "Myhostname" + priority: + description: Priority of a name server + type: str + sample: "1" + zone: + description: Specifies the DNS zone + type: str + sample: "fe40808272701cbe0172cbca17f91882" +''' + +EXAMPLES = ''' +# Get Nameserver Info about a zone: + +- name: Get nameserver Info + opentelekomcloud.cloud.dns_nameserver_info: + zone: fe40808272701cbe0172cbca17f91882 + hostname: "MyHostname" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSNameserverInfoModule(OTCModule): + argument_spec = dict( + address=dict(required=False), + hostname=dict(required=False), + priority=dict(required=False), + zone=dict(required=True) + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + + data = [] + query = {} + + if self.params['zone']: + zi = self.conn.dns.find_zone( + name_or_id=self.params['zone'], + ignore_missing=True) + if zi: + query['zone'] = zi.id + else: + self.exit( + changed=False, + message=('No zone found with name or id: %s' % + self.params['zone']) + ) + + for raw in self.conn.dns.nameservers(**query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + + # Filter data by deleting all entries without the right criteria as our Query doesn't support other queries + i = 0 + while i < len(data): + if self.params['address']: + if data[i]['address'] != self.params['address']: + del data[i] + i = 0 + continue + if self.params['hostname']: + if data[i]['hostname'] != self.params['hostname']: + del data[i] + i = 0 + continue + if self.params['priority']: + if data[i]['priority'] != self.params['priority']: + del data[i] + i = 0 + continue + i = i + 1 + + self.exit( + changed=False, + dns_nameservers=data + ) + + +def main(): + module = DNSNameserverInfoModule() + module() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py new file mode 100644 index 00000000..e1f43991 --- /dev/null +++ b/plugins/modules/dns_recordset_info.py @@ -0,0 +1,210 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +module: dns_recordset_info +short_description: Get DNS Recordsets +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.2.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get DNS Recordsets from the OTC. +options: + default: + description: + - Whether the record set is created by default + type: bool + description: + description: + - Description of the Record Set + type: str + created_at: + description: + - Time of creation + type: str + name: + description: + - Record name or ID + type: str + project_id: + description: + - Project ID + type: str + status: + description: + - Resource status + type: str + ttl: + description: + - Record set cache duration (in second) on a local DNS server + type: int + type: + description: + - Record set type + type: str + updated_at: + description: + - Last Update time + type: str + zone_id: + description: + - Zone ID or Name of the record set + type: str + required: true + +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +recordsets: + description: Get DNS Recordsets + type: complex + returned: On Success. + contains: + default: + description: Whether the record set is created by default + type: str + sample: "false" + description: + description: Description of the Record + type: str + sample: "MyRecord123" + created_at: + description: Time of creation + type: str + sample: "2020-09-29T12:28:59.721" + name: + description: Recordset name or ID + type: str + sample: "fe80823273f2065d0174defcbdce5951" + project_id: + description: Project ID + type: str + sample: "16e23f43a13b49529d2e2c3646691288" + status: + description: Resource status + type: str + sample: "ACTIVE" + ttl: + description: Record set cache duration (in second) on a local DNS server + type: int + sample: 300 + type: + description: Record set type + type: str + sample: "AAAA" + updated_at: + description: Last Update time + type: str + sample: "2020-09-29T12:28:59.721" + zone_id: + description: Zone ID of the record set + type: str + sample: "fe4080825c5f1234015c5f26688d0008" + +''' + +EXAMPLES = ''' +# Get Record Set Info: +- name: Record Set Info + opentelekomcloud.cloud.dns_recordset_info: + zone_id: "fe12345672701c340174d8e94bb9562c" + name: "my" + ttl: 86400 +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSRecordsetsInfoModule(OTCModule): + argument_spec = dict( + zone_id=dict(required=True), + status=dict(required=False), + type=dict(required=False), + name=dict(required=False), + description=dict(required=False), + ttl=dict(required=False, type='int'), + created_at=dict(required=False), + updated_at=dict(required=False), + default=dict(required=False, type='bool'), + project_id=dict(required=False) + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + + data = [] + query = {} + + if self.params['status']: + query['status'] = self.params['status'] + if self.params['type']: + query['type'] = self.params['type'] + if self.params['name']: + query['name'] = self.params['name'] + + for raw in self.conn.dns.recordsets(zone=self.params['zone_id'], **query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + + # Filter data by deleting all entries without the right criteria + i = 0 + while i < len(data): + if self.params['description']: + if data[i]['description'] != self.params['description']: + del data[i] + i = 0 + continue + if self.params['ttl']: + if data[i]['ttl'] != self.params['ttl']: + del data[i] + i = 0 + continue + if self.params['created_at']: + if data[i]['created_at'] != self.params['created_at']: + del data[i] + i = 0 + continue + if self.params['updated_at']: + if data[i]['updated_at'] != self.params['updated_at']: + del data[i] + i = 0 + continue + if self.params['default']: + if data[i]['default'] != self.params['default']: + del data[i] + i = 0 + continue + if self.params['project_id']: + if data[i]['project_id'] != self.params['project_id']: + del data[i] + i = 0 + continue + i = i + 1 + + self.exit( + changed=False, + recordsets=data + ) + + +def main(): + module = DNSRecordsetsInfoModule() + module() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py new file mode 100644 index 00000000..4546b797 --- /dev/null +++ b/plugins/modules/dns_zone_info.py @@ -0,0 +1,229 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +module: dns_zone_info +short_description: Get DNS Zone Infos +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.2.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get NAT gateway info from the OTC. +options: + description: + description: + - DNS Zone Description + type: str + email: + description: + - DNS Zone EMail Adress of the administrator managing the zone + type: str + name: + description: + - DNS Zone Name + type: str + pool_id: + description: + - Pool ID of the zone + type: str + project_id: + description: + - Project ID of the zone + type: str + serial: + description: + - Serial number in the SOA record set in a zone + type: int + status: + description: + - Ressource status + type: str + ttl: + description: + - TTL value of the SOA record set in the zone + type: int + type: + description: + - DNS Zone type + type: str + required: true + zone_id: + description: + - DNS Zone ID + type: str + +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +dns_zones: + description: List of dictionaries describing NAT gateways. + type: complex + returned: On Success. + contains: + description: + description: Description of the zone + type: str + sample: "What a great zone" + email: + description: DNS Zone EMail Adress of the administrator managing the zone + type: str + sample: "email@mail.ru" + name: + description: Name of the zone + type: str + sample: "MyZone123" + pool_id: + description: Pool ID of the zone + type: str + sample: "fe4080825c5f1977015c5f26688d0008" + project_id: + description: Project ID of the zone + type: str + sample: "19f43a84a13b49529d2e2c3646693458" + serial: + description: Serial number in the SOA record set in a zone + type: int + sample: 1 + status: + description: Ressource Status + type: str + sample: "ACTIVE" + ttl: + description: TTL value of the SOA record set in the zone + type: int + sample: 300 + type: + description: DNS Zone type + type: str + sample: "private" + zone_id: + description: DNS Zone ID + type: str + sample: "fe4080825c5f1977015c5f26688d0008" + routers: + description: Routers (VPCs associated with the zone) + type: dict + sample: { + "status": "ACTIVE", + "router_id": "19664294-0bf6-4271-ad3a-94b8c79c6558", + "router_region": "xx" + } + +''' + +EXAMPLES = ''' +# Get list of private zones and filter by name +- name: Listing + opentelekomcloud.cloud.dns_zone_info: + zone_type: "private" + name: "test_zone" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSZoneInfoModule(OTCModule): + argument_spec = dict( + description=dict(required=False), + email=dict(required=False), + name=dict(required=False), + pool_id=dict(required=False), + project_id=dict(required=False), + serial=dict(required=False, type='int'), + status=dict(required=False), + ttl=dict(required=False, type='int'), + type=dict(required=True), + zone_id=dict(required=False) + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + + data = [] + query = {} + + if self.params['type']: + query['zone_type'] = self.params['type'] + + for raw in self.conn.dns.zones(**query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + + # Filter data by deleting all entries without the right criteria + i = 0 + while i < len(data): + if self.params['status']: + if data[i]['status'] != self.params['status']: + del data[i] + i = 0 + continue + if self.params['zone_id']: + if data[i]['zone_id'] != self.params['zone_id']: + del data[i] + i = 0 + continue + if self.params['description']: + if data[i]['description'] != self.params['description']: + del data[i] + i = 0 + continue + if self.params['email']: + if data[i]['email'] != self.params['email']: + del data[i] + i = 0 + continue + if self.params['name']: + if data[i]['name'] != self.params['name']: + del data[i] + i = 0 + continue + if self.params['ttl']: + if data[i]['ttl'] != self.params['ttl']: + del data[i] + i = 0 + continue + if self.params['serial']: + if data[i]['serial'] != self.params['serial']: + del data[i] + i = 0 + continue + if self.params['pool_id']: + if data[i]['pool_id'] != self.params['pool_id']: + del data[i] + i = 0 + continue + if self.params['project_id']: + if data[i]['project_id'] != self.params['project_id']: + del data[i] + i = 0 + continue + i = i + 1 + + self.exit( + changed=False, + dns_zones=data + ) + + +def main(): + module = DNSZoneInfoModule() + module() + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 7f09672d..dad9da61 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -13,6 +13,7 @@ - name: Set facts set_fact: fl_ip: "{{ fl.floating_ip.floating_ip_address }}" + ptrdname: "{{ ( prefix + 'dns.com.' ) }}" description: "{{ ( prefix + 'description-dns' ) }}" zone_public_name: "{{ ( prefix + '-dnszone.com.' ) }}" @@ -112,6 +113,14 @@ - dns_fl is success - dns_fl.ptr.description is defined + - name: Get DNS Floating IP Info + dns_floating_ip_info: + register: ptr + + - name: debug configs + debug: + var: ptr.ptr_records + - name: Creating a public DNS Zone - check mode opentelekomcloud.cloud.dns_zones: name: "{{ zone_public_name }}" @@ -122,6 +131,10 @@ - name: assert result assert: that: + + - ptr is success + - ptr is not changed + - ptr.ptr_records is defined - dns_zo_ch is success - dns_zo_ch is changed @@ -171,6 +184,21 @@ that: - dns_zo is success - dns_zo.zone.description is defined + + - name: Getting Nameserver Info on Public Zone + opentelekomcloud.cloud.dns_nameserver_info: + zone: "{{ dns_zo.zone.id }}" + register: dns_zo_ns_info + + - name: debug + debug: + var: dns_zo_ns_info + + - name: assert result + assert: + that: + - dns_zo_ns_info is success + - dns_zo_ns_info.dns_nameservers is defined - name: Creating a DNS private Zone - check mode opentelekomcloud.cloud.dns_zones: @@ -235,6 +263,22 @@ that: - dns_zo_pr is success - dns_zo_pr.zone.description is defined + + - name: Getting Zone Info on Private Zone + opentelekomcloud.cloud.dns_zone_info: + type: "private" + name: "{{ zone_private_name }}" + register: dns_zo_zo_info + + - name: debug + debug: + var: dns_zo_zo_info + + - name: assert result + assert: + that: + - dns_zo_zo_info is success + - dns_zo_zo_info.dns_zones is defined - name: Creating a DNS Recordset - check mode opentelekomcloud.cloud.dns_recordset: @@ -306,6 +350,22 @@ state: present register: dns_rs + - name: Get DNS Recordset Info + dns_recordset_info: + zone_id: "{{ dns_zo.zone.id }}" + register: rs + + - name: debug configs + debug: + var: rs.recordsets + + - name: assert result + assert: + that: + - rs is success + - rs is not changed + - rs.recordsets is defined + - name: debug debug: var: dns_rs.recordset diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 8d6ad9be..562b26de 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -2,6 +2,10 @@ plugins/modules/as_config.py validate-modules:missing-gplv3-license plugins/modules/as_config_info.py validate-modules:missing-gplv3-license plugins/modules/as_group.py validate-modules:missing-gplv3-license plugins/modules/as_group_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_floating_ip_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_nameserver_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_recordset_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_zone_info.py validate-modules:missing-gplv3-license plugins/modules/as_instance_info.py validate-modules:missing-gplv3-license plugins/modules/as_policy.py validate-modules:missing-gplv3-license plugins/modules/as_policy_info.py validate-modules:missing-gplv3-license diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 9b2e21f9..87700d00 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -2,6 +2,10 @@ plugins/modules/as_config.py validate-modules:missing-gplv3-license plugins/modules/as_config_info.py validate-modules:missing-gplv3-license plugins/modules/as_group.py validate-modules:missing-gplv3-license plugins/modules/as_group_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_floating_ip_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_nameserver_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_recordset_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_zone_info.py validate-modules:missing-gplv3-license plugins/modules/as_instance_info.py validate-modules:missing-gplv3-license plugins/modules/as_policy.py validate-modules:missing-gplv3-license plugins/modules/as_policy_info.py validate-modules:missing-gplv3-license