From 60a89cad10fefd54a6ae3d7f0dae6f4452813721 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 2 Oct 2020 11:34:27 +0000 Subject: [PATCH 01/50] Added DNS Info Modules --- meta/runtime.yml | 4 + plugins/modules/dns_floating_ip_info.py | 161 +++++++++++ plugins/modules/dns_nameserver_info.py | 132 +++++++++ plugins/modules/dns_recordset_info.py | 219 ++++++++++++++ plugins/modules/dns_zone_info.py | 268 ++++++++++++++++++ .../dns_floating_ip_info/tasks/main.yaml | 3 + .../dns_nameserver_info/tasks/main.yaml | 4 + .../dns_recordset_info/tasks/main.yaml | 5 + .../targets/dns_zone_info/tasks/main.yaml | 4 + tests/sanity/ignore-2.10.txt | 4 + tests/sanity/ignore-2.9.txt | 4 + 11 files changed, 808 insertions(+) create mode 100644 plugins/modules/dns_floating_ip_info.py create mode 100644 plugins/modules/dns_nameserver_info.py create mode 100644 plugins/modules/dns_recordset_info.py create mode 100644 plugins/modules/dns_zone_info.py create mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml create mode 100644 tests/integration/targets/dns_nameserver_info/tasks/main.yaml create mode 100644 tests/integration/targets/dns_recordset_info/tasks/main.yaml create mode 100644 tests/integration/targets/dns_zone_info/tasks/main.yaml diff --git a/meta/runtime.yml b/meta/runtime.yml index 60ab15c7..6bcaaba5 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -4,6 +4,10 @@ action_groups: otc: - as_config_group - as_config_info + - dns_floating_ip_info + - dns_nameserver_info + - dns_recordset_info + - dns_zone_info - cce_cluster - cce_cluster_cert_info - cce_cluster_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..b24d0bac --- /dev/null +++ b/plugins/modules/dns_floating_ip_info.py @@ -0,0 +1,161 @@ +#!/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.0.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 Nameserver Info about a zone: +- name: Getting Info + dns_floating_ip_info: + description: "Test" + +''' + +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') + ) + + def run(self): + + data = [] + + for raw in self.conn.dns.floating_ips(): + 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['address']: + if data[i]['address'] != self.params['address']: + del data[i] + i = 0 + continue + if self.params['id']: + if data[i]['id'] != self.params['id']: + del data[i] + i = 0 + continue + if self.params['ptrdname']: + if data[i]['ptrdname'] != self.params['ptrdname']: + 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['description']: + if data[i]['description'] != self.params['description']: + del data[i] + i = 0 + continue + if self.params['status']: + if data[i]['status'] != self.params['status']: + del data[i] + i = 0 + continue + i = i + 1 + + 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..6504def9 --- /dev/null +++ b/plugins/modules/dns_nameserver_info.py @@ -0,0 +1,132 @@ +#!/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.0.3" +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 + dns_nameserver_info: + zone: fe40808272701cbe0172cbca17f91882 + +''' + +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) + + ) + + 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']) + ) + + if self.params['priority']: + query['priority'] = self.params['priority'] + if self.params['priority']: + query['address'] = self.params['priority'] + if self.params['priority']: + query['priority'] = self.params['priority'] + + for raw in self.conn.dns.nameservers(**query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + + 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..6599374a --- /dev/null +++ b/plugins/modules/dns_recordset_info.py @@ -0,0 +1,219 @@ +#!/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.0.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 + create_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 + update_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" + create_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" + update_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 + 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'), + create_at=dict(required=False), + update_at=dict(required=False), + default=dict(required=False, type='bool'), + project_id=dict(required=False) + ) + + 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']: + rs = self.conn.dns.find_recordset( + zone=self.params['zone_id'], + name_or_id=self.params['name'], + ignore_missing=True) + if rs: + query['name'] = rs.name + else: + self.exit( + changed=False, + nat_gateways=[], + message=('No entry found with name or id: %s' % + 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['create_at']: + if data[i]['create_at'] != self.params['create_at']: + del data[i] + i = 0 + continue + if self.params['update_at']: + if data[i]['update_at'] != self.params['update_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..a6b40df6 --- /dev/null +++ b/plugins/modules/dns_zone_info.py @@ -0,0 +1,268 @@ +#!/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.0.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get NAT gateway info from the OTC. +options: + created_at: + description: + - Time when the zone was created + type: str + 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 + record_num: + description: + - Number of record sets in the zone + type: int + 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 + updated_at: + description: + - Time when the zone was updated + type: str + zone_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: + created_at: + description: Time when the zone was created + type: str + sample: "2020-09-10T19:40:29.362" + 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" + record_num: + description: Number of record sets in the zone + type: int + sample: 3 + 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 + updated_at: + description: Time when the zone was updated + type: str + sample: "2020-09-10T19:40:29.362" + zone_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 with 3 records +- name: Listing + dns_zone_info: + record_num: "3" + zone_type: "private" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSZoneInfoModule(OTCModule): + argument_spec = dict( + created_at=dict(required=False), + description=dict(required=False), + email=dict(required=False), + name=dict(required=False), + pool_id=dict(required=False), + project_id=dict(required=False), + record_num=dict(required=False, type='int'), + serial=dict(required=False, type='int'), + status=dict(required=False), + ttl=dict(required=False, type='int'), + updated_at=dict(required=False), + zone_type=dict(required=True), + zone_id=dict(required=False) + ) + + def run(self): + + data = [] + query = {} + + if self.params['zone_type']: + query['zone_type'] = self.params['zone_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['record_num']: + if data[i]['record_num'] != self.params['record_num']: + 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['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['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 + 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 + 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_floating_ip_info/tasks/main.yaml b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml new file mode 100644 index 00000000..0b9bba17 --- /dev/null +++ b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml @@ -0,0 +1,3 @@ +- name: Testing + dns_floating_ip_info: + description: "Test3" diff --git a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml new file mode 100644 index 00000000..770891a6 --- /dev/null +++ b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml @@ -0,0 +1,4 @@ +- name: Get Nameserver info + dns_nameserver_info: + zone: fe12345672701cbe0172cbca17f91882 + diff --git a/tests/integration/targets/dns_recordset_info/tasks/main.yaml b/tests/integration/targets/dns_recordset_info/tasks/main.yaml new file mode 100644 index 00000000..12b822a5 --- /dev/null +++ b/tests/integration/targets/dns_recordset_info/tasks/main.yaml @@ -0,0 +1,5 @@ +- name: Record Set Info + dns_recordset_info: + zone_id: "fe12345672701c340174d8e94bb9562c" + name: "my" + ttl: 86400 diff --git a/tests/integration/targets/dns_zone_info/tasks/main.yaml b/tests/integration/targets/dns_zone_info/tasks/main.yaml new file mode 100644 index 00000000..3c6aa1f7 --- /dev/null +++ b/tests/integration/targets/dns_zone_info/tasks/main.yaml @@ -0,0 +1,4 @@ +- name: Testing + dns_zone_info: + record_num: "3" + zone_type: "private" diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 9a7d9acc..a13f67f5 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -1,5 +1,9 @@ plugins/modules/as_config_info.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/cce_cluster.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 520ddb02..2148323c 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,5 +1,9 @@ plugins/modules/as_config_info.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/cce_cluster.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license From 61ae16ea4ac32e5d7fddc244df803ad097bb9c83 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 2 Oct 2020 12:40:19 +0000 Subject: [PATCH 02/50] Fixed Whitespace --- plugins/modules/dns_nameserver_info.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index 6504def9..b3f285f8 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -63,7 +63,6 @@ description: Specifies the DNS zone type: str sample: "fe40808272701cbe0172cbca17f91882" - ''' EXAMPLES = ''' @@ -84,7 +83,6 @@ class DNSNameserverInfoModule(OTCModule): hostname=dict(required=False), priority=dict(required=False), zone=dict(required=True) - ) def run(self): From d6ab88f0bc78d52afaa5524b0dc1e1402dae5490 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 5 Oct 2020 07:53:44 +0000 Subject: [PATCH 03/50] Fixed Integration --- .../integration/targets/dns_floating_ip_info/tasks/main.yaml | 3 --- .../integration/targets/dns_nameserver_info/tasks/main.yaml | 4 ---- tests/integration/targets/dns_recordset_info/tasks/main.yaml | 5 ----- tests/integration/targets/dns_zone_info/tasks/main.yaml | 4 ---- 4 files changed, 16 deletions(-) delete mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_nameserver_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_recordset_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_zone_info/tasks/main.yaml diff --git a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml deleted file mode 100644 index 0b9bba17..00000000 --- a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ -- name: Testing - dns_floating_ip_info: - description: "Test3" diff --git a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml deleted file mode 100644 index 770891a6..00000000 --- a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- name: Get Nameserver info - dns_nameserver_info: - zone: fe12345672701cbe0172cbca17f91882 - diff --git a/tests/integration/targets/dns_recordset_info/tasks/main.yaml b/tests/integration/targets/dns_recordset_info/tasks/main.yaml deleted file mode 100644 index 12b822a5..00000000 --- a/tests/integration/targets/dns_recordset_info/tasks/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ -- name: Record Set Info - dns_recordset_info: - zone_id: "fe12345672701c340174d8e94bb9562c" - name: "my" - ttl: 86400 diff --git a/tests/integration/targets/dns_zone_info/tasks/main.yaml b/tests/integration/targets/dns_zone_info/tasks/main.yaml deleted file mode 100644 index 3c6aa1f7..00000000 --- a/tests/integration/targets/dns_zone_info/tasks/main.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- name: Testing - dns_zone_info: - record_num: "3" - zone_type: "private" From 019071ca7fe0e8daf33cda77bc805ca09e400f38 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 9 Oct 2020 10:06:57 +0000 Subject: [PATCH 04/50] added dns_flaoting_ip --- plugins/modules/dns_floating_ip.py | 165 ++++++++++++++++++++++++++ plugins/modules/dns_recordset.py | 184 +++++++++++++++++++++++++++++ 2 files changed, 349 insertions(+) create mode 100644 plugins/modules/dns_floating_ip.py create mode 100644 plugins/modules/dns_recordset.py diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py new file mode 100644 index 00000000..da236a21 --- /dev/null +++ b/plugins/modules/dns_floating_ip.py @@ -0,0 +1,165 @@ +#!/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 +short_description: Get DNS PTR Records +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.0.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 Nameserver Info about a zone: +- name: Getting Info + dns_floating_ip_info: + description: "Test" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSFloatingIpModule(OTCModule): + argument_spec = dict( + floating_ip=dict(required=True), + ptrdname=dict(required=False), + description=dict(required=False), + ttl=dict(required=False, type='int'), + state=dict(type='str', choices=['present', 'absent'], default='present') + ) + + def run(self): + changed = False + data = [] + + fl = self.conn.network.find_ip( + name_or_id=self.params['floating_ip'], + ignore_missing=True + ) + if not fl: + self.exit( + changed=False, + message=('No floating IP found with name or id: %s' % + self.params['floating_ip']) + ) + if self.params['state'] == 'absent': + changed = False + # Set eu-de: in front of the id to comly with the API. Nothing else as eu-de is available currently + self.conn.dns.unset_floating_ip(floating_ip = ('eu-de:' + fl.id)) + changed = True + + if self.params['state'] == 'present': + attrs = {} + if not self.params['ptrdname']: + self.exit( + changed=False, + message=('No ptrdname specified but required for creation') + ) + else: + attrs['ptrdname'] = self.params['ptrdname'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + + #get_floating_ip doesn't support ignore_missing and throws an error when there's nothing found. So we need to catch the error + try: + self.conn.dns.get_floating_ip(floating_ip = ('eu-de:' + fl.id)) + except: + output = self.conn.dns.set_floating_ip(floating_ip = ('eu-de:' + fl.id), **attrs) + self.exit( + changed = True, + ptr = output.to_dict() + ) + else: + output = self.conn.dns.update_floating_ip(floating_ip = ('eu-de:' + fl.id), **attrs) + self.exit( + changed = True, + ptr = output.to_dict() + ) + + self.exit( + changed=changed + ) + + +def main(): + module = DNSFloatingIpModule() + module() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py new file mode 100644 index 00000000..152e032c --- /dev/null +++ b/plugins/modules/dns_recordset.py @@ -0,0 +1,184 @@ +#!/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 +short_description: Get DNS PTR Records +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.0.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 Nameserver Info about a zone: +- name: Getting Info + dns_floating_ip_info: + description: "Test" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSRecordsetModule(OTCModule): + argument_spec = dict( + zone_id=dict(required=True), + recordset_name=dict(required=True), + description=dict(required=False), + type=dict(required=False), + ttl=dict(required=False, type='int'), + records=dict(required=False, type=[]), + state=dict(type='str', choices=['present', 'absent'], default='present') + ) + + def run(self): + changed = False + data = [] + + zo = self.conn.dns.find_zone( + name_or_id = self.params['zone_id'], + ignore_missing = True + ) + if not zo: + self.exit( + changed=False, + message=('No Zone found with name or id: %s' % + self.params['zone_id']) + ) + + + if self.params['state'] == 'absent': + changed = False + rs = self.conn.dns.find_recordset( + name_or_id = self.params['recordset_name'], + zone = zo.id, + ignore_missing = True + ) + if not rs: + self.exit( + changed=False, + message=('No Recordset found with name or id: %s' % + self.params['recordset_name']) + ) + self.conn.dns.delete_recordset( + recordset = rs.id, + zone = zo.id + ) + changed = True + + if self.params['state'] == 'present': + attrs = {} + attrs['name'] = self.params['recordset_name'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['type']: + attrs['type'] = self.params['type'] + else: + self.exit( + changed=False, + message=('No type specified!') + ) + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i+1 + else: + self.exit( + changed=False, + message=('No records specified!') + ) + + rset = self.conn.dns.create_recordset(zone = zo.id , **attrs) + self.exit(changed=True, rset=rset.to_dict()) + + + + + self.exit( + changed=changed + ) + + +def main(): + module = DNSRecordsetModule() + module() + + +if __name__ == '__main__': + main() From 5c007eeaa01d2c57791afeca6ca3495f9aa80b55 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 9 Oct 2020 10:25:05 +0000 Subject: [PATCH 05/50] Added docu FLIP and fixed pep8 --- plugins/modules/dns_floating_ip.py | 88 +++++++++++++++--------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index da236a21..a1d11c26 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -20,26 +20,25 @@ description: - Get DNS PTR Records from the OTC. options: - address: - description: - - EIP address - type: str description: description: - Description of the Record type: str - id: + floating_ip: description: - - PTR record ID + - Name or ID of the floating ip type: str + required: true ptrdname: description: - - Domain name of the PTR record + - Domain name of the PTR record required if updating/creating rule type: str - status: + state: description: - - Resource status + - Resource state type: str + choices: [present, absent] + default: present ttl: description: - PTR record cache duration (in second) on a local DNS server @@ -54,20 +53,16 @@ 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 + floating_ip: + description: Name or ID of the floating ip type: str - sample: "eu-de:fe864230-d3bc-4391-8a32-394c3e9ca22d" + sample: "123.123.123.123" ptrdname: - description: Domain name of the PTR record + description: Domain name of the PTR record required if updating/creating rule type: str sample: "example.com" status: @@ -82,10 +77,15 @@ ''' EXAMPLES = ''' -# Get Nameserver Info about a zone: -- name: Getting Info - dns_floating_ip_info: - description: "Test" +# Creating a record: +- name: Creating a record + dns_floating_ip: + floating_ip: 123.123.123.123 + ptrdname: "test2.com." + description: "test2nownow" + ttl: 300 + state: present + ''' @@ -118,39 +118,39 @@ def run(self): if self.params['state'] == 'absent': changed = False # Set eu-de: in front of the id to comly with the API. Nothing else as eu-de is available currently - self.conn.dns.unset_floating_ip(floating_ip = ('eu-de:' + fl.id)) + self.conn.dns.unset_floating_ip(floating_ip=('eu-de:' + fl.id)) changed = True if self.params['state'] == 'present': attrs = {} if not self.params['ptrdname']: - self.exit( - changed=False, - message=('No ptrdname specified but required for creation') - ) + self.exit( + changed=False, + message=('No ptrdname specified but required for creation') + ) else: - attrs['ptrdname'] = self.params['ptrdname'] + attrs['ptrdname'] = self.params['ptrdname'] if self.params['description']: - attrs['description'] = self.params['description'] + attrs['description'] = self.params['description'] if self.params['ttl']: - attrs['ttl'] = self.params['ttl'] - - #get_floating_ip doesn't support ignore_missing and throws an error when there's nothing found. So we need to catch the error + attrs['ttl'] = self.params['ttl'] + + # get_floating_ip doesn't support ignore_missing and throws an error when there's nothing found. So we need to catch the error try: - self.conn.dns.get_floating_ip(floating_ip = ('eu-de:' + fl.id)) - except: - output = self.conn.dns.set_floating_ip(floating_ip = ('eu-de:' + fl.id), **attrs) - self.exit( - changed = True, - ptr = output.to_dict() - ) + self.conn.dns.get_floating_ip(floating_ip=('eu-de:' + fl.id)) + except Exception: + output = self.conn.dns.set_floating_ip(floating_ip=('eu-de:' + fl.id), **attrs) + self.exit( + changed=True, + ptr=output.to_dict() + ) else: - output = self.conn.dns.update_floating_ip(floating_ip = ('eu-de:' + fl.id), **attrs) - self.exit( - changed = True, - ptr = output.to_dict() - ) - + output = self.conn.dns.update_floating_ip(floating_ip=('eu-de:' + fl.id), **attrs) + self.exit( + changed=True, + ptr=output.to_dict() + ) + self.exit( changed=changed ) From e708daecf2a0121c9fb35d81f51d0bf6a53c38b2 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 3 Nov 2020 09:24:11 +0000 Subject: [PATCH 06/50] Fixed version_added --- plugins/modules/dns_floating_ip_info.py | 5 +++-- plugins/modules/dns_nameserver_info.py | 2 +- plugins/modules/dns_recordset_info.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index b24d0bac..21f9d33a 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -15,7 +15,7 @@ module: dns_floating_ip_info short_description: Get DNS PTR Records extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS PTR Records from the OTC. @@ -82,10 +82,11 @@ ''' EXAMPLES = ''' -# Get Nameserver Info about a zone: +# Get PRT Info: - name: Getting Info dns_floating_ip_info: description: "Test" + ptrdname: "example.com" ''' diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index b3f285f8..228e7519 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -15,7 +15,7 @@ module: dns_nameserver_info short_description: Get DNS Nameserver Infos extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.3" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS Namerserver infos from the OTC. diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index 6599374a..661b3aca 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -15,7 +15,7 @@ module: dns_recordset_info short_description: Get DNS Recordsets extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS Recordsets from the OTC. From 3c61ac62fb15e71ba0722bcc18bf28f676172efe Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 3 Nov 2020 09:26:47 +0000 Subject: [PATCH 07/50] Fixed version_added --- plugins/modules/dns_zone_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index a6b40df6..47c08f66 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -15,7 +15,7 @@ module: dns_zone_info short_description: Get DNS Zone Infos extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get NAT gateway info from the OTC. From 888a57b6cf3b8d1be0d809de8756627a8b73d47d Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 3 Nov 2020 09:49:47 +0000 Subject: [PATCH 08/50] Deleted Date Filters --- plugins/modules/dns_zone_info.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index 47c08f66..be5a7e1e 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -20,10 +20,6 @@ description: - Get NAT gateway info from the OTC. options: - created_at: - description: - - Time when the zone was created - type: str description: description: - DNS Zone Description @@ -60,10 +56,6 @@ description: - TTL value of the SOA record set in the zone type: int - updated_at: - description: - - Time when the zone was updated - type: str zone_type: description: - DNS Zone type @@ -83,10 +75,6 @@ type: complex returned: On Success. contains: - created_at: - description: Time when the zone was created - type: str - sample: "2020-09-10T19:40:29.362" description: description: Description of the zone type: str @@ -123,10 +111,6 @@ description: TTL value of the SOA record set in the zone type: int sample: 300 - updated_at: - description: Time when the zone was updated - type: str - sample: "2020-09-10T19:40:29.362" zone_type: description: DNS Zone type type: str @@ -160,7 +144,6 @@ class DNSZoneInfoModule(OTCModule): argument_spec = dict( - created_at=dict(required=False), description=dict(required=False), email=dict(required=False), name=dict(required=False), @@ -170,7 +153,6 @@ class DNSZoneInfoModule(OTCModule): serial=dict(required=False, type='int'), status=dict(required=False), ttl=dict(required=False, type='int'), - updated_at=dict(required=False), zone_type=dict(required=True), zone_id=dict(required=False) ) @@ -241,16 +223,6 @@ def run(self): 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 i = i + 1 self.exit( From 219e9c08caac94b4118bf4ef22d48fc6ff6fadbc Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 3 Nov 2020 09:52:21 +0000 Subject: [PATCH 09/50] some help for sebastian --- plugins/modules/dns_floating_ip_info.py | 51 ++++++------------- .../dns_floating_ip_info/tasks/main.yaml | 17 +++++++ 2 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index 21f9d33a..1906fa45 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -105,48 +105,27 @@ class DNSFloatingIpInfoModule(OTCModule): def run(self): + query = {} data = [] - for raw in self.conn.dns.floating_ips(): + 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) - # Filter data by deleting all entries without the right criteria - 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['id']: - if data[i]['id'] != self.params['id']: - del data[i] - i = 0 - continue - if self.params['ptrdname']: - if data[i]['ptrdname'] != self.params['ptrdname']: - 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['description']: - if data[i]['description'] != self.params['description']: - del data[i] - i = 0 - continue - if self.params['status']: - if data[i]['status'] != self.params['status']: - del data[i] - i = 0 - continue - i = i + 1 - self.exit( changed=False, ptr_records=data diff --git a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml new file mode 100644 index 00000000..f32928c1 --- /dev/null +++ b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml @@ -0,0 +1,17 @@ +--- +- block: + - name: Get DNAT rule info + dns_floating_ip_info: + cloud: "{{ test_cloud }}" + register: ptr + + - name: debug configs + debug: + var: ptr.ptr_records + + - name: assert result + assert: + that: + - ptr is success + - ptr is not changed + - ptr.ptr_records is defined From 1a28ce0be8e8bb0f62acdb9ac0fff50572ebe638 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 4 Nov 2020 10:39:01 +0000 Subject: [PATCH 10/50] Changed FQCN --- plugins/modules/dns_floating_ip_info.py | 2 +- plugins/modules/dns_nameserver_info.py | 3 ++- plugins/modules/dns_recordset_info.py | 2 +- plugins/modules/dns_zone_info.py | 12 ++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index 1906fa45..e20a2b05 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -84,7 +84,7 @@ EXAMPLES = ''' # Get PRT Info: - name: Getting Info - dns_floating_ip_info: + opentelekomcloud.cloud.dns_floating_ip_info: description: "Test" ptrdname: "example.com" diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index 228e7519..2a60bb26 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -69,8 +69,9 @@ # Get Nameserver Info about a zone: - name: Get nameserver Info - dns_nameserver_info: + opentelekomcloud.cloud.dns_nameserver_info: zone: fe40808272701cbe0172cbca17f91882 + hostname: "MyHostname" ''' diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index 661b3aca..ad0b93a3 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -117,7 +117,7 @@ EXAMPLES = ''' # Get Record Set Info: - name: Record Set Info - dns_recordset_info: + opentelekomcloud.cloud.dns_recordset_info: zone_id: "fe12345672701c340174d8e94bb9562c" name: "my" ttl: 86400 diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index be5a7e1e..f036b017 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -133,7 +133,7 @@ EXAMPLES = ''' # Get list of private zones with 3 records - name: Listing - dns_zone_info: + opentelekomcloud.cloud.dns_zone_info: record_num: "3" zone_type: "private" @@ -183,11 +183,6 @@ def run(self): 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['zone_id']: if data[i]['zone_id'] != self.params['zone_id']: del data[i] @@ -203,6 +198,11 @@ def run(self): 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] From 580e86e85c51baa94edf7c3070dc5a242bcd1c39 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 4 Nov 2020 10:50:57 +0000 Subject: [PATCH 11/50] Fixed Sanity Checks --- tests/sanity/ignore-2.10.txt | 2 ++ tests/sanity/ignore-2.9.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 9a7d9acc..8d83be9e 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -3,6 +3,8 @@ plugins/modules/as_group_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_floating_ip.py validate-modules:missing-gplv3-license +plugins/modules/dns_recordset.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer_info.py validate-modules:missing-gplv3-license plugins/modules/nat_gateway_info.py validate-modules:missing-gplv3-license diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 520ddb02..14e64bd7 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -3,6 +3,8 @@ plugins/modules/as_group_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license +plugins/modules/dns_floating_ip.py validate-modules:missing-gplv3-license +plugins/modules/dns_recordset.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer_info.py validate-modules:missing-gplv3-license plugins/modules/nat_dnat_rule_info.py validate-modules:missing-gplv3-license From d0aa79587fe9a197d2fe8ffd1c963f5466da0c58 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 4 Nov 2020 12:26:36 +0000 Subject: [PATCH 12/50] Fixed issue creating recordset --- plugins/modules/dns_recordset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 152e032c..c27a03bc 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -99,7 +99,7 @@ class DNSRecordsetModule(OTCModule): description=dict(required=False), type=dict(required=False), ttl=dict(required=False, type='int'), - records=dict(required=False, type=[]), + records=dict(required=False, type='list'), state=dict(type='str', choices=['present', 'absent'], default='present') ) @@ -158,6 +158,7 @@ def run(self): while i < len(self.params['records']): attrs['records'].append(self.params['records'][i]) i = i+1 + # raise Exception(self.params['records'], len(self.params['records']), ' ', attrs['records'][1]) else: self.exit( changed=False, From d62a07a5e63dedf404e38f7970d38f74f2e9952c Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 4 Nov 2020 13:38:53 +0000 Subject: [PATCH 13/50] Functional complete - Missing Docu --- plugins/modules/dns_recordset.py | 130 +++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 41 deletions(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index c27a03bc..bdbb86da 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -99,7 +99,7 @@ class DNSRecordsetModule(OTCModule): description=dict(required=False), type=dict(required=False), ttl=dict(required=False, type='int'), - records=dict(required=False, type='list'), + records=dict(required=True, type='list'), state=dict(type='str', choices=['present', 'absent'], default='present') ) @@ -117,8 +117,7 @@ def run(self): message=('No Zone found with name or id: %s' % self.params['zone_id']) ) - - + if self.params['state'] == 'absent': changed = False rs = self.conn.dns.find_recordset( @@ -126,48 +125,97 @@ def run(self): zone = zo.id, ignore_missing = True ) + if rs: + self.conn.dns.delete_recordset( + recordset = rs.id, + zone = zo.id + ) + changed = True if not rs: - self.exit( - changed=False, - message=('No Recordset found with name or id: %s' % - self.params['recordset_name']) - ) - self.conn.dns.delete_recordset( - recordset = rs.id, - zone = zo.id - ) - changed = True + self.exit( + changed=False, + message=('No recordset found with name or id: %s' % + self.params['zone_id']) + ) if self.params['state'] == 'present': attrs = {} - attrs['name'] = self.params['recordset_name'] - if self.params['description']: - attrs['description'] = self.params['description'] - if self.params['type']: - attrs['type'] = self.params['type'] - else: - self.exit( - changed=False, - message=('No type specified!') - ) - if self.params['ttl']: - attrs['ttl'] = self.params['ttl'] - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i+1 - # raise Exception(self.params['records'], len(self.params['records']), ' ', attrs['records'][1]) - else: - self.exit( - changed=False, - message=('No records specified!') - ) - - rset = self.conn.dns.create_recordset(zone = zo.id , **attrs) - self.exit(changed=True, rset=rset.to_dict()) - + rs = self.conn.dns.find_recordset( + name_or_id = self.params['recordset_name'], + zone = zo.id, + ignore_missing = True + ) + + if not rs: + attrs['name'] = self.params['recordset_name'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['type']: + attrs['type'] = self.params['type'] + else: + self.exit( + changed=False, + message=('No type specified!') + ) + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i+1 + # raise Exception(self.params['records'], len(self.params['records']), ' ', attrs['records'][1]) + else: + self.exit( + changed=False, + message=('No records specified!') + ) + + rset = self.conn.dns.create_recordset(zone = zo.id , **attrs) + self.exit(changed=True, rset=rset.to_dict()) + + if rs: + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i+1 + + # That's not a good way of doing it + if self.params['description'] and not self.params['ttl']: + rset = self.conn.dns.update_recordset( + zone_id = zo.id, + recordset = rs.id, + description = self.params['description'], + records = attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and not self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id = zo.id, + recordset = rs.id, + ttl = self.params['ttl'], + records = attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id = zo.id, + recordset = rs.id, + ttl = self.params['ttl'], + description = self.params['description'], + records = attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + else: + rset = self.conn.dns.update_recordset( + zone_id = zo.id, + recordset = rs.id, + records = attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) From cda1665380330925fc7561b7a5fcb362853d3fe2 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 10:14:21 +0000 Subject: [PATCH 14/50] Fixed many errors in nameserver_info --- plugins/modules/dns_nameserver_info.py | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index 2a60bb26..9f79442b 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -104,18 +104,31 @@ def run(self): self.params['zone']) ) - if self.params['priority']: - query['priority'] = self.params['priority'] - if self.params['priority']: - query['address'] = self.params['priority'] - if self.params['priority']: - query['priority'] = self.params['priority'] - 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 From a0804b47b5f776bd8f8c409f8c1654396b05461f Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 10:16:31 +0000 Subject: [PATCH 15/50] Fixed spelling --- plugins/modules/dns_recordset_info.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index ad0b93a3..adadf5af 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -28,7 +28,7 @@ description: - Description of the Record Set type: str - create_at: + created_at: description: - Time of creation type: str @@ -52,7 +52,7 @@ description: - Record set type type: str - update_at: + updated_at: description: - Last Update time type: str @@ -79,7 +79,7 @@ description: Description of the Record type: str sample: "MyRecord123" - create_at: + created_at: description: Time of creation type: str sample: "2020-09-29T12:28:59.721" @@ -103,7 +103,7 @@ description: Record set type type: str sample: "AAAA" - update_at: + updated_at: description: Last Update time type: str sample: "2020-09-29T12:28:59.721" @@ -134,8 +134,8 @@ class DNSRecordsetsInfoModule(OTCModule): name=dict(required=False), description=dict(required=False), ttl=dict(required=False, type='int'), - create_at=dict(required=False), - update_at=dict(required=False), + created_at=dict(required=False), + updated_at=dict(required=False), default=dict(required=False, type='bool'), project_id=dict(required=False) ) @@ -182,13 +182,13 @@ def run(self): del data[i] i = 0 continue - if self.params['create_at']: - if data[i]['create_at'] != self.params['create_at']: + if self.params['created_at']: + if data[i]['created_at'] != self.params['created_at']: del data[i] i = 0 continue - if self.params['update_at']: - if data[i]['update_at'] != self.params['update_at']: + if self.params['updated_at']: + if data[i]['updated_at'] != self.params['updated_at']: del data[i] i = 0 continue From 3c6d76b765bda58363df22a7e1134c65db94d392 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 10:24:01 +0000 Subject: [PATCH 16/50] Removed Find function --- plugins/modules/dns_recordset_info.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index adadf5af..541591c9 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -150,19 +150,7 @@ def run(self): if self.params['type']: query['type'] = self.params['type'] if self.params['name']: - rs = self.conn.dns.find_recordset( - zone=self.params['zone_id'], - name_or_id=self.params['name'], - ignore_missing=True) - if rs: - query['name'] = rs.name - else: - self.exit( - changed=False, - nat_gateways=[], - message=('No entry found with name or id: %s' % - 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() From 358289f9206de2fa29338a8dde27931185e16f5f Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 10:49:15 +0000 Subject: [PATCH 17/50] Fixed pep8 issues --- plugins/modules/dns_recordset.py | 163 +++++++++++++++---------------- 1 file changed, 80 insertions(+), 83 deletions(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index bdbb86da..523ae38e 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -108,8 +108,8 @@ def run(self): data = [] zo = self.conn.dns.find_zone( - name_or_id = self.params['zone_id'], - ignore_missing = True + name_or_id=self.params['zone_id'], + ignore_missing=True ) if not zo: self.exit( @@ -121,103 +121,100 @@ def run(self): if self.params['state'] == 'absent': changed = False rs = self.conn.dns.find_recordset( - name_or_id = self.params['recordset_name'], - zone = zo.id, - ignore_missing = True + name_or_id=self.params['recordset_name'], + zone=zo.id, + ignore_missing=True ) if rs: self.conn.dns.delete_recordset( - recordset = rs.id, - zone = zo.id + recordset=rs.id, + zone=zo.id ) changed = True if not rs: self.exit( changed=False, message=('No recordset found with name or id: %s' % - self.params['zone_id']) + self.params['zone_id']) ) if self.params['state'] == 'present': - attrs = {} - rs = self.conn.dns.find_recordset( - name_or_id = self.params['recordset_name'], - zone = zo.id, - ignore_missing = True + attrs = {} + rs = self.conn.dns.find_recordset( + name_or_id=self.params['recordset_name'], + zone=zo.id, + ignore_missing=True ) - - if not rs: - attrs['name'] = self.params['recordset_name'] - if self.params['description']: - attrs['description'] = self.params['description'] - if self.params['type']: - attrs['type'] = self.params['type'] - else: - self.exit( - changed=False, - message=('No type specified!') - ) - if self.params['ttl']: - attrs['ttl'] = self.params['ttl'] - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i+1 - # raise Exception(self.params['records'], len(self.params['records']), ' ', attrs['records'][1]) - else: - self.exit( - changed=False, - message=('No records specified!') - ) - - rset = self.conn.dns.create_recordset(zone = zo.id , **attrs) - self.exit(changed=True, rset=rset.to_dict()) - - if rs: - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i+1 - - # That's not a good way of doing it - if self.params['description'] and not self.params['ttl']: - rset = self.conn.dns.update_recordset( - zone_id = zo.id, - recordset = rs.id, - description = self.params['description'], - records = attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and not self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id = zo.id, - recordset = rs.id, - ttl = self.params['ttl'], - records = attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id = zo.id, - recordset = rs.id, - ttl = self.params['ttl'], - description = self.params['description'], - records = attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - else: - rset = self.conn.dns.update_recordset( - zone_id = zo.id, - recordset = rs.id, - records = attrs['records'] + + if not rs: + attrs['name'] = self.params['recordset_name'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['type']: + attrs['type'] = self.params['type'] + else: + self.exit( + changed=False, + message=('No type specified!') + ) + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i + 1 + else: + self.exit( + changed=False, + message=('No records specified!') ) - self.exit(changed=True, rset=rset.to_dict()) + rset = self.conn.dns.create_recordset(zone=zo.id, **attrs) + self.exit(changed=True, rset=rset.to_dict()) + if rs: + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i + 1 + + # That's not a good way of doing it + if self.params['description'] and not self.params['ttl']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + description=self.params['description'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and not self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + ttl=self.params['ttl'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + ttl=self.params['ttl'], + description=self.params['description'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + else: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) self.exit( changed=changed From 5c10501d63fca967c70e6098c0f34336fe7eecdf Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 11:07:03 +0000 Subject: [PATCH 18/50] Added correct Docu --- plugins/modules/dns_recordset.py | 77 ++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 523ae38e..649716dc 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -20,64 +20,85 @@ description: - Get DNS PTR Records from the OTC. options: - address: - description: - - EIP address - type: str description: description: - Description of the Record type: str - id: + records: description: - - PTR record ID - type: str - ptrdname: + - IP Records of the entry. Type is a list + type: list + required: true + recordset_name: description: - - Domain name of the PTR record + - Can be name or ID of the recordset. When creating a new one please enter a name type: str - status: + required: true + state: description: - - Resource status + - State, either absent or present type: str + choices: [present, absent] + default: present ttl: description: - - PTR record cache duration (in second) on a local DNS server + - Cache duration (in second) on a local DNS server type: int + type: + description: + - Record set type + type: str + zone_id: + description: + - Zone ID of the recordset + type: str + required: true requirements: ["openstacksdk", "otcextensions"] ''' RETURN = ''' -ptr_records: +rset: 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 + description: ID + type: str + sample: "fe80804323f2065d0175980e81617c10" + records: + description: IP Records of the entry. Type is a list type: str - sample: "eu-de:fe864230-d3bc-4391-8a32-394c3e9ca22d" - ptrdname: - description: Domain name of the PTR record + sample: "[ + 1.3.1.2, + 121.111.111.111, + 145.145.145.145 + ]" + name: + description: Name type: str - sample: "example.com" + sample: "test.test2." status: description: Resource status type: str sample: "ACTIVE" ttl: - description: PTR record cache duration (in second) on a local DNS server + description: Cache duration (in second) on a local DNS server type: int sample: 300 + type: + description: Recordset Type + type: str + sample: "A" + zone_name: + description: Zone Name + type: str + sample: "test." ''' @@ -94,13 +115,13 @@ class DNSRecordsetModule(OTCModule): argument_spec = dict( - zone_id=dict(required=True), - recordset_name=dict(required=True), description=dict(required=False), - type=dict(required=False), - ttl=dict(required=False, type='int'), records=dict(required=True, type='list'), - state=dict(type='str', choices=['present', 'absent'], default='present') + recordset_name=dict(required=True), + state=dict(type='str', choices=['present', 'absent'], default='present'), + ttl=dict(required=False, type='int'), + type=dict(required=False), + zone_id=dict(required=True) ) def run(self): From 2360b601ee48ccc6f684966025919b85ef8bf9d6 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 5 Nov 2020 11:09:59 +0000 Subject: [PATCH 19/50] Added working example --- plugins/modules/dns_floating_ip.py | 2 +- plugins/modules/dns_recordset.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index a1d11c26..dfe0a610 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -79,7 +79,7 @@ EXAMPLES = ''' # Creating a record: - name: Creating a record - dns_floating_ip: + opentelekomcloud.cloud.dns_floating_ip: floating_ip: 123.123.123.123 ptrdname: "test2.com." description: "test2nownow" diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 649716dc..15930c63 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -103,10 +103,18 @@ ''' EXAMPLES = ''' -# Get Nameserver Info about a zone: -- name: Getting Info - dns_floating_ip_info: - description: "Test" +# Creating / Updating a recordset: +- name: Testing + opentelekomcloud.cloud.dns_recordset: + zone_id: fe80829272374c340174d8e94bb9562c + recordset_name: "test.test2." + state: present + ttl: 400 + type: A + records: + - "1.3.1.2" + - "121.111.111.111" + - "145.145.145.145" ''' From d7005e63f9e2240349799bfb538d8643e37d08af Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Thu, 5 Nov 2020 13:20:59 +0000 Subject: [PATCH 20/50] recordset update --- plugins/modules/dns_recordset.py | 107 +++++++++++-------------------- 1 file changed, 39 insertions(+), 68 deletions(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 15930c63..64391251 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -28,6 +28,7 @@ description: - IP Records of the entry. Type is a list type: list + elements: str required: true recordset_name: description: @@ -58,7 +59,7 @@ ''' RETURN = ''' -rset: +recordset: description: Get DNS PTR Records type: complex returned: On Success. @@ -124,7 +125,7 @@ class DNSRecordsetModule(OTCModule): argument_spec = dict( description=dict(required=False), - records=dict(required=True, type='list'), + records=dict(required=True, type='list', elements='str'), recordset_name=dict(required=True), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), @@ -143,38 +144,51 @@ def run(self): if not zo: self.exit( changed=False, + failed=True, message=('No Zone found with name or id: %s' % self.params['zone_id']) ) + rs = self.conn.dns.find_recordset( + name_or_id=self.params['recordset_name'], + zone=zo.id, + ignore_missing=True + ) + + # recordset deletion if self.params['state'] == 'absent': changed = False - rs = self.conn.dns.find_recordset( - name_or_id=self.params['recordset_name'], - zone=zo.id, - ignore_missing=True - ) if rs: self.conn.dns.delete_recordset( recordset=rs.id, zone=zo.id ) changed = True - if not rs: - self.exit( - changed=False, - message=('No recordset found with name or id: %s' % - self.params['zone_id']) - ) if self.params['state'] == 'present': attrs = {} - rs = self.conn.dns.find_recordset( - name_or_id=self.params['recordset_name'], - zone=zo.id, - ignore_missing=True - ) + # Modify recordset + if rs: + if self.params['records']: + for item in self.params['records']: + if item not in rs.records: + # user is intended to overwrite whole recordset + attrs['records'] = self.params['records'] + break + + if self.params['description'] and (self.params['description'] != rs.description): + attrs['description'] = self.params['description'] + if self.params['ttl'] and (self.params['ttl'] != rs.ttl): + attrs['ttl'] = self.params['ttl'] + + if attrs: + attrs['recordset'] = rs.id + attrs['zone_id'] = zo.id + recordset = self.conn.dns.update_recordset(**attrs) + self.exit(changed=True, recordset=recordset.to_dict()) + + # create recordset if not rs: attrs['name'] = self.params['recordset_name'] if self.params['description']: @@ -184,66 +198,23 @@ def run(self): else: self.exit( changed=False, - message=('No type specified!') + failed=True, + message=('Type is mandatory for recordset creation') ) if self.params['ttl']: attrs['ttl'] = self.params['ttl'] if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i + 1 + attrs['records'] = self.params['records'] else: self.exit( changed=False, - message=('No records specified!') + failed=True, + message=('No records specified for recordset ' + 'creation.') ) rset = self.conn.dns.create_recordset(zone=zo.id, **attrs) - self.exit(changed=True, rset=rset.to_dict()) - - if rs: - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i + 1 - - # That's not a good way of doing it - if self.params['description'] and not self.params['ttl']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - description=self.params['description'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and not self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - ttl=self.params['ttl'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - ttl=self.params['ttl'], - description=self.params['description'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - else: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) + self.exit(changed=True, recordset=rset.to_dict()) self.exit( changed=changed From 1ebcd49ad801c72766c75bdd5182868e2842a550 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 6 Nov 2020 10:24:20 +0000 Subject: [PATCH 21/50] New File for zone --- plugins/modules/dns_floating_ip.py | 2 +- plugins/modules/dns_recordset.py | 2 +- plugins/modules/dns_zones.py | 246 +++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 plugins/modules/dns_zones.py diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index dfe0a610..f34b63b8 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -15,7 +15,7 @@ module: dns_floating_ip short_description: Get DNS PTR Records extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS PTR Records from the OTC. diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 15930c63..52828983 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -15,7 +15,7 @@ module: dns_recordset short_description: Get DNS PTR Records extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS PTR Records from the OTC. diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py new file mode 100644 index 00000000..f8409c65 --- /dev/null +++ b/plugins/modules/dns_zones.py @@ -0,0 +1,246 @@ +#!/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 +short_description: Get DNS PTR Records +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.0.1" +author: "Sebastian Gode (@SebastianGode)" +description: + - Get DNS PTR Records from the OTC. +options: + description: + description: + - Description of the Record + type: str + records: + description: + - IP Records of the entry. Type is a list + type: list + required: true + recordset_name: + description: + - Can be name or ID of the recordset. When creating a new one please enter a name + type: str + required: true + state: + description: + - State, either absent or present + type: str + choices: [present, absent] + default: present + ttl: + description: + - Cache duration (in second) on a local DNS server + type: int + type: + description: + - Record set type + type: str + zone_id: + description: + - Zone ID of the recordset + type: str + required: true + +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +rset: + description: Get DNS PTR Records + type: complex + returned: On Success. + contains: + description: + description: Description of the Record + type: str + sample: "MyRecord123" + id: + description: ID + type: str + sample: "fe80804323f2065d0175980e81617c10" + records: + description: IP Records of the entry. Type is a list + type: str + sample: "[ + 1.3.1.2, + 121.111.111.111, + 145.145.145.145 + ]" + name: + description: Name + type: str + sample: "test.test2." + status: + description: Resource status + type: str + sample: "ACTIVE" + ttl: + description: Cache duration (in second) on a local DNS server + type: int + sample: 300 + type: + description: Recordset Type + type: str + sample: "A" + zone_name: + description: Zone Name + type: str + sample: "test." + +''' + +EXAMPLES = ''' +# Creating / Updating a recordset: +- name: Testing + opentelekomcloud.cloud.dns_recordset: + zone_id: fe80829272374c340174d8e94bb9562c + recordset_name: "test.test2." + state: present + ttl: 400 + type: A + records: + - "1.3.1.2" + - "121.111.111.111" + - "145.145.145.145" + +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class DNSRecordsetModule(OTCModule): + argument_spec = dict( + description=dict(required=False), + email=dict(required=True, type='list'), + name=dict(required=True), + state=dict(type='str', choices=['present', 'absent'], default='present'), + ttl=dict(required=False, type='int'), + zone_type=dict(required=True) + ) + + def run(self): + changed = False + data = [] + + zo = self.conn.dns.find_zone( + name_or_id=self.params['name'], + ignore_missing=True + ) + + if self.params['state'] == 'absent': + changed = False + if zo: + self.conn.dns.delete_zone( + zone=zo.id + ) + changed = True + if not rs: + self.exit( + changed=False, + message=('No Zone found with name: %s' % + self.params['name']) + ) + + if self.params['state'] == 'present': + attrs = {} + rs = self.conn.dns.find_recordset( + name_or_id=self.params['recordset_name'], + zone=zo.id, + ignore_missing=True + ) + + if not rs: + attrs['name'] = self.params['recordset_name'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['type']: + attrs['type'] = self.params['type'] + else: + self.exit( + changed=False, + message=('No type specified!') + ) + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i + 1 + else: + self.exit( + changed=False, + message=('No records specified!') + ) + + rset = self.conn.dns.create_recordset(zone=zo.id, **attrs) + self.exit(changed=True, rset=rset.to_dict()) + + if rs: + if self.params['records']: + attrs['records'] = [] + i = 0 + while i < len(self.params['records']): + attrs['records'].append(self.params['records'][i]) + i = i + 1 + + # That's not a good way of doing it + if self.params['description'] and not self.params['ttl']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + description=self.params['description'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and not self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + ttl=self.params['ttl'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + elif self.params['ttl'] and self.params['description']: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + ttl=self.params['ttl'], + description=self.params['description'], + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + else: + rset = self.conn.dns.update_recordset( + zone_id=zo.id, + recordset=rs.id, + records=attrs['records'] + ) + self.exit(changed=True, rset=rset.to_dict()) + + self.exit( + changed=changed + ) + + +def main(): + module = DNSRecordsetModule() + module() + + +if __name__ == '__main__': + main() From 02c1f29a68428d86684e18467d401f979f9bfb19 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 10 Nov 2020 09:11:20 +0000 Subject: [PATCH 22/50] First semi working zone script --- plugins/modules/dns_zones.py | 74 +++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index f8409c65..7c705d73 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -124,8 +124,9 @@ class DNSRecordsetModule(OTCModule): argument_spec = dict( description=dict(required=False), - email=dict(required=True, type='list'), + email=dict(required=False), name=dict(required=True), + router=dict(required=False), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), zone_type=dict(required=True) @@ -134,34 +135,71 @@ class DNSRecordsetModule(OTCModule): def run(self): changed = False data = [] + query = {} - zo = self.conn.dns.find_zone( - name_or_id=self.params['name'], - ignore_missing=True - ) - - if self.params['state'] == 'absent': - changed = False + # find_zone doesn't support searching for private zones with name + # As a result we use it only to search in public zones + if self.params['zone_type'] == 'public': + zo = self.conn.dns.find_zone( + name_or_id=self.params['name'], + ignore_missing=True + ) if zo: - self.conn.dns.delete_zone( - zone=zo.id + zone_id = zo.id + else: + self.exit( + changed=False, + message=('No Zone found with name: %s' % + self.params['name']) ) - changed = True - if not rs: + + + # For private Zones we list all zones and then filter by name + if self.params['zone_type'] == 'private': + query['zone_type'] = self.params['zone_type'] + for raw in self.conn.dns.zones(**query): + dt = raw.to_dict() + dt.pop('location') + data.append(dt) + # Query parameter name is not supported, so we need to filter it by hand + i = 0 + while i < len(data): + if data[i]['name'] != self.params['name']: + del data[i] + i = 0 + continue + i = i+1 + # As we remove datasets we need to check wether there's the correct one left to obtain the ID + if len(data) != 0: + zone_id = data[0]['id'] + else: self.exit( changed=False, message=('No Zone found with name: %s' % self.params['name']) ) - if self.params['state'] == 'present': - attrs = {} - rs = self.conn.dns.find_recordset( - name_or_id=self.params['recordset_name'], - zone=zo.id, - ignore_missing=True + # We now have the zone_id to work with + if self.params['state'] == 'absent': + changed = False + # No check for zone_id necessary as we checked it + self.conn.dns.delete_zone( + zone=zone_id ) + changed = True + if self.params['state'] == 'present': + attrs = {} + # Check if VPC exists + if self.params['zone_type'] == 'private': + ro = self.conn.network.find_router( + name_or_id=self.params['router'], + ignore_missing=True + ) + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['email']: + attrs['email'] = self.params['email'] if not rs: attrs['name'] = self.params['recordset_name'] if self.params['description']: From 212f16fedb01c7912cdfa69cc8c8a6cfb672eabb Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 10 Nov 2020 10:02:54 +0000 Subject: [PATCH 23/50] Added Zone creation --- plugins/modules/dns_zones.py | 114 +++++++++++------------------------ 1 file changed, 34 insertions(+), 80 deletions(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index 7c705d73..e8d35932 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -126,7 +126,7 @@ class DNSRecordsetModule(OTCModule): description=dict(required=False), email=dict(required=False), name=dict(required=True), - router=dict(required=False), + router_id=dict(required=False), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), zone_type=dict(required=True) @@ -139,6 +139,7 @@ def run(self): # find_zone doesn't support searching for private zones with name # As a result we use it only to search in public zones + if self.params['zone_type'] == 'public': zo = self.conn.dns.find_zone( name_or_id=self.params['name'], @@ -147,11 +148,12 @@ def run(self): if zo: zone_id = zo.id else: - self.exit( - changed=False, - message=('No Zone found with name: %s' % - self.params['name']) - ) + if self.params['state'] == 'absent': + self.exit( + changed=False, + message=('No Zone found with name: %s' % + self.params['name']) + ) # For private Zones we list all zones and then filter by name @@ -173,11 +175,12 @@ def run(self): if len(data) != 0: zone_id = data[0]['id'] else: - self.exit( - changed=False, - message=('No Zone found with name: %s' % - self.params['name']) - ) + if self.params['state'] == 'absent': + self.exit( + changed=False, + message=('No Zone found with name: %s' % + self.params['name']) + ) # We now have the zone_id to work with if self.params['state'] == 'absent': @@ -190,85 +193,36 @@ def run(self): if self.params['state'] == 'present': attrs = {} + changed = False # Check if VPC exists if self.params['zone_type'] == 'private': ro = self.conn.network.find_router( - name_or_id=self.params['router'], + name_or_id=self.params['router_id'], ignore_missing=True ) + if ro: + # Somehow the API wants a dict wiuth router_id in it + routerdict = { + 'router_id': ro.id + } + attrs['router'] = routerdict + else: + self.exit( + changed=False, + message=('No Router found with name or id: %s' % + self.params['router']) + ) + attrs['zone_type'] = self.params['zone_type'] if self.params['description']: attrs['description'] = self.params['description'] if self.params['email']: attrs['email'] = self.params['email'] - if not rs: - attrs['name'] = self.params['recordset_name'] - if self.params['description']: - attrs['description'] = self.params['description'] - if self.params['type']: - attrs['type'] = self.params['type'] - else: - self.exit( - changed=False, - message=('No type specified!') - ) - if self.params['ttl']: - attrs['ttl'] = self.params['ttl'] - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i + 1 - else: - self.exit( - changed=False, - message=('No records specified!') - ) + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + attrs['name'] = self.params['name'] - rset = self.conn.dns.create_recordset(zone=zo.id, **attrs) - self.exit(changed=True, rset=rset.to_dict()) - - if rs: - if self.params['records']: - attrs['records'] = [] - i = 0 - while i < len(self.params['records']): - attrs['records'].append(self.params['records'][i]) - i = i + 1 - - # That's not a good way of doing it - if self.params['description'] and not self.params['ttl']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - description=self.params['description'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and not self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - ttl=self.params['ttl'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - elif self.params['ttl'] and self.params['description']: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - ttl=self.params['ttl'], - description=self.params['description'], - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) - else: - rset = self.conn.dns.update_recordset( - zone_id=zo.id, - recordset=rs.id, - records=attrs['records'] - ) - self.exit(changed=True, rset=rset.to_dict()) + zone = self.conn.dns.create_zone(**attrs) + self.exit(changed=True, zone=zone.to_dict()) self.exit( changed=changed From 5fe003df7c3a2fc78afd24c9ae9344a1dc98853c Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 10 Nov 2020 10:17:09 +0000 Subject: [PATCH 24/50] Fully working zone script - docu missing --- plugins/modules/dns_zones.py | 91 ++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index e8d35932..49d4aecc 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -12,10 +12,10 @@ # limitations under the License. DOCUMENTATION = ''' -module: dns_recordset +module: dns_zones short_description: Get DNS PTR Records extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.0.1" +version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS PTR Records from the OTC. @@ -58,7 +58,7 @@ ''' RETURN = ''' -rset: +zone: description: Get DNS PTR Records type: complex returned: On Success. @@ -121,7 +121,7 @@ from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule -class DNSRecordsetModule(OTCModule): +class DNSZonesModule(OTCModule): argument_spec = dict( description=dict(required=False), email=dict(required=False), @@ -139,7 +139,6 @@ def run(self): # find_zone doesn't support searching for private zones with name # As a result we use it only to search in public zones - if self.params['zone_type'] == 'public': zo = self.conn.dns.find_zone( name_or_id=self.params['name'], @@ -147,7 +146,9 @@ def run(self): ) if zo: zone_id = zo.id + zone_ceck = True else: + zone_check = False if self.params['state'] == 'absent': self.exit( changed=False, @@ -174,7 +175,9 @@ def run(self): # As we remove datasets we need to check wether there's the correct one left to obtain the ID if len(data) != 0: zone_id = data[0]['id'] + zone_check = True else: + zone_check = False if self.params['state'] == 'absent': self.exit( changed=False, @@ -194,45 +197,53 @@ def run(self): if self.params['state'] == 'present': attrs = {} changed = False - # Check if VPC exists - if self.params['zone_type'] == 'private': - ro = self.conn.network.find_router( - name_or_id=self.params['router_id'], - ignore_missing=True - ) - if ro: - # Somehow the API wants a dict wiuth router_id in it - routerdict = { - 'router_id': ro.id - } - attrs['router'] = routerdict - else: - self.exit( - changed=False, - message=('No Router found with name or id: %s' % - self.params['router']) - ) - attrs['zone_type'] = self.params['zone_type'] - if self.params['description']: - attrs['description'] = self.params['description'] - if self.params['email']: - attrs['email'] = self.params['email'] - if self.params['ttl']: - attrs['ttl'] = self.params['ttl'] - attrs['name'] = self.params['name'] - - zone = self.conn.dns.create_zone(**attrs) - self.exit(changed=True, zone=zone.to_dict()) - - self.exit( - changed=changed - ) + if zone_check == False: + # Check if VPC exists + if self.params['zone_type'] == 'private': + ro = self.conn.network.find_router( + name_or_id=self.params['router_id'], + ignore_missing=True + ) + if ro: + # Somehow the API wants a dict wiuth router_id in it + routerdict = { + 'router_id': ro.id + } + attrs['router'] = routerdict + else: + self.exit( + changed=False, + message=('No Router found with name or id: %s' % + self.params['router']) + ) + attrs['zone_type'] = self.params['zone_type'] + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['email']: + attrs['email'] = self.params['email'] + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + attrs['name'] = self.params['name'] + + zone = self.conn.dns.create_zone(**attrs) + self.exit(changed=True, zone=zone.to_dict()) + + if zone_check == True: + if self.params['description']: + attrs['description'] = self.params['description'] + if self.params['email']: + attrs['email'] = self.params['email'] + if self.params['ttl']: + attrs['ttl'] = self.params['ttl'] + attrs['zone'] = zone_id + + zone = self.conn.dns.update_zone(**attrs) + self.exit(changed=True, zone=zone.to_dict()) def main(): - module = DNSRecordsetModule() + module = DNSZonesModule() module() - if __name__ == '__main__': main() From 4088dffcd095edc879b2272e6f0f7f60b52ddd10 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 10 Nov 2020 10:40:53 +0000 Subject: [PATCH 25/50] Fixed Pep8, added docu --- plugins/modules/dns_floating_ip.py | 6 +- plugins/modules/dns_recordset.py | 6 +- plugins/modules/dns_zones.py | 118 ++++++++++++++--------------- tests/sanity/ignore-2.10.txt | 1 + tests/sanity/ignore-2.9.txt | 1 + 5 files changed, 67 insertions(+), 65 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index f34b63b8..d2e6fc7f 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -13,12 +13,12 @@ DOCUMENTATION = ''' module: dns_floating_ip -short_description: Get DNS PTR Records +short_description: Modify DNS Floating IPs extends_documentation_fragment: opentelekomcloud.cloud.otc version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - - Get DNS PTR Records from the OTC. + - Modify DNS Floating IPs options: description: description: @@ -49,7 +49,7 @@ RETURN = ''' ptr_records: - description: Get DNS PTR Records + description: Modify DNS floating IPs type: complex returned: On Success. contains: diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index f073d5a1..70438c53 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -13,12 +13,12 @@ DOCUMENTATION = ''' module: dns_recordset -short_description: Get DNS PTR Records +short_description: Modify DNS Recordsets extends_documentation_fragment: opentelekomcloud.cloud.otc version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - - Get DNS PTR Records from the OTC. + - Modify DNS Recordsets options: description: description: @@ -60,7 +60,7 @@ RETURN = ''' recordset: - description: Get DNS PTR Records + description: Modify DNS PTR Records type: complex returned: On Success. contains: diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index 49d4aecc..4a50bea4 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -22,18 +22,21 @@ options: description: description: - - Description of the Record + - Description of the Zone type: str - records: + email: description: - - IP Records of the entry. Type is a list - type: list - required: true - recordset_name: + - E-Mail Address + type: str + name: description: - - Can be name or ID of the recordset. When creating a new one please enter a name + - Zone Name type: str required: true + router_id: + description: + - VPC ID, required when creating an private Zone + type: str state: description: - State, either absent or present @@ -44,77 +47,73 @@ description: - Cache duration (in second) on a local DNS server type: int - type: - description: - - Record set type - type: str - zone_id: + zone_type: description: - - Zone ID of the recordset + - Zone Type, either public or private type: str - required: true + choices: [public, private] + default: public requirements: ["openstacksdk", "otcextensions"] ''' RETURN = ''' zone: - description: Get DNS PTR Records + description: Modfiy DNS Zones type: complex returned: On Success. contains: description: - description: Description of the Record + description: Description of the Zone + type: str + sample: "MyZone123" + email: + description: assigned E-Mail of the Zone type: str - sample: "MyRecord123" + sample: "mail@mail.com" id: - description: ID + description: Zone ID type: str sample: "fe80804323f2065d0175980e81617c10" - records: - description: IP Records of the entry. Type is a list - type: str - sample: "[ - 1.3.1.2, - 121.111.111.111, - 145.145.145.145 - ]" name: - description: Name + description: Name of the zone type: str sample: "test.test2." + router: + description: Assigned VPC + type: list + sample: "[ + router_id: 79c32783-e560-4e3a-95b1-5a0756441e12, + router_region: eu-de, + status: PENDING_CREATE + ]" status: description: Resource status type: str - sample: "ACTIVE" + sample: "PENDING_CREATE" ttl: description: Cache duration (in second) on a local DNS server type: int sample: 300 - type: - description: Recordset Type - type: str - sample: "A" - zone_name: - description: Zone Name + zone_type: + description: Zone Type, either public or private type: str - sample: "test." + sample: "private" ''' EXAMPLES = ''' -# Creating / Updating a recordset: +# Creating / Updating a Zone: - name: Testing - opentelekomcloud.cloud.dns_recordset: - zone_id: fe80829272374c340174d8e94bb9562c - recordset_name: "test.test2." + opentelekomcloud.cloud.dns_zones: + name: "test.com." state: present - ttl: 400 - type: A - records: - - "1.3.1.2" - - "121.111.111.111" - - "145.145.145.145" + zone_type: private + router_id: 79c32783-e560-4e3a-95b1-5a0756441e12 + description: test2 + ttl: 5000 + email: mail2@mail2.test + ''' @@ -129,7 +128,7 @@ class DNSZonesModule(OTCModule): router_id=dict(required=False), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), - zone_type=dict(required=True) + zone_type=dict(type='str', choices=['public', 'private'], default='public') ) def run(self): @@ -146,17 +145,16 @@ def run(self): ) if zo: zone_id = zo.id - zone_ceck = True + zone_check = True else: zone_check = False if self.params['state'] == 'absent': self.exit( changed=False, message=('No Zone found with name: %s' % - self.params['name']) + self.params['name']) ) - # For private Zones we list all zones and then filter by name if self.params['zone_type'] == 'private': query['zone_type'] = self.params['zone_type'] @@ -171,9 +169,9 @@ def run(self): del data[i] i = 0 continue - i = i+1 + i = i + 1 # As we remove datasets we need to check wether there's the correct one left to obtain the ID - if len(data) != 0: + if len(data) != 0: zone_id = data[0]['id'] zone_check = True else: @@ -182,7 +180,7 @@ def run(self): self.exit( changed=False, message=('No Zone found with name: %s' % - self.params['name']) + self.params['name']) ) # We now have the zone_id to work with @@ -198,14 +196,14 @@ def run(self): attrs = {} changed = False - if zone_check == False: + if zone_check is False: # Check if VPC exists if self.params['zone_type'] == 'private': ro = self.conn.network.find_router( name_or_id=self.params['router_id'], ignore_missing=True ) - if ro: + if ro: # Somehow the API wants a dict wiuth router_id in it routerdict = { 'router_id': ro.id @@ -213,10 +211,10 @@ def run(self): attrs['router'] = routerdict else: self.exit( - changed=False, - message=('No Router found with name or id: %s' % - self.params['router']) - ) + changed=False, + message=('No Router found with name or id: %s' % + self.params['router']) + ) attrs['zone_type'] = self.params['zone_type'] if self.params['description']: attrs['description'] = self.params['description'] @@ -229,7 +227,7 @@ def run(self): zone = self.conn.dns.create_zone(**attrs) self.exit(changed=True, zone=zone.to_dict()) - if zone_check == True: + if zone_check is True: if self.params['description']: attrs['description'] = self.params['description'] if self.params['email']: @@ -241,9 +239,11 @@ def run(self): zone = self.conn.dns.update_zone(**attrs) self.exit(changed=True, zone=zone.to_dict()) + def main(): module = DNSZonesModule() module() + if __name__ == '__main__': main() diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 8d83be9e..628ac9e4 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -5,6 +5,7 @@ plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license plugins/modules/dns_floating_ip.py validate-modules:missing-gplv3-license plugins/modules/dns_recordset.py validate-modules:missing-gplv3-license +plugins/modules/dns_zones.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer_info.py validate-modules:missing-gplv3-license plugins/modules/nat_gateway_info.py validate-modules:missing-gplv3-license diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 14e64bd7..efb270c2 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -5,6 +5,7 @@ plugins/modules/cce_cluster_cert_info.py validate-modules:missing-gplv3-license plugins/modules/cce_cluster_info.py validate-modules:missing-gplv3-license plugins/modules/dns_floating_ip.py validate-modules:missing-gplv3-license plugins/modules/dns_recordset.py validate-modules:missing-gplv3-license +plugins/modules/dns_zones.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer.py validate-modules:missing-gplv3-license plugins/modules/loadbalancer_info.py validate-modules:missing-gplv3-license plugins/modules/nat_dnat_rule_info.py validate-modules:missing-gplv3-license From c6ef466da83ba09896cbffae2993608a2f3544b5 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 10 Nov 2020 11:35:03 +0000 Subject: [PATCH 26/50] Fixed Typo --- plugins/modules/dns_zones.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index 4a50bea4..1ccb20bb 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -33,9 +33,9 @@ - Zone Name type: str required: true - router_id: + router: description: - - VPC ID, required when creating an private Zone + - VPC ID or name, required when creating an private Zone type: str state: description: @@ -109,7 +109,7 @@ name: "test.com." state: present zone_type: private - router_id: 79c32783-e560-4e3a-95b1-5a0756441e12 + router: 79c32783-e560-4e3a-95b1-5a0756441e12 description: test2 ttl: 5000 email: mail2@mail2.test @@ -125,7 +125,7 @@ class DNSZonesModule(OTCModule): description=dict(required=False), email=dict(required=False), name=dict(required=True), - router_id=dict(required=False), + router=dict(required=False), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), zone_type=dict(type='str', choices=['public', 'private'], default='public') @@ -200,11 +200,11 @@ def run(self): # Check if VPC exists if self.params['zone_type'] == 'private': ro = self.conn.network.find_router( - name_or_id=self.params['router_id'], + name_or_id=self.params['router'], ignore_missing=True ) if ro: - # Somehow the API wants a dict wiuth router_id in it + # Somehow the API wants a dict with router_id in it routerdict = { 'router_id': ro.id } From 9a6640141e6ac063d8ad1aa79faeefa11c403ae8 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 11 Nov 2020 08:27:38 +0000 Subject: [PATCH 27/50] Fixed Ansible Docu spaces and fixed changed on update --- plugins/modules/dns_floating_ip.py | 57 +++++++++------- plugins/modules/dns_recordset.py | 80 +++++++++++----------- plugins/modules/dns_zones.py | 106 ++++++++++++++++------------- 3 files changed, 131 insertions(+), 112 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index d2e6fc7f..5b044ac4 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -49,30 +49,30 @@ RETURN = ''' ptr_records: - description: Modify DNS floating IPs - type: complex - returned: On Success. - contains: - description: - description: Description of the Record - type: str - sample: "MyRecord123" - floating_ip: - description: Name or ID of the floating ip - type: str - sample: "123.123.123.123" - ptrdname: - description: Domain name of the PTR record required if updating/creating rule - 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 + description: Modify DNS floating IPs + type: complex + returned: On Success. + contains: + description: + description: Description of the Record + type: str + sample: "MyRecord123" + floating_ip: + description: Name or ID of the floating ip + type: str + sample: "123.123.123.123" + ptrdname: + description: Domain name of the PTR record required if updating/creating rule + 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 ''' @@ -137,7 +137,7 @@ def run(self): # get_floating_ip doesn't support ignore_missing and throws an error when there's nothing found. So we need to catch the error try: - self.conn.dns.get_floating_ip(floating_ip=('eu-de:' + fl.id)) + flip = self.conn.dns.get_floating_ip(floating_ip=('eu-de:' + fl.id)) except Exception: output = self.conn.dns.set_floating_ip(floating_ip=('eu-de:' + fl.id), **attrs) self.exit( @@ -145,9 +145,14 @@ def run(self): ptr=output.to_dict() ) else: + changed = False + if self.params['description'] != flip.description: + changed = True + if self.params['ttl'] != flip.ttl: + changed = True output = self.conn.dns.update_floating_ip(floating_ip=('eu-de:' + fl.id), **attrs) self.exit( - changed=True, + changed=changed, ptr=output.to_dict() ) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 70438c53..617e2b40 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -60,46 +60,46 @@ RETURN = ''' recordset: - description: Modify DNS PTR Records - type: complex - returned: On Success. - contains: - description: - description: Description of the Record - type: str - sample: "MyRecord123" - id: - description: ID - type: str - sample: "fe80804323f2065d0175980e81617c10" - records: - description: IP Records of the entry. Type is a list - type: str - sample: "[ - 1.3.1.2, - 121.111.111.111, - 145.145.145.145 - ]" - name: - description: Name - type: str - sample: "test.test2." - status: - description: Resource status - type: str - sample: "ACTIVE" - ttl: - description: Cache duration (in second) on a local DNS server - type: int - sample: 300 - type: - description: Recordset Type - type: str - sample: "A" - zone_name: - description: Zone Name - type: str - sample: "test." + description: Modify DNS PTR Records + type: complex + returned: On Success. + contains: + description: + description: Description of the Record + type: str + sample: "MyRecord123" + id: + description: ID + type: str + sample: "fe80804323f2065d0175980e81617c10" + records: + description: IP Records of the entry. Type is a list + type: str + sample: "[ + 1.3.1.2, + 121.111.111.111, + 145.145.145.145 + ]" + name: + description: Name + type: str + sample: "test.test2." + status: + description: Resource status + type: str + sample: "ACTIVE" + ttl: + description: Cache duration (in second) on a local DNS server + type: int + sample: 300 + type: + description: Recordset Type + type: str + sample: "A" + zone_name: + description: Zone Name + type: str + sample: "test." ''' diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index 1ccb20bb..f2677c6c 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -18,7 +18,7 @@ version_added: "0.1.2" author: "Sebastian Gode (@SebastianGode)" description: - - Get DNS PTR Records from the OTC. + - Get DNS PTR Records from the OTC. options: description: description: @@ -59,46 +59,46 @@ RETURN = ''' zone: - description: Modfiy DNS Zones - type: complex - returned: On Success. - contains: - description: - description: Description of the Zone - type: str - sample: "MyZone123" - email: - description: assigned E-Mail of the Zone - type: str - sample: "mail@mail.com" - id: - description: Zone ID - type: str - sample: "fe80804323f2065d0175980e81617c10" - name: - description: Name of the zone - type: str - sample: "test.test2." - router: - description: Assigned VPC - type: list - sample: "[ - router_id: 79c32783-e560-4e3a-95b1-5a0756441e12, - router_region: eu-de, - status: PENDING_CREATE - ]" - status: - description: Resource status - type: str - sample: "PENDING_CREATE" - ttl: - description: Cache duration (in second) on a local DNS server - type: int - sample: 300 - zone_type: - description: Zone Type, either public or private - type: str - sample: "private" + description: Modfiy DNS Zones + type: complex + returned: On Success. + contains: + description: + description: Description of the Zone + type: str + sample: "MyZone123" + email: + description: assigned E-Mail of the Zone + type: str + sample: "mail@mail.com" + id: + description: Zone ID + type: str + sample: "fe80804323f2065d0175980e81617c10" + name: + description: Name of the zone + type: str + sample: "test.test2." + router: + description: Assigned VPC + type: list + sample: "[ + router_id: 79c32783-e560-4e3a-95b1-5a0756441e12, + router_region: eu-de, + status: PENDING_CREATE + ]" + status: + description: Resource status + type: str + sample: "PENDING_CREATE" + ttl: + description: Cache duration (in second) on a local DNS server + type: int + sample: 300 + zone_type: + description: Zone Type, either public or private + type: str + sample: "private" ''' @@ -145,6 +145,9 @@ def run(self): ) if zo: zone_id = zo.id + zone_desc = zo.description + zone_ttl = zo.ttl + zone_email = zo.email zone_check = True else: zone_check = False @@ -173,6 +176,9 @@ def run(self): # As we remove datasets we need to check wether there's the correct one left to obtain the ID if len(data) != 0: zone_id = data[0]['id'] + zone_desc = data[0]['description'] + zone_ttl = data[0]['ttl'] + zone_email = data[0]['email'] zone_check = True else: zone_check = False @@ -194,7 +200,6 @@ def run(self): if self.params['state'] == 'present': attrs = {} - changed = False if zone_check is False: # Check if VPC exists @@ -228,16 +233,25 @@ def run(self): self.exit(changed=True, zone=zone.to_dict()) if zone_check is True: - if self.params['description']: + changed=False + # raise Exception("desc: ", zone_desc, "email: ", zone_email, "ttl: ", zone_ttl) + if self.params['description'] and self.params['description'] != zone_desc: attrs['description'] = self.params['description'] - if self.params['email']: + changed=True + if self.params['email'] and self.params['email'] != zone_email: attrs['email'] = self.params['email'] - if self.params['ttl']: + changed=True + if self.params['ttl'] and self.params['ttl'] != zone_ttl: attrs['ttl'] = self.params['ttl'] + changed=True attrs['zone'] = zone_id zone = self.conn.dns.update_zone(**attrs) - self.exit(changed=True, zone=zone.to_dict()) + self.exit(changed=changed, zone=zone.to_dict()) + + self.exit( + changed=changed + ) def main(): From 8134862e5f618530cb7373a7ad73ff717d83e9e7 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 11 Nov 2020 08:41:17 +0000 Subject: [PATCH 28/50] Fixed pep8 --- plugins/modules/dns_floating_ip.py | 1 - plugins/modules/dns_recordset.py | 1 - plugins/modules/dns_zones.py | 9 ++++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index 5b044ac4..294ac7c6 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -103,7 +103,6 @@ class DNSFloatingIpModule(OTCModule): def run(self): changed = False - data = [] fl = self.conn.network.find_ip( name_or_id=self.params['floating_ip'], diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 617e2b40..3a7749e7 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -135,7 +135,6 @@ class DNSRecordsetModule(OTCModule): def run(self): changed = False - data = [] zo = self.conn.dns.find_zone( name_or_id=self.params['zone_id'], diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index f2677c6c..787e6071 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -233,17 +233,16 @@ def run(self): self.exit(changed=True, zone=zone.to_dict()) if zone_check is True: - changed=False - # raise Exception("desc: ", zone_desc, "email: ", zone_email, "ttl: ", zone_ttl) + changed = False if self.params['description'] and self.params['description'] != zone_desc: attrs['description'] = self.params['description'] - changed=True + changed = True if self.params['email'] and self.params['email'] != zone_email: attrs['email'] = self.params['email'] - changed=True + changed = True if self.params['ttl'] and self.params['ttl'] != zone_ttl: attrs['ttl'] = self.params['ttl'] - changed=True + changed = True attrs['zone'] = zone_id zone = self.conn.dns.update_zone(**attrs) From 60535c86c6394c22f5b8567a4540db2ab2e5098c Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Wed, 11 Nov 2020 08:55:45 +0000 Subject: [PATCH 29/50] Fixed pep8 + removed spaces --- plugins/modules/dns_floating_ip_info.py | 58 ++++++------ plugins/modules/dns_nameserver_info.py | 40 ++++----- plugins/modules/dns_recordset_info.py | 88 +++++++++---------- plugins/modules/dns_zone_info.py | 112 ++++++++++++------------ 4 files changed, 149 insertions(+), 149 deletions(-) diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index e20a2b05..34496dca 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -50,34 +50,34 @@ 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 + 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 ''' @@ -120,7 +120,7 @@ def run(self): 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') diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index 9f79442b..fee4c497 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -43,26 +43,26 @@ 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" + 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 = ''' diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index 541591c9..d6f48def 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -67,50 +67,50 @@ 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" + 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" ''' diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index f036b017..52448473 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -71,62 +71,62 @@ 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" - record_num: - description: Number of record sets in the zone - type: int - sample: 3 - 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 - zone_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" - } + 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" + record_num: + description: Number of record sets in the zone + type: int + sample: 3 + 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 + zone_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" + } ''' From a13e3f236c0465fc8e41dfcbb08d06898c4a3e71 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 09:28:30 +0000 Subject: [PATCH 30/50] changed version --- plugins/modules/dns_floating_ip_info.py | 2 +- plugins/modules/dns_nameserver_info.py | 2 +- plugins/modules/dns_recordset_info.py | 2 +- plugins/modules/dns_zone_info.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index 34496dca..740f2da9 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -15,7 +15,7 @@ module: dns_floating_ip_info short_description: Get DNS PTR Records extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.1.2" +version_added: "0.2.1" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS PTR Records from the OTC. diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index fee4c497..4ae07fec 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -15,7 +15,7 @@ module: dns_nameserver_info short_description: Get DNS Nameserver Infos extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.1.2" +version_added: "0.2.1" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS Namerserver infos from the OTC. diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index d6f48def..3badd4a3 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -15,7 +15,7 @@ module: dns_recordset_info short_description: Get DNS Recordsets extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.1.2" +version_added: "0.2.1" author: "Sebastian Gode (@SebastianGode)" description: - Get DNS Recordsets from the OTC. diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index 52448473..3b83d617 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -15,7 +15,7 @@ module: dns_zone_info short_description: Get DNS Zone Infos extends_documentation_fragment: opentelekomcloud.cloud.otc -version_added: "0.1.2" +version_added: "0.2.1" author: "Sebastian Gode (@SebastianGode)" description: - Get NAT gateway info from the OTC. From fa37493db646c2ec6c146519ab950e9e1cd14e26 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 09:50:13 +0000 Subject: [PATCH 31/50] Added integration tests --- .../dns_floating_ip_info/tasks/main.yaml | 3 +-- .../dns_floating_ip_info/tasks/main.yaml.old | 3 +++ .../dns_nameserver_info/tasks/main.yaml | 17 +++++++++++++++++ .../dns_recordset_info/tasks/main.yaml | 17 +++++++++++++++++ .../targets/dns_zone_info/tasks/main.yaml | 19 +++++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old create mode 100644 tests/integration/targets/dns_nameserver_info/tasks/main.yaml create mode 100644 tests/integration/targets/dns_recordset_info/tasks/main.yaml create mode 100644 tests/integration/targets/dns_zone_info/tasks/main.yaml diff --git a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml index f32928c1..5da6e332 100644 --- a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml +++ b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml @@ -1,8 +1,7 @@ --- - block: - - name: Get DNAT rule info + - name: Get DNS Floating IP Info dns_floating_ip_info: - cloud: "{{ test_cloud }}" register: ptr - name: debug configs diff --git a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old new file mode 100644 index 00000000..7fc469fc --- /dev/null +++ b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old @@ -0,0 +1,3 @@ +- name: Testing + dns_floating_ip_info: + description: "test3" diff --git a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml new file mode 100644 index 00000000..8d581a67 --- /dev/null +++ b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml @@ -0,0 +1,17 @@ +--- +- block: + - name: Get DNS Nameserver Info + dns_nameserver_info: + zone: "{{ test_zone }}" + register: nms + + - name: debug configs + debug: + var: nms.dns_nameservers + + - name: assert result + assert: + that: + - nms is success + - nms is not changed + - nms.dns_nameservers is defined diff --git a/tests/integration/targets/dns_recordset_info/tasks/main.yaml b/tests/integration/targets/dns_recordset_info/tasks/main.yaml new file mode 100644 index 00000000..0bb4aa29 --- /dev/null +++ b/tests/integration/targets/dns_recordset_info/tasks/main.yaml @@ -0,0 +1,17 @@ +--- +- block: + - name: Get DNS Recordset Info + dns_recordset_info: + zone_id: "{{ test_zone }}" + 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 diff --git a/tests/integration/targets/dns_zone_info/tasks/main.yaml b/tests/integration/targets/dns_zone_info/tasks/main.yaml new file mode 100644 index 00000000..7839a907 --- /dev/null +++ b/tests/integration/targets/dns_zone_info/tasks/main.yaml @@ -0,0 +1,19 @@ +--- +- block: + - name: Get DNS Zone Info + dns_zone_info: + zone_type: private + name: "sgode." + register: zone + + - name: debug configs + debug: + var: zone.dns_zones + + - name: assert result + assert: + that: + - zone is success + - zone is not changed + - zone.dns_zones is defined + From b57ea75ce6bf98cf21792db8cc3c044690391b75 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 09:51:19 +0000 Subject: [PATCH 32/50] Added Integration Tests --- .../targets/dns_floating_ip_info/tasks/main.yaml.old | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old diff --git a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old deleted file mode 100644 index 7fc469fc..00000000 --- a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml.old +++ /dev/null @@ -1,3 +0,0 @@ -- name: Testing - dns_floating_ip_info: - description: "test3" From 6c0928720bc22d6acbf22f6facad524f865cd4e6 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 11:08:17 +0000 Subject: [PATCH 33/50] Added big Integration Test --- plugins/modules/dns_floating_ip.py | 2 +- plugins/modules/dns_recordset.py | 2 +- tests/integration/targets/dns/tasks/main.yaml | 154 ++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 tests/integration/targets/dns/tasks/main.yaml diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index 294ac7c6..55e107b9 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -48,7 +48,7 @@ ''' RETURN = ''' -ptr_records: +ptr: description: Modify DNS floating IPs type: complex returned: On Success. diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 3a7749e7..4ffb9a2b 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -125,7 +125,7 @@ class DNSRecordsetModule(OTCModule): argument_spec = dict( description=dict(required=False), - records=dict(required=True, type='list', elements='str'), + records=dict(required=False, type='list', elements='str'), recordset_name=dict(required=True), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml new file mode 100644 index 00000000..5385bd2e --- /dev/null +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -0,0 +1,154 @@ +--- +- name: Doing Integration test + block: + - name: Set random prefix + set_fact: + prefix: "{{ 99999999 | random | to_uuid | hash('md5') }}" + + - name: Set facts + set_fact: + fl_ip: 80.158.1.1 + ptrdname: "{{ ( prefix + '.com.' ) }}" + description: "{{ ( prefix + 'description' ) }}" + zone_name: "{{ ( prefix + '-zone.com.' ) }}" + rs_name: "{{ ( prefix + '-rs.' + prefix + '-zone.com.' ) }}" + + - name: Creating a dns_floating_ip entry + dns_floating_ip: + floating_ip: "{{ fl_ip }}" + ptrdname: "{{ ptrdname }}" + state: present + register: dns_fl + + - name: debug + debug: + var: dns_fl.ptr + + - name: assert result + assert: + that: + - dns_fl is success + - dns_fl.ptr is defined + + - name: Updating a dns_floating_ip entry + dns_floating_ip: + floating_ip: "{{ fl_ip }}" + ptrdname: "{{ ptrdname }}" + description: "{{ description }}" + state: present + register: dns_fl + + - name: debug + debug: + var: dns_fl.ptr + + - name: assert result + assert: + that: + - dns_fl is success + - dns_fl.ptr.description is defined + + + + + - name: Creating a DNS Zone + dns_zones: + name: "{{ zone_name }}" + state: present + register: dns_zo + + - name: debug + debug: + var: dns_zo.zone + + - name: assert result + assert: + that: + - dns_zo is success + - dns_zo.zone is defined + + - name: Updating a DNS Zone + dns_zones: + name: "{{ zone_name }}" + state: present + description: "{{ description }}" + register: dns_zo + + - name: debug + debug: + var: dns_zo.zone + + - name: assert result + assert: + that: + - dns_zo is success + - dns_zo.zone.description is defined + + + + + - name: Creating a DNS Recordset + dns_recordset: + zone_id: "{{ dns_zo.zone.id }}" + recordset_name: "{{ rs_name }}" + type: A + records: + - "1.1.1.1" + - "2.2.2.2" + state: present + register: dns_rs + + - name: debug + debug: + var: dns_rs.recordset + + - name: assert result + assert: + that: + - dns_rs is success + - dns_rs.recordset is defined + + - name: Updating a DNS Recordset + dns_recordset: + zone_id: "{{ dns_zo.zone.id }}" + recordset_name: "{{ rs_name }}" + type: A + description: "{{ description }}" + records: + - "1.1.1.1" + - "2.2.2.2" + state: present + register: dns_rs + + - name: debug + debug: + var: dns_rs.recordset + + - name: assert result + assert: + that: + - dns_rs is success + - dns_rs.recordset.description is defined + + + always: + - block: + - name: Drop dns_floating_ip entry + dns_floating_ip: + floating_ip: "{{ fl_ip }}" + state: absent + register: dns_fl_dr + + - name: Dropping DNS Recordset + dns_recordset: + zone_id: "{{ dns_zo.zone.id }}" + recordset_name: "{{ rs_name }}" + state: absent + register: dns_rs_dr + + - name: Drop DNS Zone + dns_zones: + name: "{{ zone_name }}" + state: absent + register: dns_zo_dr + From 6592a0c9da2d62fabd0904ff27eb68582d2be65e Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 11:14:33 +0000 Subject: [PATCH 34/50] Fixed yamllint --- tests/integration/targets/dns_zone_info/tasks/main.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/dns_zone_info/tasks/main.yaml b/tests/integration/targets/dns_zone_info/tasks/main.yaml index 7839a907..a9df3961 100644 --- a/tests/integration/targets/dns_zone_info/tasks/main.yaml +++ b/tests/integration/targets/dns_zone_info/tasks/main.yaml @@ -16,4 +16,3 @@ - zone is success - zone is not changed - zone.dns_zones is defined - From 9c6eb1bd8941697c935ae7ee84adf7bae4327dfd Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 12:37:04 +0000 Subject: [PATCH 35/50] Added integration test --- tests/integration/targets/dns/tasks/main.yaml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 5385bd2e..96704bde 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -5,14 +5,19 @@ set_fact: prefix: "{{ 99999999 | random | to_uuid | hash('md5') }}" + - name: Assigning Floating IP + floating_ip: + network: admin_external_net + register: fl + - name: Set facts set_fact: - fl_ip: 80.158.1.1 + fl_ip: "{{ fl.floating_ip.floating_ip_address }}" ptrdname: "{{ ( prefix + '.com.' ) }}" description: "{{ ( prefix + 'description' ) }}" zone_name: "{{ ( prefix + '-zone.com.' ) }}" rs_name: "{{ ( prefix + '-rs.' + prefix + '-zone.com.' ) }}" - + - name: Creating a dns_floating_ip entry dns_floating_ip: floating_ip: "{{ fl_ip }}" @@ -152,3 +157,9 @@ state: absent register: dns_zo_dr + - name: Drop Floating IP + floating_ip: + floating_ip_address: "{{ fl_ip }}" + state: absent + purge: True + register: fl_dr From b50a8664a7b066555fa0b6d23b1b55033402a699 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 13:02:03 +0000 Subject: [PATCH 36/50] Fixed Yamllint --- tests/integration/targets/dns/tasks/main.yaml | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 96704bde..15e16d6d 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -17,7 +17,7 @@ description: "{{ ( prefix + 'description' ) }}" zone_name: "{{ ( prefix + '-zone.com.' ) }}" rs_name: "{{ ( prefix + '-rs.' + prefix + '-zone.com.' ) }}" - + - name: Creating a dns_floating_ip entry dns_floating_ip: floating_ip: "{{ fl_ip }}" @@ -53,15 +53,12 @@ - dns_fl is success - dns_fl.ptr.description is defined - - - - name: Creating a DNS Zone dns_zones: name: "{{ zone_name }}" state: present register: dns_zo - + - name: debug debug: var: dns_zo.zone @@ -89,9 +86,6 @@ - dns_zo is success - dns_zo.zone.description is defined - - - - name: Creating a DNS Recordset dns_recordset: zone_id: "{{ dns_zo.zone.id }}" @@ -135,31 +129,30 @@ - dns_rs is success - dns_rs.recordset.description is defined - always: - block: - - name: Drop dns_floating_ip entry - dns_floating_ip: - floating_ip: "{{ fl_ip }}" - state: absent - register: dns_fl_dr - - - name: Dropping DNS Recordset - dns_recordset: - zone_id: "{{ dns_zo.zone.id }}" - recordset_name: "{{ rs_name }}" - state: absent - register: dns_rs_dr - - - name: Drop DNS Zone - dns_zones: - name: "{{ zone_name }}" - state: absent - register: dns_zo_dr - - - name: Drop Floating IP - floating_ip: - floating_ip_address: "{{ fl_ip }}" - state: absent - purge: True - register: fl_dr + - name: Drop dns_floating_ip entry + dns_floating_ip: + floating_ip: "{{ fl_ip }}" + state: absent + register: dns_fl_dr + + - name: Dropping DNS Recordset + dns_recordset: + zone_id: "{{ dns_zo.zone.id }}" + recordset_name: "{{ rs_name }}" + state: absent + register: dns_rs_dr + + - name: Drop DNS Zone + dns_zones: + name: "{{ zone_name }}" + state: absent + register: dns_zo_dr + + - name: Drop Floating IP + floating_ip: + floating_ip_address: "{{ fl_ip }}" + state: absent + purge: true + register: fl_dr From a330db730129ac5e174c9d3dd1214ae503a62027 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 13 Nov 2020 13:24:52 +0000 Subject: [PATCH 37/50] Fixed Sanity --- plugins/modules/dns_recordset.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 4ffb9a2b..29e6b8c6 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -29,7 +29,6 @@ - IP Records of the entry. Type is a list type: list elements: str - required: true recordset_name: description: - Can be name or ID of the recordset. When creating a new one please enter a name From 56ceeddb3d92627429c6e6bf50ee9323af177add Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 16 Nov 2020 09:33:24 +0000 Subject: [PATCH 38/50] Fixed blank lines, fixed fqdn --- plugins/modules/dns_floating_ip.py | 3 --- plugins/modules/dns_recordset.py | 2 -- plugins/modules/dns_zones.py | 3 --- tests/integration/targets/dns/tasks/main.yaml | 22 +++++++++---------- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/plugins/modules/dns_floating_ip.py b/plugins/modules/dns_floating_ip.py index 55e107b9..e2de7758 100644 --- a/plugins/modules/dns_floating_ip.py +++ b/plugins/modules/dns_floating_ip.py @@ -73,7 +73,6 @@ description: PTR record cache duration (in second) on a local DNS server type: int sample: 300 - ''' EXAMPLES = ''' @@ -85,8 +84,6 @@ description: "test2nownow" ttl: 300 state: present - - ''' from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule diff --git a/plugins/modules/dns_recordset.py b/plugins/modules/dns_recordset.py index 29e6b8c6..ba6e2e14 100644 --- a/plugins/modules/dns_recordset.py +++ b/plugins/modules/dns_recordset.py @@ -99,7 +99,6 @@ description: Zone Name type: str sample: "test." - ''' EXAMPLES = ''' @@ -115,7 +114,6 @@ - "1.3.1.2" - "121.111.111.111" - "145.145.145.145" - ''' from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index 787e6071..fcf4da24 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -99,7 +99,6 @@ description: Zone Type, either public or private type: str sample: "private" - ''' EXAMPLES = ''' @@ -113,8 +112,6 @@ description: test2 ttl: 5000 email: mail2@mail2.test - - ''' from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 15e16d6d..fe4aa860 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -6,7 +6,7 @@ prefix: "{{ 99999999 | random | to_uuid | hash('md5') }}" - name: Assigning Floating IP - floating_ip: + opentelekomcloud.cloud.floating_ip: network: admin_external_net register: fl @@ -19,7 +19,7 @@ rs_name: "{{ ( prefix + '-rs.' + prefix + '-zone.com.' ) }}" - name: Creating a dns_floating_ip entry - dns_floating_ip: + opentelekomcloud.cloud.dns_floating_ip: floating_ip: "{{ fl_ip }}" ptrdname: "{{ ptrdname }}" state: present @@ -36,7 +36,7 @@ - dns_fl.ptr is defined - name: Updating a dns_floating_ip entry - dns_floating_ip: + opentelekomcloud.cloud.dns_floating_ip: floating_ip: "{{ fl_ip }}" ptrdname: "{{ ptrdname }}" description: "{{ description }}" @@ -54,7 +54,7 @@ - dns_fl.ptr.description is defined - name: Creating a DNS Zone - dns_zones: + opentelekomcloud.cloud.dns_zones: name: "{{ zone_name }}" state: present register: dns_zo @@ -70,7 +70,7 @@ - dns_zo.zone is defined - name: Updating a DNS Zone - dns_zones: + opentelekomcloud.cloud.dns_zones: name: "{{ zone_name }}" state: present description: "{{ description }}" @@ -87,7 +87,7 @@ - dns_zo.zone.description is defined - name: Creating a DNS Recordset - dns_recordset: + opentelekomcloud.cloud.dns_recordset: zone_id: "{{ dns_zo.zone.id }}" recordset_name: "{{ rs_name }}" type: A @@ -108,7 +108,7 @@ - dns_rs.recordset is defined - name: Updating a DNS Recordset - dns_recordset: + opentelekomcloud.cloud.dns_recordset: zone_id: "{{ dns_zo.zone.id }}" recordset_name: "{{ rs_name }}" type: A @@ -132,26 +132,26 @@ always: - block: - name: Drop dns_floating_ip entry - dns_floating_ip: + opentelekomcloud.cloud.dns_floating_ip: floating_ip: "{{ fl_ip }}" state: absent register: dns_fl_dr - name: Dropping DNS Recordset - dns_recordset: + opentelekomcloud.cloud.dns_recordset: zone_id: "{{ dns_zo.zone.id }}" recordset_name: "{{ rs_name }}" state: absent register: dns_rs_dr - name: Drop DNS Zone - dns_zones: + opentelekomcloud.cloud.dns_zones: name: "{{ zone_name }}" state: absent register: dns_zo_dr - name: Drop Floating IP - floating_ip: + opentelekomcloud.cloud.floating_ip: floating_ip_address: "{{ fl_ip }}" state: absent purge: true From a84ecce2f177186d5062780a3c13a0efcdc03f47 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 16 Nov 2020 10:03:09 +0000 Subject: [PATCH 39/50] Changed zone_find according to new PR --- plugins/modules/dns_zones.py | 75 +++++++++++------------------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index fcf4da24..f478302c 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -133,59 +133,25 @@ def run(self): data = [] query = {} - # find_zone doesn't support searching for private zones with name - # As a result we use it only to search in public zones - if self.params['zone_type'] == 'public': - zo = self.conn.dns.find_zone( - name_or_id=self.params['name'], - ignore_missing=True - ) - if zo: - zone_id = zo.id - zone_desc = zo.description - zone_ttl = zo.ttl - zone_email = zo.email - zone_check = True - else: - zone_check = False - if self.params['state'] == 'absent': - self.exit( - changed=False, - message=('No Zone found with name: %s' % - self.params['name']) - ) - - # For private Zones we list all zones and then filter by name if self.params['zone_type'] == 'private': - query['zone_type'] = self.params['zone_type'] - for raw in self.conn.dns.zones(**query): - dt = raw.to_dict() - dt.pop('location') - data.append(dt) - # Query parameter name is not supported, so we need to filter it by hand - i = 0 - while i < len(data): - if data[i]['name'] != self.params['name']: - del data[i] - i = 0 - continue - i = i + 1 - # As we remove datasets we need to check wether there's the correct one left to obtain the ID - if len(data) != 0: - zone_id = data[0]['id'] - zone_desc = data[0]['description'] - zone_ttl = data[0]['ttl'] - zone_email = data[0]['email'] - zone_check = True - else: - zone_check = False - if self.params['state'] == 'absent': - self.exit( - changed=False, - message=('No Zone found with name: %s' % - self.params['name']) - ) - + query['type'] = self.params['zone_type'] + query['name_or_id'] = self.params['name'] + query['ignore_missing'] = True + zo = self.conn.dns.find_zone(**query) + if zo: + zone_id = zo.id + zone_desc = zo.description + zone_ttl = zo.ttl + zone_email = zo.email + zone_check = True + else: + zone_check = False + if self.params['state'] == 'absent': + self.exit( + changed=False, + message=('No Zone found with name: %s' % + self.params['name']) + ) # We now have the zone_id to work with if self.params['state'] == 'absent': changed = False @@ -201,6 +167,11 @@ def run(self): if zone_check is False: # Check if VPC exists if self.params['zone_type'] == 'private': + if not self.params['router']: + self.exit( + changed=False, + message=('No Router specified, but needed for creation') + ) ro = self.conn.network.find_router( name_or_id=self.params['router'], ignore_missing=True From d60e62453d78ddbce430889c8fd3b5745b026092 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 16 Nov 2020 10:26:11 +0000 Subject: [PATCH 40/50] Fixed Pep8 --- plugins/modules/dns_zones.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/dns_zones.py b/plugins/modules/dns_zones.py index f478302c..2b769691 100644 --- a/plugins/modules/dns_zones.py +++ b/plugins/modules/dns_zones.py @@ -130,7 +130,6 @@ class DNSZonesModule(OTCModule): def run(self): changed = False - data = [] query = {} if self.params['zone_type'] == 'private': From 236dae6c1967d1a1f0ae09267b8ea6a6e2d76d15 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 08:28:05 +0000 Subject: [PATCH 41/50] Added DNS Private Zone Test + ignore errors --- tests/integration/targets/dns/tasks/main.yaml | 114 ++++++++++++++++-- 1 file changed, 106 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index fe4aa860..768441fc 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -15,8 +15,38 @@ fl_ip: "{{ fl.floating_ip.floating_ip_address }}" ptrdname: "{{ ( prefix + '.com.' ) }}" description: "{{ ( prefix + 'description' ) }}" - zone_name: "{{ ( prefix + '-zone.com.' ) }}" + zone_public_name: "{{ ( prefix + '-zone.com.' ) }}" + zone_private_name: "{{ ( prefix + '-zone.com.' ) }}" rs_name: "{{ ( prefix + '-rs.' + prefix + '-zone.com.' ) }}" + network_name: "{{ ( prefix + '-network' )}}" + subnet_name: "{{ ( prefix + '-subnet' )}}" + router_name: "{{ ( prefix + '-router' )}}" + + - name: Create network for DNS private Zone + openstack.cloud.network: + name: "{{ network_name }}" + state: present + register: zone_net + + - name: Create subnet for DNS private Zone + openstack.cloud.subnet: + name: "{{ subnet_name }}" + state: present + network_name: "{{ zone_net.network.name }}" + cidr: "192.168.110.0/24" + dns_nameservers: "{{ ['100.125.4.25', '8.8.8.8'] }}" + register: zone_subnet + + - name: Create Router for DNS private Zone + openstack.cloud.router: + name: "{{ router_name }}" + state: present + network: admin_external_net + enable_snat: False + interfaces: + - net: "{{ zone_net.network.name }}" + subnet: "{{ zone_subnet.subnet.name }}" + register: zone_router - name: Creating a dns_floating_ip entry opentelekomcloud.cloud.dns_floating_ip: @@ -53,9 +83,9 @@ - dns_fl is success - dns_fl.ptr.description is defined - - name: Creating a DNS Zone + - name: Creating a public DNS Zone opentelekomcloud.cloud.dns_zones: - name: "{{ zone_name }}" + name: "{{ zone_public_name }}" state: present register: dns_zo @@ -69,9 +99,9 @@ - dns_zo is success - dns_zo.zone is defined - - name: Updating a DNS Zone + - name: Updating a public DNS Zone opentelekomcloud.cloud.dns_zones: - name: "{{ zone_name }}" + name: "{{ zone_public_name }}" state: present description: "{{ description }}" register: dns_zo @@ -85,6 +115,41 @@ that: - dns_zo is success - dns_zo.zone.description is defined + + - name: Creating a DNS private Zone + opentelekomcloud.cloud.dns_zones: + name: "{{ zone_private_name }}" + router: "{{ router_name }}" + zone_type: "private" + state: present + register: dns_zo_pr + + - name: debug + debug: + var: dns_zo_pr.zone + + - name: assert result + assert: + that: + - dns_zo_pr is success + - dns_zo_pr.zone is defined + + - name: Updating a private DNS Zone + opentelekomcloud.cloud.dns_zones: + name: "{{ zone_private_name }}" + state: present + description: "{{ description }}" + register: dns_zo_pr + + - name: debug + debug: + var: dns_zo_pr.zone + + - name: assert result + assert: + that: + - dns_zo_pr is success + - dns_zo_pr.zone.description is defined - name: Creating a DNS Recordset opentelekomcloud.cloud.dns_recordset: @@ -136,6 +201,7 @@ floating_ip: "{{ fl_ip }}" state: absent register: dns_fl_dr + ignore_errors: yes - name: Dropping DNS Recordset opentelekomcloud.cloud.dns_recordset: @@ -143,12 +209,22 @@ recordset_name: "{{ rs_name }}" state: absent register: dns_rs_dr + ignore_errors: yes - - name: Drop DNS Zone + - name: Drop DNS public Zone opentelekomcloud.cloud.dns_zones: - name: "{{ zone_name }}" + name: "{{ zone_public_name }}" state: absent - register: dns_zo_dr + register: dns_zo_pu_dr + ignore_errors: yes + + - name: Drop DNS private Zone + opentelekomcloud.cloud.dns_zones: + name: "{{ zone_private_name }}" + zone_type: "private" + state: absent + register: dns_zo_pr_dr + ignore_errors: yes - name: Drop Floating IP opentelekomcloud.cloud.floating_ip: @@ -156,3 +232,25 @@ state: absent purge: true register: fl_dr + ignore_errors: yes + + - name: Drop existing Router + openstack.cloud.router: + name: "{{ router_name }}" + state: absent + register: dns_rout_dr + ignore_errors: yes + + - name: Drop existing subnet + openstack.cloud.subnet: + name: "{{ subnet_name }}" + state: absent + register: dns_subnet_dr + ignore_errors: yes + + - name: Drop existing network + openstack.cloud.network: + name: "{{ network_name }}" + state: absent + register: dns_net_dr + ignore_errors: yes \ No newline at end of file From 1a23f746dda43aaff9a90a00e56e050cc840f11c Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 08:30:35 +0000 Subject: [PATCH 42/50] Fixed yamllint --- tests/integration/targets/dns/tasks/main.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 768441fc..5cac57c5 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -27,7 +27,7 @@ name: "{{ network_name }}" state: present register: zone_net - + - name: Create subnet for DNS private Zone openstack.cloud.subnet: name: "{{ subnet_name }}" @@ -115,7 +115,7 @@ that: - dns_zo is success - dns_zo.zone.description is defined - + - name: Creating a DNS private Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_private_name }}" @@ -217,7 +217,7 @@ state: absent register: dns_zo_pu_dr ignore_errors: yes - + - name: Drop DNS private Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_private_name }}" @@ -253,4 +253,4 @@ name: "{{ network_name }}" state: absent register: dns_net_dr - ignore_errors: yes \ No newline at end of file + ignore_errors: yes From 75411529699dcfc996c6a87fb7de75740559c070 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 08:31:44 +0000 Subject: [PATCH 43/50] Fixed yamllint -2 --- tests/integration/targets/dns/tasks/main.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 5cac57c5..6bb9d7b2 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -42,7 +42,7 @@ name: "{{ router_name }}" state: present network: admin_external_net - enable_snat: False + enable_snat: false interfaces: - net: "{{ zone_net.network.name }}" subnet: "{{ zone_subnet.subnet.name }}" @@ -201,7 +201,7 @@ floating_ip: "{{ fl_ip }}" state: absent register: dns_fl_dr - ignore_errors: yes + ignore_errors: true - name: Dropping DNS Recordset opentelekomcloud.cloud.dns_recordset: @@ -209,14 +209,14 @@ recordset_name: "{{ rs_name }}" state: absent register: dns_rs_dr - ignore_errors: yes + ignore_errors: true - name: Drop DNS public Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_public_name }}" state: absent register: dns_zo_pu_dr - ignore_errors: yes + ignore_errors: true - name: Drop DNS private Zone opentelekomcloud.cloud.dns_zones: @@ -224,7 +224,7 @@ zone_type: "private" state: absent register: dns_zo_pr_dr - ignore_errors: yes + ignore_errors: true - name: Drop Floating IP opentelekomcloud.cloud.floating_ip: @@ -232,25 +232,25 @@ state: absent purge: true register: fl_dr - ignore_errors: yes + ignore_errors: true - name: Drop existing Router openstack.cloud.router: name: "{{ router_name }}" state: absent register: dns_rout_dr - ignore_errors: yes + ignore_errors: true - name: Drop existing subnet openstack.cloud.subnet: name: "{{ subnet_name }}" state: absent register: dns_subnet_dr - ignore_errors: yes + ignore_errors: true - name: Drop existing network openstack.cloud.network: name: "{{ network_name }}" state: absent register: dns_net_dr - ignore_errors: yes + ignore_errors: true From c0c5cf3f53b0c8a8168bbaf5745550be95e8986b Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 08:50:42 +0000 Subject: [PATCH 44/50] Fixed ignore_errors --- tests/integration/targets/dns/tasks/main.yaml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 6bb9d7b2..9dc840d3 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -196,12 +196,11 @@ always: - block: - - name: Drop dns_floating_ip entry + git add- name: Drop dns_floating_ip entry opentelekomcloud.cloud.dns_floating_ip: floating_ip: "{{ fl_ip }}" state: absent register: dns_fl_dr - ignore_errors: true - name: Dropping DNS Recordset opentelekomcloud.cloud.dns_recordset: @@ -209,14 +208,12 @@ recordset_name: "{{ rs_name }}" state: absent register: dns_rs_dr - ignore_errors: true - name: Drop DNS public Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_public_name }}" state: absent register: dns_zo_pu_dr - ignore_errors: true - name: Drop DNS private Zone opentelekomcloud.cloud.dns_zones: @@ -224,7 +221,6 @@ zone_type: "private" state: absent register: dns_zo_pr_dr - ignore_errors: true - name: Drop Floating IP opentelekomcloud.cloud.floating_ip: @@ -232,25 +228,22 @@ state: absent purge: true register: fl_dr - ignore_errors: true - name: Drop existing Router openstack.cloud.router: name: "{{ router_name }}" state: absent register: dns_rout_dr - ignore_errors: true - name: Drop existing subnet openstack.cloud.subnet: name: "{{ subnet_name }}" state: absent register: dns_subnet_dr - ignore_errors: true - name: Drop existing network openstack.cloud.network: name: "{{ network_name }}" state: absent register: dns_net_dr - ignore_errors: true + ignore_errors: true From 95935e32299653ff899f93abd0e3c82ca8506ec5 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 08:55:57 +0000 Subject: [PATCH 45/50] Fixed git --- tests/integration/targets/dns/tasks/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 9dc840d3..a9b427db 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -196,7 +196,7 @@ always: - block: - git add- name: Drop dns_floating_ip entry + - name: Drop dns_floating_ip entry opentelekomcloud.cloud.dns_floating_ip: floating_ip: "{{ fl_ip }}" state: absent From e1e939d1c1c08ea7912efa610aab5567b582cb32 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 17 Nov 2020 09:11:17 +0000 Subject: [PATCH 46/50] minor fix --- tests/integration/targets/dns/tasks/main.yaml | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index a9b427db..a9a16a5c 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -196,54 +196,54 @@ always: - block: - - name: Drop dns_floating_ip entry - opentelekomcloud.cloud.dns_floating_ip: - floating_ip: "{{ fl_ip }}" - state: absent - register: dns_fl_dr - - - name: Dropping DNS Recordset - opentelekomcloud.cloud.dns_recordset: - zone_id: "{{ dns_zo.zone.id }}" - recordset_name: "{{ rs_name }}" - state: absent - register: dns_rs_dr - - - name: Drop DNS public Zone - opentelekomcloud.cloud.dns_zones: - name: "{{ zone_public_name }}" - state: absent - register: dns_zo_pu_dr - - - name: Drop DNS private Zone - opentelekomcloud.cloud.dns_zones: - name: "{{ zone_private_name }}" - zone_type: "private" - state: absent - register: dns_zo_pr_dr - - - name: Drop Floating IP - opentelekomcloud.cloud.floating_ip: - floating_ip_address: "{{ fl_ip }}" - state: absent - purge: true - register: fl_dr - - - name: Drop existing Router - openstack.cloud.router: - name: "{{ router_name }}" - state: absent - register: dns_rout_dr - - - name: Drop existing subnet - openstack.cloud.subnet: - name: "{{ subnet_name }}" - state: absent - register: dns_subnet_dr - - - name: Drop existing network - openstack.cloud.network: - name: "{{ network_name }}" - state: absent - register: dns_net_dr - ignore_errors: true + - name: Drop dns_floating_ip entry + opentelekomcloud.cloud.dns_floating_ip: + floating_ip: "{{ fl_ip }}" + state: absent + register: dns_fl_dr + + - name: Dropping DNS Recordset + opentelekomcloud.cloud.dns_recordset: + zone_id: "{{ dns_zo.zone.id }}" + recordset_name: "{{ rs_name }}" + state: absent + register: dns_rs_dr + + - name: Drop DNS public Zone + opentelekomcloud.cloud.dns_zones: + name: "{{ zone_public_name }}" + state: absent + register: dns_zo_pu_dr + + - name: Drop DNS private Zone + opentelekomcloud.cloud.dns_zones: + name: "{{ zone_private_name }}" + zone_type: "private" + state: absent + register: dns_zo_pr_dr + + - name: Drop Floating IP + opentelekomcloud.cloud.floating_ip: + floating_ip_address: "{{ fl_ip }}" + state: absent + purge: true + register: fl_dr + + - name: Drop existing Router + openstack.cloud.router: + name: "{{ router_name }}" + state: absent + register: dns_rout_dr + + - name: Drop existing subnet + openstack.cloud.subnet: + name: "{{ subnet_name }}" + state: absent + register: dns_subnet_dr + + - name: Drop existing network + openstack.cloud.network: + name: "{{ network_name }}" + state: absent + register: dns_net_dr + ignore_errors: yes From e5e8a1db21a724afc67998e2daa6b53db9cb778c Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 17 Nov 2020 09:37:35 +0000 Subject: [PATCH 47/50] Added big integration test --- tests/integration/targets/dns/tasks/main.yaml | 64 +++++++++++++++++++ .../dns_floating_ip_info/tasks/main.yaml | 16 ----- .../dns_nameserver_info/tasks/main.yaml | 17 ----- .../dns_recordset_info/tasks/main.yaml | 17 ----- .../targets/dns_zone_info/tasks/main.yaml | 18 ------ 5 files changed, 64 insertions(+), 68 deletions(-) delete mode 100644 tests/integration/targets/dns_floating_ip_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_nameserver_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_recordset_info/tasks/main.yaml delete mode 100644 tests/integration/targets/dns_zone_info/tasks/main.yaml diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index a9a16a5c..98199728 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -83,6 +83,21 @@ - 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: assert result + assert: + that: + - ptr is success + - ptr is not changed + - ptr.ptr_records is defined + - name: Creating a public DNS Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_public_name }}" @@ -116,6 +131,39 @@ - dns_zo is success - dns_zo.zone.description is defined + - name: Get DNS Nameserver Info + dns_nameserver_info: + zone: "{{ zone_public_name }}" + register: nms + + - name: debug configs + debug: + var: nms.dns_nameservers + + - name: assert result + assert: + that: + - nms is success + - nms is not changed + - nms.dns_nameservers is defined + + - name: Get DNS Zone Info + dns_zone_info: + zone_type: private + name: "{{ zone_public_name }}" + register: zone + + - name: debug configs + debug: + var: zone.dns_zones + + - name: assert result + assert: + that: + - zone is success + - zone is not changed + - zone.dns_zones is defined + - name: Creating a DNS private Zone opentelekomcloud.cloud.dns_zones: name: "{{ zone_private_name }}" @@ -184,6 +232,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/integration/targets/dns_floating_ip_info/tasks/main.yaml b/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml deleted file mode 100644 index 5da6e332..00000000 --- a/tests/integration/targets/dns_floating_ip_info/tasks/main.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- block: - - name: Get DNS Floating IP Info - dns_floating_ip_info: - register: ptr - - - name: debug configs - debug: - var: ptr.ptr_records - - - name: assert result - assert: - that: - - ptr is success - - ptr is not changed - - ptr.ptr_records is defined diff --git a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml b/tests/integration/targets/dns_nameserver_info/tasks/main.yaml deleted file mode 100644 index 8d581a67..00000000 --- a/tests/integration/targets/dns_nameserver_info/tasks/main.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- block: - - name: Get DNS Nameserver Info - dns_nameserver_info: - zone: "{{ test_zone }}" - register: nms - - - name: debug configs - debug: - var: nms.dns_nameservers - - - name: assert result - assert: - that: - - nms is success - - nms is not changed - - nms.dns_nameservers is defined diff --git a/tests/integration/targets/dns_recordset_info/tasks/main.yaml b/tests/integration/targets/dns_recordset_info/tasks/main.yaml deleted file mode 100644 index 0bb4aa29..00000000 --- a/tests/integration/targets/dns_recordset_info/tasks/main.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- block: - - name: Get DNS Recordset Info - dns_recordset_info: - zone_id: "{{ test_zone }}" - 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 diff --git a/tests/integration/targets/dns_zone_info/tasks/main.yaml b/tests/integration/targets/dns_zone_info/tasks/main.yaml deleted file mode 100644 index a9df3961..00000000 --- a/tests/integration/targets/dns_zone_info/tasks/main.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- block: - - name: Get DNS Zone Info - dns_zone_info: - zone_type: private - name: "sgode." - register: zone - - - name: debug configs - debug: - var: zone.dns_zones - - - name: assert result - assert: - that: - - zone is success - - zone is not changed - - zone.dns_zones is defined From 2dcf58851a3565c7f0e6debab2ea0d7b1980a16e Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 11 Jun 2021 07:41:52 +0000 Subject: [PATCH 48/50] New Integration Tests for info modules --- plugins/modules/dns_zone_info.py | 18 ++--------- tests/integration/targets/dns/tasks/main.yaml | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index 3b83d617..6184b57a 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -40,10 +40,6 @@ description: - Project ID of the zone type: str - record_num: - description: - - Number of record sets in the zone - type: int serial: description: - Serial number in the SOA record set in a zone @@ -95,10 +91,6 @@ description: Project ID of the zone type: str sample: "19f43a84a13b49529d2e2c3646693458" - record_num: - description: Number of record sets in the zone - type: int - sample: 3 serial: description: Serial number in the SOA record set in a zone type: int @@ -131,11 +123,11 @@ ''' EXAMPLES = ''' -# Get list of private zones with 3 records +# Get list of private zones and filter by name - name: Listing opentelekomcloud.cloud.dns_zone_info: - record_num: "3" zone_type: "private" + name: "test_zone" ''' @@ -149,7 +141,6 @@ class DNSZoneInfoModule(OTCModule): name=dict(required=False), pool_id=dict(required=False), project_id=dict(required=False), - record_num=dict(required=False, type='int'), serial=dict(required=False, type='int'), status=dict(required=False), ttl=dict(required=False, type='int'), @@ -178,11 +169,6 @@ def run(self): del data[i] i = 0 continue - if self.params['record_num']: - if data[i]['record_num'] != self.params['record_num']: - del data[i] - i = 0 - continue if self.params['zone_id']: if data[i]['zone_id'] != self.params['zone_id']: del data[i] diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 018b5174..573a0c1a 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -184,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: @@ -248,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: + zone_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: From d59b99a18aaeaae2495e3f2301daceb3baeb362a Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 11 Jun 2021 07:58:07 +0000 Subject: [PATCH 49/50] Make dns_zone_info Upstream compliant --- plugins/modules/dns_zone_info.py | 8 ++++---- tests/integration/targets/dns/tasks/main.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index 6184b57a..9164ad39 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -103,7 +103,7 @@ description: TTL value of the SOA record set in the zone type: int sample: 300 - zone_type: + type: description: DNS Zone type type: str sample: "private" @@ -144,7 +144,7 @@ class DNSZoneInfoModule(OTCModule): serial=dict(required=False, type='int'), status=dict(required=False), ttl=dict(required=False, type='int'), - zone_type=dict(required=True), + type=dict(required=True), zone_id=dict(required=False) ) @@ -153,8 +153,8 @@ def run(self): data = [] query = {} - if self.params['zone_type']: - query['zone_type'] = self.params['zone_type'] + if self.params['type']: + query['zone_type'] = self.params['type'] for raw in self.conn.dns.zones(**query): dt = raw.to_dict() diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 573a0c1a..dad9da61 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -266,7 +266,7 @@ - name: Getting Zone Info on Private Zone opentelekomcloud.cloud.dns_zone_info: - zone_type: "private" + type: "private" name: "{{ zone_private_name }}" register: dns_zo_zo_info From 905ff41eca0ea0067f3b9a6764925c2ecfd10a8a Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Fri, 11 Jun 2021 08:12:11 +0000 Subject: [PATCH 50/50] Fixed Sanity + Added Checkmode --- plugins/modules/dns_floating_ip_info.py | 3 +++ plugins/modules/dns_nameserver_info.py | 3 +++ plugins/modules/dns_recordset_info.py | 3 +++ plugins/modules/dns_zone_info.py | 5 ++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/modules/dns_floating_ip_info.py b/plugins/modules/dns_floating_ip_info.py index 740f2da9..98a1f793 100644 --- a/plugins/modules/dns_floating_ip_info.py +++ b/plugins/modules/dns_floating_ip_info.py @@ -102,6 +102,9 @@ class DNSFloatingIpInfoModule(OTCModule): status=dict(required=False), ttl=dict(required=False, type='int') ) + module_kwargs = dict( + supports_check_mode=True + ) def run(self): diff --git a/plugins/modules/dns_nameserver_info.py b/plugins/modules/dns_nameserver_info.py index 4ae07fec..6df593bb 100644 --- a/plugins/modules/dns_nameserver_info.py +++ b/plugins/modules/dns_nameserver_info.py @@ -85,6 +85,9 @@ class DNSNameserverInfoModule(OTCModule): priority=dict(required=False), zone=dict(required=True) ) + module_kwargs = dict( + supports_check_mode=True + ) def run(self): diff --git a/plugins/modules/dns_recordset_info.py b/plugins/modules/dns_recordset_info.py index 3badd4a3..e1f43991 100644 --- a/plugins/modules/dns_recordset_info.py +++ b/plugins/modules/dns_recordset_info.py @@ -139,6 +139,9 @@ class DNSRecordsetsInfoModule(OTCModule): default=dict(required=False, type='bool'), project_id=dict(required=False) ) + module_kwargs = dict( + supports_check_mode=True + ) def run(self): diff --git a/plugins/modules/dns_zone_info.py b/plugins/modules/dns_zone_info.py index 9164ad39..4546b797 100644 --- a/plugins/modules/dns_zone_info.py +++ b/plugins/modules/dns_zone_info.py @@ -52,7 +52,7 @@ description: - TTL value of the SOA record set in the zone type: int - zone_type: + type: description: - DNS Zone type type: str @@ -147,6 +147,9 @@ class DNSZoneInfoModule(OTCModule): type=dict(required=True), zone_id=dict(required=False) ) + module_kwargs = dict( + supports_check_mode=True + ) def run(self):