| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'status': ['preview'], |
| 9 |
'supported_by': 'community', |
| 10 |
'metadata_version': '1.1'} |
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: fmgr_switchcontroller_managedswitch_systemdhcpserver |
| 15 |
short_description: Configure DHCP servers. |
| 16 |
version_added: "2.12.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.full_crud |
| 20 |
options: |
| 21 |
revision_note: |
| 22 |
description: The change note that can be specified when an object is created or updated. |
| 23 |
type: str |
| 24 |
adom: |
| 25 |
description: The parameter (adom) in requested url. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
managed-switch: |
| 29 |
description: Deprecated, please use "managed_switch" |
| 30 |
type: str |
| 31 |
managed_switch: |
| 32 |
description: The parameter (managed-switch) in requested url. |
| 33 |
type: str |
| 34 |
switchcontroller_managedswitch_systemdhcpserver: |
| 35 |
description: The top level parameters set. |
| 36 |
required: false |
| 37 |
type: dict |
| 38 |
suboptions: |
| 39 |
default_gateway: |
| 40 |
aliases: ['default-gateway'] |
| 41 |
type: str |
| 42 |
description: Default gateway IP address assigned by the DHCP server. |
| 43 |
dns_server1: |
| 44 |
aliases: ['dns-server1'] |
| 45 |
type: str |
| 46 |
description: DNS server 1. |
| 47 |
dns_server2: |
| 48 |
aliases: ['dns-server2'] |
| 49 |
type: str |
| 50 |
description: DNS server 2. |
| 51 |
dns_server3: |
| 52 |
aliases: ['dns-server3'] |
| 53 |
type: str |
| 54 |
description: DNS server 3. |
| 55 |
dns_service: |
| 56 |
aliases: ['dns-service'] |
| 57 |
type: str |
| 58 |
description: Options for assigning DNS servers to DHCP clients. |
| 59 |
choices: ['default', 'specify', 'local'] |
| 60 |
id: |
| 61 |
type: int |
| 62 |
description: ID. |
| 63 |
required: true |
| 64 |
interface: |
| 65 |
type: list |
| 66 |
elements: str |
| 67 |
description: DHCP server can assign IP configurations to clients connected to this interface. |
| 68 |
ip_range: |
| 69 |
aliases: ['ip-range'] |
| 70 |
type: list |
| 71 |
elements: dict |
| 72 |
description: Ip range. |
| 73 |
suboptions: |
| 74 |
end_ip: |
| 75 |
aliases: ['end-ip'] |
| 76 |
type: str |
| 77 |
description: End of IP range. |
| 78 |
id: |
| 79 |
type: int |
| 80 |
description: ID. |
| 81 |
start_ip: |
| 82 |
aliases: ['start-ip'] |
| 83 |
type: str |
| 84 |
description: Start of IP range. |
| 85 |
lease_time: |
| 86 |
aliases: ['lease-time'] |
| 87 |
type: int |
| 88 |
description: Lease time in seconds, 0 means unlimited. |
| 89 |
netmask: |
| 90 |
type: str |
| 91 |
description: Netmask assigned by the DHCP server. |
| 92 |
ntp_server1: |
| 93 |
aliases: ['ntp-server1'] |
| 94 |
type: str |
| 95 |
description: NTP server 1. |
| 96 |
ntp_server2: |
| 97 |
aliases: ['ntp-server2'] |
| 98 |
type: str |
| 99 |
description: NTP server 2. |
| 100 |
ntp_server3: |
| 101 |
aliases: ['ntp-server3'] |
| 102 |
type: str |
| 103 |
description: NTP server 3. |
| 104 |
ntp_service: |
| 105 |
aliases: ['ntp-service'] |
| 106 |
type: str |
| 107 |
description: Options for assigning Network Time Protocol |
| 108 |
choices: ['default', 'specify', 'local'] |
| 109 |
options: |
| 110 |
type: list |
| 111 |
elements: dict |
| 112 |
description: Options. |
| 113 |
suboptions: |
| 114 |
code: |
| 115 |
type: int |
| 116 |
description: DHCP option code. |
| 117 |
id: |
| 118 |
type: int |
| 119 |
description: ID. |
| 120 |
ip: |
| 121 |
type: str |
| 122 |
description: DHCP option IPs. |
| 123 |
type: |
| 124 |
type: str |
| 125 |
description: DHCP option type. |
| 126 |
choices: ['hex', 'string', 'ip', 'fqdn'] |
| 127 |
value: |
| 128 |
type: str |
| 129 |
description: DHCP option value. |
| 130 |
status: |
| 131 |
type: str |
| 132 |
description: Enable/disable this DHCP configuration. |
| 133 |
choices: ['disable', 'enable'] |
| 134 |
switch_id: |
| 135 |
aliases: ['switch-id'] |
| 136 |
type: list |
| 137 |
elements: str |
| 138 |
description: Switch ID. |
| 139 |
''' |
| 140 |
|
| 141 |
EXAMPLES = ''' |
| 142 |
- name: Example playbook (generated based on argument schema) |
| 143 |
hosts: fortimanagers |
| 144 |
connection: httpapi |
| 145 |
gather_facts: false |
| 146 |
tasks: |
| 147 |
- name: Configure DHCP servers. |
| 148 |
fortinet.fortimanager.fmgr_switchcontroller_managedswitch_systemdhcpserver: |
| 149 |
# workspace_locking_adom: <global or your adom name> |
| 150 |
adom: <your own value> |
| 151 |
managed_switch: <your own value> |
| 152 |
state: present # <value in [present, absent]> |
| 153 |
switchcontroller_managedswitch_systemdhcpserver: |
| 154 |
id: 0 # Required variable, integer |
| 155 |
# default_gateway: <string> |
| 156 |
# dns_server1: <string> |
| 157 |
# dns_server2: <string> |
| 158 |
# dns_server3: <string> |
| 159 |
# dns_service: <value in [default, specify, local]> |
| 160 |
# interface: <list or string> |
| 161 |
# ip_range: |
| 162 |
# - end_ip: <string> |
| 163 |
# id: <integer> |
| 164 |
# start_ip: <string> |
| 165 |
# lease_time: <integer> |
| 166 |
# netmask: <string> |
| 167 |
# ntp_server1: <string> |
| 168 |
# ntp_server2: <string> |
| 169 |
# ntp_server3: <string> |
| 170 |
# ntp_service: <value in [default, specify, local]> |
| 171 |
# options: |
| 172 |
# - code: <integer> |
| 173 |
# id: <integer> |
| 174 |
# ip: <string> |
| 175 |
# type: <value in [hex, string, ip, ...]> |
| 176 |
# value: <string> |
| 177 |
# status: <value in [disable, enable]> |
| 178 |
# switch_id: <list or string> |
| 179 |
''' |
| 180 |
|
| 181 |
RETURN = ''' |
| 182 |
meta: |
| 183 |
description: The result of the request. |
| 184 |
type: dict |
| 185 |
returned: always |
| 186 |
contains: |
| 187 |
request_url: |
| 188 |
description: The full url requested. |
| 189 |
returned: always |
| 190 |
type: str |
| 191 |
sample: /sys/login/user |
| 192 |
response_code: |
| 193 |
description: The status of api request. |
| 194 |
returned: always |
| 195 |
type: int |
| 196 |
sample: 0 |
| 197 |
response_data: |
| 198 |
description: The api response. |
| 199 |
type: list |
| 200 |
returned: always |
| 201 |
response_message: |
| 202 |
description: The descriptive message of the api response. |
| 203 |
type: str |
| 204 |
returned: always |
| 205 |
sample: OK. |
| 206 |
system_information: |
| 207 |
description: The information of the target system. |
| 208 |
type: dict |
| 209 |
returned: always |
| 210 |
rc: |
| 211 |
description: The status the request. |
| 212 |
type: int |
| 213 |
returned: always |
| 214 |
sample: 0 |
| 215 |
version_check_warning: |
| 216 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 217 |
type: list |
| 218 |
returned: complex |
| 219 |
''' |
| 220 |
from ansible.module_utils.basic import AnsibleModule |
| 221 |
from ansible.module_utils.connection import Connection |
| 222 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 223 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 224 |
|
| 225 |
|
| 226 |
def main(): |
| 227 |
urls_list = [ |
| 228 |
'/pm/config/adom/{adom}/obj/switch-controller/managed-switch/{managed-switch}/system-dhcp-server' |
| 229 |
] |
| 230 |
module_arg_spec = { |
| 231 |
'adom': {'required': True, 'type': 'str'}, |
| 232 |
'managed-switch': {'type': 'str', 'api_name': 'managed_switch'}, |
| 233 |
'managed_switch': {'type': 'str'}, |
| 234 |
'revision_note': {'type': 'str'}, |
| 235 |
'switchcontroller_managedswitch_systemdhcpserver': { |
| 236 |
'type': 'dict', 'v_range': [['7.6.4', '']], |
| 237 |
'options': { |
| 238 |
'default-gateway': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 239 |
'dns-server1': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 240 |
'dns-server2': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 241 |
'dns-server3': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 242 |
'dns-service': {'v_range': [['7.6.4', '']], 'choices': ['default', 'specify', 'local'], 'type': 'str'}, |
| 243 |
'id': {'v_range': [['7.6.4', '']], 'required': True, 'type': 'int'}, |
| 244 |
'interface': {'v_range': [['7.6.4', '']], 'type': 'list', 'elements': 'str'}, |
| 245 |
'ip-range': { |
| 246 |
'v_range': [['7.6.4', '']], |
| 247 |
'type': 'list', |
| 248 |
'options': { |
| 249 |
'end-ip': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 250 |
'id': {'v_range': [['7.6.4', '']], 'type': 'int'}, |
| 251 |
'start-ip': {'v_range': [['7.6.4', '']], 'type': 'str'} |
| 252 |
}, |
| 253 |
'elements': 'dict' |
| 254 |
}, |
| 255 |
'lease-time': {'v_range': [['7.6.4', '']], 'type': 'int'}, |
| 256 |
'netmask': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 257 |
'ntp-server1': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 258 |
'ntp-server2': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 259 |
'ntp-server3': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 260 |
'ntp-service': {'v_range': [['7.6.4', '']], 'choices': ['default', 'specify', 'local'], 'type': 'str'}, |
| 261 |
'options': { |
| 262 |
'v_range': [['7.6.4', '']], |
| 263 |
'type': 'list', |
| 264 |
'options': { |
| 265 |
'code': {'v_range': [['7.6.4', '']], 'type': 'int'}, |
| 266 |
'id': {'v_range': [['7.6.4', '']], 'type': 'int'}, |
| 267 |
'ip': {'v_range': [['7.6.4', '']], 'type': 'str'}, |
| 268 |
'type': {'v_range': [['7.6.4', '']], 'choices': ['hex', 'string', 'ip', 'fqdn'], 'type': 'str'}, |
| 269 |
'value': {'v_range': [['7.6.4', '']], 'type': 'str'} |
| 270 |
}, |
| 271 |
'elements': 'dict' |
| 272 |
}, |
| 273 |
'status': {'v_range': [['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 274 |
'switch-id': {'v_range': [['7.6.4', '']], 'type': 'list', 'elements': 'str'} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
module_option_spec = get_module_arg_spec('full crud') |
| 280 |
module_arg_spec.update(module_option_spec) |
| 281 |
check_galaxy_version(module_arg_spec) |
| 282 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'switchcontroller_managedswitch_systemdhcpserver'), |
| 283 |
supports_check_mode=True) |
| 284 |
if not module._socket_path: |
| 285 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 286 |
connection = Connection(module._socket_path) |
| 287 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 288 |
'id', 'data', module, connection) |
| 289 |
fmgr.process_crud() |
| 290 |
module.exit_json(meta=module.params) |
| 291 |
|
| 292 |
|
| 293 |
if __name__ == '__main__': |
| 294 |
main() |