Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/dellemc_idrac_lc_attributes.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
15 __metaclass__ = type
16
17 DOCUMENTATION = """
18 ---
19 module: dellemc_idrac_lc_attributes
20 short_description: Enable or disable Collect System Inventory on Restart (CSIOR) property for all iDRAC/LC jobs
21 version_added: "1.0.0"
22 deprecated:
23 removed_at_date: "2024-12-31"
24 why: Replaced with M(dellemc.openmanage.idrac_attributes).
25 alternative: Use M(dellemc.openmanage.idrac_attributes) instead.
26 removed_from_collection: dellemc.openmanage
27 description:
28 - This module is responsible for enabling or disabling of Collect System Inventory on Restart (CSIOR)
29 property for all iDRAC/LC jobs.
30 extends_documentation_fragment:
31 - dellemc.openmanage.idrac_auth_options
32 options:
33 share_name:
34 type: str
35 description:
36 - (deprecated)Network share or a local path.
37 - This option is deprecated and will be removed in the later version.
38 share_user:
39 type: str
40 description:
41 - (deprecated)Network share user in the format 'user@domain' or 'domain\\user' if user is
42 part of a domain else 'user'. This option is mandatory for CIFS Network Share.
43 - This option is deprecated and will be removed in the later version.
44 share_password:
45 type: str
46 description:
47 - (deprecated)Network share user password. This option is mandatory for CIFS Network Share.
48 - This option is deprecated and will be removed in the later version.
49 aliases: ['share_pwd']
50 share_mnt:
51 type: str
52 description:
53 - (deprecated)Local mount path of the network share with read-write permission for ansible user.
54 This option is mandatory for Network Share.
55 - This option is deprecated and will be removed in the later version.
56 csior:
57 type: str
58 description: Whether to Enable or Disable Collect System Inventory on Restart (CSIOR)
59 property for all iDRAC/LC jobs.
60 choices: [Enabled, Disabled]
61 default: Enabled
62 requirements:
63 - "omsdk >= 1.2.488"
64 - "python >= 3.9.6"
65 author: "Felix Stephen (@felixs88)"
66 notes:
67 - This module requires 'Administrator' privilege for I(idrac_user).
68 - Run this module from a system that has direct access to Dell iDRAC.
69 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
70 - This module supports C(check_mode).
71 """
72
73 EXAMPLES = """
74 ---
75 - name: Set up iDRAC LC Attributes
76 dellemc.openmanage.dellemc_idrac_lc_attributes:
77 idrac_ip: "192.168.0.1"
78 idrac_user: "user_name"
79 idrac_password: "user_password"
80 ca_path: "/path/to/ca_cert.pem"
81 csior: "Enabled"
82 """
83
84 RETURN = r'''
85 ---
86 msg:
87 description: Overall status of iDRAC LC attributes configuration.
88 returned: always
89 type: str
90 sample: Successfully configured the iDRAC LC attributes.
91 lc_attribute_status:
92 description: Collect System Inventory on Restart (CSIOR) property for all iDRAC/LC jobs is configured.
93 returned: success
94 type: dict
95 sample: {
96 "CompletionTime": "2020-03-30T00:06:53",
97 "Description": "Job Instance",
98 "EndTime": null,
99 "Id": "JID_1234512345",
100 "JobState": "Completed",
101 "JobType": "ImportConfiguration",
102 "Message": "Successfully imported and applied Server Configuration Profile.",
103 "MessageArgs": [],
104 "[email protected]": 0,
105 "MessageId": "SYS053",
106 "Name": "Import Configuration",
107 "PercentComplete": 100,
108 "StartTime": "TIME_NOW",
109 "Status": "Success",
110 "TargetSettingsURI": null,
111 "retval": true
112 }
113 error_info:
114 description: Details of the HTTP Error.
115 returned: on HTTP error
116 type: dict
117 sample: {
118 "error": {
119 "code": "Base.1.0.GeneralError",
120 "message": "A general error has occurred. See ExtendedInfo for more information.",
121 "@Message.ExtendedInfo": [
122 {
123 "MessageId": "GEN1234",
124 "RelatedProperties": [],
125 "Message": "Unable to process the request because an error occurred.",
126 "MessageArgs": [],
127 "Severity": "Critical",
128 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
129 }
130 ]
131 }
132 }
133 '''
134
135 import os
136 import tempfile
137 import json
138 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params
139 from ansible.module_utils.basic import AnsibleModule
140 from ansible.module_utils.urls import ConnectionError, SSLValidationError
141 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
142
143 try:
144 from omsdk.sdkfile import file_share_manager
145 except ImportError:
146 pass
147
148
149 # Get Lifecycle Controller status
150 def run_setup_idrac_csior(idrac, module):
151 """
152 Get Lifecycle Controller status
153
154 Keyword arguments:
155 idrac -- iDRAC handle
156 module -- Ansible module
157 """
158 idrac.use_redfish = True
159 share_path = tempfile.gettempdir() + os.sep
160 upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True)
161 if not upd_share.IsValid:
162 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
163 "share mount, and share credentials provided are correct.")
164 set_liason = idrac.config_mgr.set_liason_share(upd_share)
165 if set_liason['Status'] == "Failed":
166 try:
167 message = set_liason['Data']['Message']
168 except (IndexError, KeyError):
169 message = set_liason['Message']
170 module.fail_json(msg=message)
171 if module.params['csior'] == 'Enabled':
172 # Enable csior
173 idrac.config_mgr.enable_csior()
174 elif module.params['csior'] == 'Disabled':
175 # Disable csior
176 idrac.config_mgr.disable_csior()
177
178 if module.check_mode:
179 status = idrac.config_mgr.is_change_applicable()
180 if status.get("changes_applicable"):
181 module.exit_json(msg="Changes found to commit!", changed=True)
182 else:
183 module.exit_json(msg="No changes found to commit!")
184 else:
185 return idrac.config_mgr.apply_changes(reboot=False)
186
187
188 # Main
189 def main():
190 specs = dict(
191 share_name=dict(required=False, type='str'),
192 share_password=dict(required=False, type='str', aliases=['share_pwd'], no_log=True),
193 share_user=dict(required=False, type='str'),
194 share_mnt=dict(required=False, type='str'),
195 csior=dict(required=False, choices=['Enabled', 'Disabled'], default='Enabled')
196 )
197 specs.update(idrac_auth_params)
198 module = AnsibleModule(
199 argument_spec=specs,
200 supports_check_mode=True)
201
202 try:
203 with iDRACConnection(module.params) as idrac:
204 status = run_setup_idrac_csior(idrac, module)
205 if status.get('Status') == "Success":
206 changed = True
207 msg = "Successfully configured the iDRAC LC attributes."
208 if status.get('Message') and (status.get('Message') == "No changes found to commit!" or
209 "No changes were applied" in status.get('Message')):
210 msg = status.get('Message')
211 changed = False
212 module.exit_json(msg=msg, lc_attribute_status=status, changed=changed)
213 else:
214 module.fail_json(msg="Failed to configure the iDRAC LC attributes.")
215 except HTTPError as err:
216 module.fail_json(msg=str(err), error_info=json.load(err))
217 except URLError as err:
218 module.exit_json(msg=str(err), unreachable=True)
219 except (RuntimeError, ImportError, SSLValidationError, IOError, ValueError, TypeError, ConnectionError) as e:
220 module.fail_json(msg=str(e))
221
222
223 if __name__ == '__main__':
224 main()