Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/idrac_network.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 7.1.0
7 # Copyright (C) 2018-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
8
9 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
10 #
11
12
13 from __future__ import (absolute_import, division, print_function)
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: idrac_network
19 short_description: Configures the iDRAC network attributes
20 version_added: "2.1.0"
21 deprecated:
22 removed_at_date: "2024-12-31"
23 why: Replaced with M(dellemc.openmanage.idrac_attributes).
24 alternative: Use M(dellemc.openmanage.idrac_attributes) instead.
25 removed_from_collection: dellemc.openmanage
26 description:
27 - This module allows to configure iDRAC network settings.
28 extends_documentation_fragment:
29 - dellemc.openmanage.idrac_auth_options
30 options:
31 share_name:
32 type: str
33 description:
34 - (deprecated)Network share or a local path.
35 - This option is deprecated and will be removed in the later version.
36 share_user:
37 type: str
38 description:
39 - (deprecated)Network share user name. Use the format 'user@domain' or 'domain\\user' if user is part of a domain.
40 This option is mandatory for CIFS share.
41 - This option is deprecated and will be removed in the later version.
42 share_password:
43 type: str
44 description:
45 - (deprecated)Network share user password. This option is mandatory for CIFS share.
46 - This option is deprecated and will be removed in the later version.
47 aliases: ['share_pwd']
48 share_mnt:
49 type: str
50 description:
51 - (deprecated)Local mount path of the network share with read-write permission for ansible user.
52 This option is mandatory for network shares.
53 - This option is deprecated and will be removed in the later version.
54 setup_idrac_nic_vlan:
55 type: str
56 description: Allows to configure VLAN on iDRAC.
57 choices: [Enabled, Disabled]
58 register_idrac_on_dns:
59 type: str
60 description: Registers iDRAC on a Domain Name System (DNS).
61 choices: [Enabled, Disabled]
62 dns_idrac_name:
63 type: str
64 description: Name of the DNS to register iDRAC.
65 auto_config:
66 type: str
67 description: Allows to enable or disable auto-provisioning to automatically acquire domain name from DHCP.
68 choices: [Enabled, Disabled]
69 static_dns:
70 type: str
71 description: Enter the static DNS domain name.
72 vlan_id:
73 type: int
74 description: Enter the VLAN ID. The VLAN ID must be a number from 1 through 4094.
75 vlan_priority:
76 type: int
77 description: Enter the priority for the VLAN ID. The priority value must be a number from 0 through 7.
78 enable_nic:
79 type: str
80 description: Allows to enable or disable the Network Interface Controller (NIC) used by iDRAC.
81 choices: [Enabled, Disabled]
82 nic_selection:
83 type: str
84 description: Select one of the available NICs.
85 choices: [Dedicated, LOM1, LOM2, LOM3, LOM4]
86 failover_network:
87 type: str
88 description: "Select one of the remaining LOMs. If a network fails, the traffic is routed through the failover
89 network."
90 choices: [ALL, LOM1, LOM2, LOM3, LOM4, T_None]
91 auto_detect:
92 type: str
93 description: Allows to auto detect the available NIC types used by iDRAC.
94 choices: [Enabled, Disabled]
95 auto_negotiation:
96 type: str
97 description: Allows iDRAC to automatically set the duplex mode and network speed.
98 choices: [Enabled, Disabled]
99 network_speed:
100 type: str
101 description: Select the network speed for the selected NIC.
102 choices: [T_10, T_100, T_1000]
103 duplex_mode:
104 type: str
105 description: Select the type of data transmission for the NIC.
106 choices: [Full, Half]
107 nic_mtu:
108 type: int
109 description: Maximum Transmission Unit of the NIC.
110 ip_address:
111 type: str
112 description: Enter a valid iDRAC static IPv4 address.
113 enable_dhcp:
114 type: str
115 description: Allows to enable or disable Dynamic Host Configuration Protocol (DHCP) in iDRAC.
116 choices: [Enabled, Disabled]
117 enable_ipv4:
118 type: str
119 description: Allows to enable or disable IPv4 configuration.
120 choices: [Enabled, Disabled]
121 dns_from_dhcp:
122 type: str
123 description: Allows to enable DHCP to obtain DNS server address.
124 choices: [Enabled, Disabled]
125 static_dns_1:
126 type: str
127 description: Enter the preferred static DNS server IPv4 address.
128 static_dns_2:
129 type: str
130 description: Enter the preferred static DNS server IPv4 address.
131 static_gateway:
132 type: str
133 description: Enter the static IPv4 gateway address to iDRAC.
134 static_net_mask:
135 type: str
136 description: Enter the static IP subnet mask to iDRAC.
137 requirements:
138 - "omsdk >= 1.2.488"
139 - "python >= 3.9.6"
140 author:
141 - "Felix Stephen (@felixs88)"
142 - "Anooja Vardhineni (@anooja-vardhineni)"
143 notes:
144 - This module requires 'Administrator' privilege for I(idrac_user).
145 - Run this module from a system that has direct access to Dell iDRAC.
146 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
147 - This module supports C(check_mode).
148 """
149
150 EXAMPLES = """
151 ---
152 - name: Configure iDRAC network settings
153 dellemc.openmanage.idrac_network:
154 idrac_ip: "192.168.0.1"
155 idrac_user: "user_name"
156 idrac_password: "user_password"
157 ca_path: "/path/to/ca_cert.pem"
158 register_idrac_on_dns: Enabled
159 dns_idrac_name: None
160 auto_config: None
161 static_dns: None
162 setup_idrac_nic_vlan: Enabled
163 vlan_id: 0
164 vlan_priority: 1
165 enable_nic: Enabled
166 nic_selection: Dedicated
167 failover_network: T_None
168 auto_detect: Disabled
169 auto_negotiation: Enabled
170 network_speed: T_1000
171 duplex_mode: Full
172 nic_mtu: 1500
173 ip_address: "192.168.0.1"
174 enable_dhcp: Enabled
175 enable_ipv4: Enabled
176 static_dns_1: "192.168.0.1"
177 static_dns_2: "192.168.0.1"
178 dns_from_dhcp: Enabled
179 static_gateway: None
180 static_net_mask: None
181 """
182
183 RETURN = r'''
184 ---
185 msg:
186 description: Successfully configured the idrac network settings.
187 returned: always
188 type: str
189 sample: "Successfully configured the idrac network settings."
190 network_status:
191 description: Status of the Network settings operation job.
192 returned: success
193 type: dict
194 sample: {
195 "@odata.context": "/redfish/v1/$metadata#DellJob.DellJob",
196 "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/JID_856418531008",
197 "@odata.type": "#DellJob.v1_0_2.DellJob",
198 "CompletionTime": "2020-03-31T03:04:15",
199 "Description": "Job Instance",
200 "EndTime": null,
201 "Id": "JID_856418531008",
202 "JobState": "Completed",
203 "JobType": "ImportConfiguration",
204 "Message": "Successfully imported and applied Server Configuration Profile.",
205 "MessageArgs": [],
206 "[email protected]": 0,
207 "MessageId": "SYS053",
208 "Name": "Import Configuration",
209 "PercentComplete": 100,
210 "StartTime": "TIME_NOW",
211 "Status": "Success",
212 "TargetSettingsURI": null,
213 "retval": true
214 }
215 error_info:
216 description: Details of the HTTP Error.
217 returned: on HTTP error
218 type: dict
219 sample: {
220 "error": {
221 "code": "Base.1.0.GeneralError",
222 "message": "A general error has occurred. See ExtendedInfo for more information.",
223 "@Message.ExtendedInfo": [
224 {
225 "MessageId": "GEN1234",
226 "RelatedProperties": [],
227 "Message": "Unable to process the request because an error occurred.",
228 "MessageArgs": [],
229 "Severity": "Critical",
230 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
231 }
232 ]
233 }
234 }
235 '''
236
237 import os
238 import tempfile
239 import json
240 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
241 from ansible.module_utils.urls import ConnectionError, SSLValidationError
242 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params
243 from ansible.module_utils.basic import AnsibleModule
244 try:
245 from omdrivers.enums.iDRAC.iDRAC import (DNSRegister_NICTypes, DNSDomainFromDHCP_NICStaticTypes,
246 Enable_NICTypes, VLanEnable_NICTypes,
247 Selection_NICTypes, Failover_NICTypes,
248 AutoDetect_NICTypes, Autoneg_NICTypes,
249 Speed_NICTypes, Duplex_NICTypes, DHCPEnable_IPv4Types,
250 Enable_IPv4Types, DNSFromDHCP_IPv4StaticTypes)
251 from omsdk.sdkfile import file_share_manager
252 except ImportError:
253 pass
254
255
256 def run_idrac_network_config(idrac, module):
257 idrac.use_redfish = True
258 share_path = tempfile.gettempdir() + os.sep
259 upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True)
260 if not upd_share.IsValid:
261 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
262 "share mount, and share credentials provided are correct.")
263 idrac.config_mgr.set_liason_share(upd_share)
264 if module.params['register_idrac_on_dns'] is not None:
265 idrac.config_mgr.configure_dns(
266 register_idrac_on_dns=DNSRegister_NICTypes[module.params['register_idrac_on_dns']]
267 )
268 if module.params['dns_idrac_name'] is not None:
269 idrac.config_mgr.configure_dns(
270 dns_idrac_name=module.params['dns_idrac_name']
271 )
272 if module.params['auto_config'] is not None:
273 idrac.config_mgr.configure_dns(
274 auto_config=DNSDomainFromDHCP_NICStaticTypes[module.params['auto_config']]
275 )
276 if module.params['static_dns'] is not None:
277 idrac.config_mgr.configure_dns(
278 static_dns=module.params['static_dns']
279 )
280
281 if module.params['setup_idrac_nic_vlan'] is not None:
282 idrac.config_mgr.configure_nic_vlan(
283 vlan_enable=VLanEnable_NICTypes[module.params['setup_idrac_nic_vlan']]
284 )
285 if module.params['vlan_id'] is not None:
286 idrac.config_mgr.configure_nic_vlan(
287 vlan_id=module.params['vlan_id']
288 )
289 if module.params['vlan_priority'] is not None:
290 idrac.config_mgr.configure_nic_vlan(
291 vlan_priority=module.params['vlan_priority']
292 )
293
294 if module.params['enable_nic'] is not None:
295 idrac.config_mgr.configure_network_settings(
296 enable_nic=Enable_NICTypes[module.params['enable_nic']]
297 )
298 if module.params['nic_selection'] is not None:
299 idrac.config_mgr.configure_network_settings(
300 nic_selection=Selection_NICTypes[module.params['nic_selection']]
301 )
302 if module.params['failover_network'] is not None:
303 idrac.config_mgr.configure_network_settings(
304 failover_network=Failover_NICTypes[module.params['failover_network']]
305 )
306 if module.params['auto_detect'] is not None:
307 idrac.config_mgr.configure_network_settings(
308 auto_detect=AutoDetect_NICTypes[module.params['auto_detect']]
309 )
310 if module.params['auto_negotiation'] is not None:
311 idrac.config_mgr.configure_network_settings(
312 auto_negotiation=Autoneg_NICTypes[module.params['auto_negotiation']]
313 )
314 if module.params['network_speed'] is not None:
315 idrac.config_mgr.configure_network_settings(
316 network_speed=Speed_NICTypes[module.params['network_speed']]
317 )
318 if module.params['duplex_mode'] is not None:
319 idrac.config_mgr.configure_network_settings(
320 duplex_mode=Duplex_NICTypes[module.params['duplex_mode']]
321 )
322 if module.params['nic_mtu'] is not None:
323 idrac.config_mgr.configure_network_settings(
324 nic_mtu=module.params['nic_mtu']
325 )
326
327 if module.params['enable_dhcp'] is not None:
328 idrac.config_mgr.configure_ipv4(
329 enable_dhcp=DHCPEnable_IPv4Types[module.params["enable_dhcp"]]
330 )
331 if module.params['ip_address'] is not None:
332 idrac.config_mgr.configure_ipv4(
333 ip_address=module.params["ip_address"]
334 )
335 if module.params['enable_ipv4'] is not None:
336 idrac.config_mgr.configure_ipv4(
337 enable_ipv4=Enable_IPv4Types[module.params["enable_ipv4"]]
338 )
339 if module.params['dns_from_dhcp'] is not None:
340 idrac.config_mgr.configure_static_ipv4(
341 dns_from_dhcp=DNSFromDHCP_IPv4StaticTypes[module.params["dns_from_dhcp"]]
342 )
343 if module.params['static_dns_1'] is not None:
344 idrac.config_mgr.configure_static_ipv4(
345 dns_1=module.params["static_dns_1"]
346 )
347 if module.params['static_dns_2'] is not None:
348 idrac.config_mgr.configure_static_ipv4(
349 dns_2=module.params["static_dns_2"]
350 )
351 if module.params['static_gateway'] is not None:
352 idrac.config_mgr.configure_static_ipv4(
353 gateway=module.params["static_gateway"]
354 )
355 if module.params['static_net_mask'] is not None:
356 idrac.config_mgr.configure_static_ipv4(
357 net_mask=module.params["static_net_mask"]
358 )
359
360 if module.check_mode:
361 msg = idrac.config_mgr.is_change_applicable()
362 else:
363 msg = idrac.config_mgr.apply_changes(reboot=False)
364 return msg
365
366
367 # Main
368 def main():
369 specs = {
370 # Export Destination
371 "share_name": {"required": False, "type": 'str'},
372 "share_password": {"required": False, "type": 'str', "aliases": ['share_pwd'], "no_log": True},
373 "share_user": {"required": False, "type": 'str'},
374 "share_mnt": {"required": False, "type": 'str'},
375
376 # setup DNS
377 "register_idrac_on_dns": {"required": False, "choices": ['Enabled', 'Disabled'], "default": None},
378 "dns_idrac_name": {"required": False, "default": None, "type": 'str'},
379 "auto_config": {"required": False, "choices": ['Enabled', 'Disabled'], "default": None, 'type': 'str'},
380 "static_dns": {"required": False, "default": None, "type": "str"},
381
382 # set up idrac vlan
383 "setup_idrac_nic_vlan": {"required": False, "choices": ['Enabled', 'Disabled']},
384 "vlan_id": {"required": False, "type": 'int'},
385 "vlan_priority": {"required": False, "type": 'int'},
386
387 # set up NIC
388 "enable_nic": {"required": False, "choices": ['Enabled', 'Disabled'], "default": None},
389 "nic_selection": {"required": False, "choices": ['Dedicated', 'LOM1', 'LOM2', 'LOM3', 'LOM4'], "default": None},
390 "failover_network": {"required": False, "choices": ['ALL', 'LOM1', 'LOM2', 'LOM3', 'LOM4', 'T_None'],
391 "default": None},
392 "auto_detect": {"required": False, "choices": ['Enabled', 'Disabled'], "default": None},
393 "auto_negotiation": {"required": False, "choices": ['Enabled', 'Disabled'], "default": None},
394 "network_speed": {"required": False, "choices": ['T_10', 'T_100', 'T_1000'], "default": None},
395 "duplex_mode": {"required": False, "choices": ['Full', 'Half'], "default": None},
396 "nic_mtu": {"required": False, 'type': 'int'},
397
398 # setup iDRAC IPV4
399 "ip_address": {"required": False, "default": None, "type": "str"},
400 "enable_dhcp": {"required": False, "choices": ["Enabled", "Disabled"], "default": None},
401 "enable_ipv4": {"required": False, "choices": ["Enabled", "Disabled"], "default": None},
402
403 # setup iDRAC Static IPv4
404 "dns_from_dhcp": {"required": False, "choices": ["Enabled", "Disabled"], "default": None},
405 "static_dns_1": {"required": False, "default": None, "type": "str"},
406 "static_dns_2": {"required": False, "default": None, "type": "str"},
407 "static_gateway": {"required": False, "type": "str"},
408 "static_net_mask": {"required": False, "type": "str"},
409 }
410 specs.update(idrac_auth_params)
411 module = AnsibleModule(
412 argument_spec=specs,
413 supports_check_mode=True)
414
415 try:
416 with iDRACConnection(module.params) as idrac:
417 msg = run_idrac_network_config(idrac, module)
418 changed, failed = False, False
419 if msg.get('Status') == "Success":
420 changed = True
421 if msg.get('Message') == "No changes found to commit!":
422 changed = False
423 if "No changes were applied" in msg.get('Message'):
424 changed = False
425 elif msg.get('Status') == "Failed":
426 failed = True
427 except HTTPError as err:
428 module.fail_json(msg=str(err), error_info=json.load(err))
429 except URLError as err:
430 module.exit_json(msg=str(err), unreachable=True)
431 except AttributeError as err:
432 if "NoneType" in str(err):
433 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
434 "share mount, and share credentials provided are correct.")
435 except (RuntimeError, SSLValidationError, ConnectionError, KeyError,
436 ImportError, ValueError, TypeError) as e:
437 module.fail_json(msg=str(e))
438 module.exit_json(msg="Successfully configured the idrac network settings.",
439 network_status=msg, changed=changed, failed=failed)
440
441
442 if __name__ == '__main__':
443 main()