Skip to content

Commit e556717

Browse files
Nameserver info module (#192)
Nameserver info module Reviewed-by: Vladimir Vshivkov <None> Reviewed-by: Anton Kachurin <[email protected]> Reviewed-by: Irina Pereiaslavskaia <[email protected]> Reviewed-by: Rodion Gyrbu <[email protected]>
1 parent ca7289e commit e556717

File tree

8 files changed

+130
-3
lines changed

8 files changed

+130
-3
lines changed

doc/source/dns.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ Domain Name Service (DNS) Modules
66

77
dns_floating_ip <dns_floating_ip_module>
88
dns_recordset <dns_recordset_module>
9+
dns_recordset_info <dns_recordset_info_module>
910
dns_zone <dns_zone_module>
10-
11+
dns_nameserver_info <dns_nameserver_info_module>

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Opentelekomcloud.Cloud
22
======================
33

4-
Collection version 0.12.3
4+
Collection version 0.12.4
55

66

77

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: opentelekomcloud
22
name: cloud
3-
version: 0.12.3
3+
version: 0.12.4
44
readme: README.md
55
authors:
66
- Artem Goncharov <[email protected]>

meta/runtime.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ action_groups:
7979
- anti_ddos_fip_statuses_info.py
8080
- anti_ddos_optional_policies_info.py
8181
- object_info.py
82+
- dns_nameserver_info.py
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/python
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
DOCUMENTATION = '''
15+
module: dns_nameserver_info
16+
short_description: Get info about DNS nameservers.
17+
extends_documentation_fragment: opentelekomcloud.cloud.otc
18+
version_added: "0.12.2"
19+
author: "Anton Sidelnikov (@anton-sidelnikov)"
20+
description:
21+
- Get DNS nameservers info from the OTC.
22+
options:
23+
zone:
24+
description:
25+
- ID or name of the required zone. If name had been provided, only public zone could be\
26+
returned. If private zone is required, only ID should be passed.
27+
type: str
28+
required: true
29+
requirements: ["openstacksdk", "otcextensions"]
30+
'''
31+
32+
RETURN = '''
33+
nameservers:
34+
description: List of dictionaries describing nameservers.
35+
type: complex
36+
returned: On Success.
37+
contains:
38+
hostname:
39+
description: Host name of a name server.
40+
type: str
41+
sample: "ns1.example.com."
42+
address:
43+
description: IP address of a DNS server (Private Zone only).
44+
type: str
45+
sample: "100.125.0.81"
46+
priority:
47+
description: Priority of a name server.
48+
type: int
49+
'''
50+
51+
EXAMPLES = '''
52+
#Get info about choosen DNS recordset.
53+
- opentelekomcloud.cloud.dns_nameserver_info:
54+
zone: "ff80808275f5fc0f017e886898315ee9"
55+
register: nameservers
56+
'''
57+
58+
from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule
59+
60+
61+
class DNSNameserverInfoModule(OTCModule):
62+
63+
argument_spec = dict(
64+
zone=dict(required=True),
65+
)
66+
module_kwargs = dict(
67+
supports_check_mode=True,
68+
)
69+
70+
def run(self):
71+
72+
data = []
73+
query = {}
74+
75+
if self.params['zone']:
76+
try:
77+
query['zone'] = self.conn.dns.find_zone(
78+
name_or_id=self.params['zone'], ignore_missing=False).id
79+
except self.sdk.exceptions.ResourceNotFound:
80+
self.fail_json(msg="Zone not found")
81+
82+
for raw in self.conn.dns.nameservers(**query):
83+
dt = raw.to_dict()
84+
dt.pop('location')
85+
dt.pop('name')
86+
dt.pop('id')
87+
data.append(dt)
88+
89+
self.exit(
90+
changed=False,
91+
nameservers=data
92+
)
93+
94+
95+
def main():
96+
module = DNSNameserverInfoModule()
97+
module()
98+
99+
100+
if __name__ == '__main__':
101+
main()

tests/integration/targets/dns/tasks/main.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@
236236
- dns_zo_pr is success
237237
- dns_zo_pr.zone.description is defined
238238

239+
- name: Get a DNS Nameservers info for public zone
240+
opentelekomcloud.cloud.dns_nameserver_info:
241+
zone: "{{ zone_public_name }}"
242+
register: dns_ns
243+
244+
- name: assert result
245+
assert:
246+
that:
247+
- dns_ns is success
248+
- dns_ns.nameservers[0].hostname is defined
249+
250+
- name: Get a DNS Nameservers info for private zone
251+
opentelekomcloud.cloud.dns_nameserver_info:
252+
zone: "{{ zone_private_name }}"
253+
register: dns_ns
254+
255+
- name: assert result
256+
assert:
257+
that:
258+
- dns_ns is success
259+
- dns_ns.nameservers[0].address is defined
260+
239261
- name: Creating a DNS Recordset - check mode
240262
opentelekomcloud.cloud.dns_recordset:
241263
zone_id: "{{ dns_zo.zone.id }}"

tests/sanity/ignore-2.10.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ plugins/modules/anti_ddos_fip_statuses_info.py validate-modules:missing-gplv3-li
9494
plugins/modules/anti_ddos_optional_policies_info.py validate-modules:missing-gplv3-license
9595
plugins/modules/server_group_info.py validate-modules:missing-gplv3-license
9696
plugins/modules/object_info.py validate-modules:missing-gplv3-license
97+
plugins/modules/dns_nameserver_info.py validate-modules:missing-gplv3-license

tests/sanity/ignore-2.9.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ plugins/modules/anti_ddos_fip_statuses_info.py validate-modules:missing-gplv3-li
9595
plugins/modules/anti_ddos_optional_policies_info.py validate-modules:missing-gplv3-license
9696
plugins/modules/server_group_info.py validate-modules:missing-gplv3-license
9797
plugins/modules/object_info.py validate-modules:missing-gplv3-license
98+
plugins/modules/dns_nameserver_info.py validate-modules:missing-gplv3-license

0 commit comments

Comments
 (0)