Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/idrac_lifecycle_controller_job_status_info.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_lifecycle_controller_job_status_info
19 short_description: Get the status of a Lifecycle Controller job
20 version_added: "2.1.0"
21 description: This module shows the status of a specific Lifecycle Controller job using its job ID.
22 extends_documentation_fragment:
23 - dellemc.openmanage.idrac_auth_options
24 options:
25 job_id:
26 required: true
27 type: str
28 description: JOB ID in the format "JID_123456789012".
29 requirements:
30 - "omsdk >= 1.2.488"
31 - "python >= 3.9.6"
32 author:
33 - "Rajeev Arakkal (@rajeevarakkal)"
34 - "Anooja Vardhineni (@anooja-vardhineni)"
35 - "Trisha Datta (@trisha-dell)"
36 notes:
37 - Run this module from a system that has direct access to Dell iDRAC.
38 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
39 - This module supports C(check_mode).
40 """
41
42 EXAMPLES = """
43 ---
44 - name: Show status of a Lifecycle Control job
45 dellemc.openmanage.idrac_lifecycle_controller_job_status_info:
46 idrac_ip: "192.168.0.1"
47 idrac_user: "user_name"
48 idrac_password: "user_password"
49 ca_path: "/path/to/ca_cert.pem"
50 job_id: "JID_1234567890"
51 """
52
53 RETURN = r'''
54 ---
55 msg:
56 description: Overall status of the job facts operation.
57 returned: always
58 type: str
59 sample: "Successfully fetched the job info."
60 job_info:
61 description: Displays the status of a Lifecycle Controller job.
62 returned: success
63 type: dict
64 sample: {
65 "ElapsedTimeSinceCompletion": "8742",
66 "InstanceID": "JID_844222910040",
67 "JobStartTime": "NA",
68 "JobStatus": "Completed",
69 "JobUntilTime": "NA",
70 "Message": "Job completed successfully.",
71 "MessageArguments": "NA",
72 "MessageID": "RED001",
73 "Name": "update:DCIM:INSTALLED#iDRAC.Embedded.1-1#IDRACinfo",
74 "PercentComplete": "100",
75 "Status": "Success"
76 }
77 error_info:
78 description: Details of the HTTP Error.
79 returned: on HTTP error
80 type: dict
81 sample: {
82 "error": {
83 "code": "Base.1.0.GeneralError",
84 "message": "A general error has occurred. See ExtendedInfo for more information.",
85 "@Message.ExtendedInfo": [
86 {
87 "MessageId": "GEN1234",
88 "RelatedProperties": [],
89 "Message": "Unable to process the request because an error occurred.",
90 "MessageArgs": [],
91 "Severity": "Critical",
92 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
93 }
94 ]
95 }
96 }
97 '''
98
99
100 import json
101 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac \
102 import iDRACConnection, idrac_auth_params
103 from ansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfish \
104 import iDRACRedfishAPI
105 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
106 from ansible.module_utils.urls import ConnectionError, SSLValidationError
107 from ansible.module_utils.basic import AnsibleModule
108 from ansible_collections.dellemc.openmanage.plugins.module_utils.\
109 idrac_utils.info.lifecycle_controller_job_status \
110 import IDRACLifecycleControllerJobStatusInfo
111 from ansible_collections.dellemc.openmanage.plugins.module_utils.\
112 idrac_utils.info.firmware import IDRACFirmwareInfo
113
114 ERR_STATUS = 404
115 FETCH_MESSAGE = "Successfully fetched the job info."
116
117
118 def main():
119 specs = {
120 "job_id": {"required": True, "type": 'str'}
121 }
122 specs.update(idrac_auth_params)
123 module = AnsibleModule(
124 argument_spec=specs,
125 supports_check_mode=True)
126
127 try:
128 with iDRACRedfishAPI(module.params) as idrac:
129 firmware_obj = IDRACFirmwareInfo(idrac)
130 if not firmware_obj.is_omsdk_required():
131 response = \
132 IDRACLifecycleControllerJobStatusInfo(idrac). \
133 get_lifecycle_controller_job_status_info(job_id=module.params["job_id"])
134 if response != "Job ID is invalid":
135 lifecycle_controller_job_status_info = \
136 IDRACLifecycleControllerJobStatusInfo(idrac). \
137 transform_job_status_data(info_data=response.json_data)
138 else:
139 module.exit_json(msg=FETCH_MESSAGE,
140 job_info={})
141 else:
142 with iDRACConnection(module.params) as idrac:
143 job_id = module.params.get('job_id')
144 lifecycle_controller_job_status_info = \
145 idrac.job_mgr.get_job_status(job_id)
146 if lifecycle_controller_job_status_info.get('Status') == "Found Fault":
147 module.exit_json(msg=FETCH_MESSAGE,
148 job_info={})
149 except HTTPError as err:
150 module.exit_json(msg=str(err), error_info=json.load(err),
151 failed=True)
152 except URLError as err:
153 module.exit_json(msg=str(err), unreachable=True)
154 except (RuntimeError,
155 SSLValidationError,
156 IOError, ValueError,
157 TypeError,
158 ConnectionError) as e:
159 module.exit_json(msg=str(e), failed=True)
160
161 module.exit_json(msg="Successfully fetched the job info.",
162 job_info=lifecycle_controller_job_status_info)
163
164
165 if __name__ == '__main__':
166 main()