summaryrefslogtreecommitdiffstats
path: root/ansible_collections/inspur/ispim/plugins/modules/edit_dns.py
blob: c8b481e7844eed6be5665c133dd16654b0612eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/python
# -*- coding:utf-8 -*-

# Copyright (C) 2020 Inspur Inc. All Rights Reserved.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

DOCUMENTATION = '''
---
module: edit_dns
version_added: "1.0.0"
author:
    - WangBaoshan (@ispim)
short_description: Set dns information
description:
   - Set dns information on Inspur server.
notes:
   - Does not support C(check_mode).
options:
    dns_status:
        description:
            - DNS status.
        choices: ['enable', 'disable']
        type: str
    host_cfg:
        description:
            - Host Settings.
        choices: ['manual', 'auto']
        type: str
    host_name:
        description:
            - Host Name.
            - Required when I(host_cfg=manual).
        type: str
    domain_manual:
        description:
            - Domain Settings.
        choices: ['manual', 'auto']
        type: str
    domain_iface:
        description:
            - Network Interface,input like 'eth0_v4', 'eth0_v6', 'eth1_v4', 'eth1_v6', 'bond0_v4', 'bond0_v6'.
            - Required when I(domain_manual=auto).
        type: str
    domain_name:
        description:
            - Domain Name.
            - Required when I(domain_manual=manual).
        type: str
    dns_manual:
        description:
            - DNS Settings.
        choices: ['manual', 'auto']
        type: str
    dns_iface:
        description:
            - DNS Interface,input like 'eth0', 'eth1', 'bond0'.
            - Required when I(dns_manual=auto).
        type: str
    dns_priority:
        description:
            - IP Priority.
            - Required when I(dns_manual=auto).
        choices: ['4', '6']
        type: str
    dns_server1:
        description:
            - DNS Server1 IPv4 or IPv6 address.
            - Required when I(dns_manual=manual).
        type: str
    dns_server2:
        description:
            - DNS Server2 IPv4 or IPv6 address.
            - Required when I(dns_manual=manual).
        type: str
    dns_server3:
        description:
            - DNS Server3 IPv4 or IPv6 address.
            - Required when I(dns_manual=manual).
        type: str
    register_status1:
        description:
            - BMC register status 1.
            - Only the M6 model supports this parameter.
        choices: ['enable', 'disable']
        type: str
    registration_method1:
        description:
            - Registration method 1.
            - Only the M6 model supports this parameter.
            - Required when I(register_status1=enable).
        choices: ['nsupdate', 'dhcp', 'hostname']
        type: str
    register_status2:
        description:
            - BMC register status 2.
            - Only the M6 model supports this parameter.
        choices: ['enable', 'disable']
        type: str
    registration_method2:
        description:
            - Registration method 2.
            - Only the M6 model supports this parameter.
            - Required when I(register_status2=enable).
        choices: ['nsupdate', 'dhcp', 'hostname']
        type: str
extends_documentation_fragment:
    - inspur.ispim.ism
'''

EXAMPLES = '''
- name: DNS test
  hosts: ism
  connection: local
  gather_facts: no
  vars:
    ism:
      host: "{{ ansible_ssh_host }}"
      username: "{{ username }}"
      password: "{{ password }}"

  tasks:

  - name: "Set dns information"
    inspur.ispim.edit_dns:
      dns_status: "disable"
      provider: "{{ ism }}"

  - name: "Set dns information"
    inspur.ispim.edit_dns:
      dns_status: "enable"
      host_cfg: "manual"
      host_name: "123456789"
      domain_manual: "auto"
      domain_iface: "eth0_v4"
      dns_manual: "manual"
      dns_server1: "100.2.2.2"
      dns_server2: "100.2.2.3"
      dns_server3: "100.2.2.4"
      provider: "{{ ism }}"

  - name: "Set dns information"
    inspur.ispim.edit_dns:
      dns_status: "enable"
      host_cfg: "manual"
      host_name: "123456789"
      domain_manual: "manual"
      domain_name: "inspur.com"
      dns_manual: "auto"
      dns_iface: "eth0"
      dns_priority: "4"
      provider: "{{ ism }}"
'''

RETURN = '''
message:
    description: Messages returned after module execution.
    returned: always
    type: str
state:
    description: Status after module execution.
    returned: always
    type: str
changed:
    description: Check to see if a change was made on the device.
    returned: always
    type: bool
'''

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.inspur.ispim.plugins.module_utils.ism import (ism_argument_spec, get_connection)


class DNS(object):
    def __init__(self, argument_spec):
        self.spec = argument_spec
        self.module = None
        self.init_module()
        self.results = dict()

    def init_module(self):
        """Init module object"""

        self.module = AnsibleModule(
            argument_spec=self.spec, supports_check_mode=False)

    def run_command(self):
        self.module.params['subcommand'] = 'setdns'
        self.results = get_connection(self.module)
        if self.results['State'] == 'Success':
            self.results['changed'] = True

    def show_result(self):
        """Show result"""
        self.module.exit_json(**self.results)

    def work(self):
        """Worker"""
        self.run_command()
        self.show_result()


def main():
    argument_spec = dict(
        dns_status=dict(type='str', required=False, choices=['enable', 'disable']),
        host_cfg=dict(type='str', required=False, choices=['manual', 'auto']),
        host_name=dict(type='str', required=False),
        domain_manual=dict(type='str', required=False, choices=['manual', 'auto']),
        domain_iface=dict(type='str', required=False),
        domain_name=dict(type='str', required=False),
        dns_manual=dict(type='str', required=False, choices=['manual', 'auto']),
        dns_iface=dict(type='str', required=False),
        dns_priority=dict(type='str', required=False, choices=['4', '6']),
        dns_server1=dict(type='str', required=False),
        dns_server2=dict(type='str', required=False),
        dns_server3=dict(type='str', required=False),
        register_status1=dict(type='str', required=False, choices=['enable', 'disable']),
        registration_method1=dict(type='str', required=False, choices=['nsupdate', 'dhcp', 'hostname']),
        register_status2=dict(type='str', required=False, choices=['enable', 'disable']),
        registration_method2=dict(type='str', required=False, choices=['nsupdate', 'dhcp', 'hostname']),
    )
    argument_spec.update(ism_argument_spec)
    dns_obj = DNS(argument_spec)
    dns_obj.work()


if __name__ == '__main__':
    main()