|
| 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() |
0 commit comments