| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from __future__ import (absolute_import, division, print_function) |
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = """ |
| 17 |
--- |
| 18 |
module: idrac_lifecycle_controller_jobs |
| 19 |
short_description: Delete the Lifecycle Controller Jobs |
| 20 |
version_added: "2.1.0" |
| 21 |
description: |
| 22 |
- Delete a Lifecycle Controller job using its job ID or delete all jobs. |
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.openmanage.idrac_auth_options |
| 25 |
options: |
| 26 |
job_id: |
| 27 |
type: str |
| 28 |
description: |
| 29 |
- Job ID of the specific job to be deleted. |
| 30 |
- All the jobs in the job queue are deleted if this option is not specified. |
| 31 |
|
| 32 |
requirements: |
| 33 |
- "omsdk >= 1.2.488" |
| 34 |
- "python >= 3.9.6" |
| 35 |
author: |
| 36 |
- "Felix Stephen (@felixs88)" |
| 37 |
- "Anooja Vardhineni (@anooja-vardhineni)" |
| 38 |
- "Saksham Nautiyal (@Saksham-Nautiyal)" |
| 39 |
notes: |
| 40 |
- Run this module from a system that has direct access to Dell iDRAC. |
| 41 |
- This module supports both IPv4 and IPv6 address for I(idrac_ip). |
| 42 |
- This module does not support C(check_mode). |
| 43 |
""" |
| 44 |
EXAMPLES = """ |
| 45 |
--- |
| 46 |
- name: Delete Lifecycle Controller job queue |
| 47 |
dellemc.openmanage.idrac_lifecycle_controller_jobs: |
| 48 |
idrac_ip: "192.168.0.1" |
| 49 |
idrac_user: "user_name" |
| 50 |
idrac_password: "user_password" |
| 51 |
ca_path: "/path/to/ca_cert.pem" |
| 52 |
|
| 53 |
- name: Delete Lifecycle Controller job using a job ID |
| 54 |
dellemc.openmanage.idrac_lifecycle_controller_jobs: |
| 55 |
idrac_ip: "192.168.0.1" |
| 56 |
idrac_user: "user_name" |
| 57 |
idrac_password: "user_password" |
| 58 |
ca_path: "/path/to/ca_cert.pem" |
| 59 |
job_id: "JID_801841929470" |
| 60 |
""" |
| 61 |
RETURN = """ |
| 62 |
--- |
| 63 |
msg: |
| 64 |
type: str |
| 65 |
description: Status of the delete operation. |
| 66 |
returned: always |
| 67 |
sample: 'Successfully deleted the job.' |
| 68 |
status: |
| 69 |
type: dict |
| 70 |
description: Details of the delete operation. |
| 71 |
returned: success |
| 72 |
sample: { |
| 73 |
'Message': 'The specified job was deleted', |
| 74 |
'MessageID': 'SUP020', |
| 75 |
'ReturnValue': '0' |
| 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.\ |
| 102 |
dellemc_idrac import iDRACConnection, idrac_auth_params |
| 103 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfish \ |
| 104 |
import iDRACRedfishAPI |
| 105 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.idrac_utils.\ |
| 106 |
lifecycle_controller.lifecycle_controller_jobs \ |
| 107 |
import IDRACLifecycleControllerJobs |
| 108 |
from ansible.module_utils.basic import AnsibleModule |
| 109 |
from urllib.error import URLError, HTTPError |
| 110 |
|
| 111 |
|
| 112 |
def main(): |
| 113 |
specs = { |
| 114 |
"job_id": {"required": False, "type": 'str'} |
| 115 |
} |
| 116 |
specs.update(idrac_auth_params) |
| 117 |
module = AnsibleModule( |
| 118 |
argument_spec=specs, |
| 119 |
supports_check_mode=False) |
| 120 |
try: |
| 121 |
with iDRACRedfishAPI(module.params) as idrac: |
| 122 |
server_det = idrac.get_server_generation |
| 123 |
server_hw_model = server_det[2] |
| 124 |
if server_hw_model != "iDRAC 8": |
| 125 |
job_id, resp = module.params.get('job_id'), {} |
| 126 |
lifecycle_controller_jobs_obj = IDRACLifecycleControllerJobs(idrac) |
| 127 |
resp, jobstr = lifecycle_controller_jobs_obj.lifecycle_controller_jobs_operation(module) |
| 128 |
|
| 129 |
else: |
| 130 |
with iDRACConnection(module.params) as idrac: |
| 131 |
job_id, resp = module.params.get('job_id'), {} |
| 132 |
if job_id is not None: |
| 133 |
resp = idrac.job_mgr.delete_job(job_id) |
| 134 |
jobstr = "job" |
| 135 |
else: |
| 136 |
resp = idrac.job_mgr.delete_all_jobs() |
| 137 |
jobstr = "job queue" |
| 138 |
if resp["Status"] == "Error": |
| 139 |
msg = "Failed to delete the Job: {0}.".format(job_id) |
| 140 |
module.exit_json(msg=msg, status=resp, failed=True) |
| 141 |
except HTTPError as err: |
| 142 |
if err.code == 400: |
| 143 |
error_info = json.load(err) |
| 144 |
resp = lifecycle_controller_jobs_obj.extract_error_info(error_info) |
| 145 |
msg = "Failed to delete the Job: {0}.".format(job_id) |
| 146 |
module.exit_json(msg=msg, status=resp, failed=True) |
| 147 |
module.exit_json(msg=str(err), error_info=json.load(err), failed=True) |
| 148 |
except URLError as err: |
| 149 |
module.exit_json(msg=str(err), unreachable=True) |
| 150 |
except (ImportError, ValueError, RuntimeError, TypeError) as e: |
| 151 |
module.exit_json(msg=str(e), failed=True) |
| 152 |
module.exit_json(msg="Successfully deleted the {0}.".format(jobstr), status=resp, changed=True) |
| 153 |
|
| 154 |
|
| 155 |
if __name__ == '__main__': |
| 156 |
main() |