Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 10.0.1
7 # Copyright (C) 2021-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 from __future__ import (absolute_import, division, print_function)
13 __metaclass__ = type
14
15 DOCUMENTATION = """
16 ---
17 module: ome_chassis_slots
18 short_description: Rename sled slots on OpenManage Enterprise Modular
19 description: "This module allows to rename sled slots on OpenManage Enterprise Modular either using device id or device
20 service tag or using chassis service tag and slot number."
21 version_added: "3.6.0"
22 author:
23 - Jagadeesh N V(@jagadeeshnv)
24 - Akash Shendge(@shenda1)
25 extends_documentation_fragment:
26 - dellemc.openmanage.omem_auth_options
27 options:
28 device_options:
29 type: list
30 elements: dict
31 description:
32 - The ID or service tag of the sled in the slot and the new name for the slot.
33 - I(device_options) is mutually exclusive with I(slot_options).
34 suboptions:
35 device_id:
36 type: int
37 description:
38 - Device ID of the sled in the slot.
39 - This is mutually exclusive with I(device_service_tag).
40 device_service_tag:
41 type: str
42 description:
43 - Service tag of the sled in the slot.
44 - This is mutually exclusive with I(device_id).
45 slot_name:
46 type: str
47 description: Provide name for the slot.
48 required: true
49 slot_options:
50 type: list
51 elements: dict
52 description:
53 - The service tag of the chassis, slot number of the slot to be renamed, and the new name for the slot.
54 - I(slot_options) is mutually exclusive with I(device_options).
55 suboptions:
56 chassis_service_tag:
57 type: str
58 description: Service tag of the chassis.
59 required: true
60 slots:
61 type: list
62 elements: dict
63 description:
64 - The slot number and the new name for the slot.
65 required: true
66 suboptions:
67 slot_number:
68 type: int
69 description: The slot number of the slot to be renamed.
70 required: true
71 slot_name:
72 type: str
73 description: Provide name for the slot.
74 required: true
75 requirements:
76 - "python >= 3.9.6"
77 notes:
78 - "This module initiates the refresh inventory task. It may take a minute for new names to be reflected.
79 If the task exceeds 300 seconds to refresh, the task times out."
80 - Run this module from a system that has direct access to Dell OpenManage Enterprise Modular.
81 - This module supports C(check_mode).
82 """
83
84 EXAMPLES = """
85 ---
86 - name: Rename the slots in multiple chassis using slot number and chassis service tag
87 dellemc.openmanage.ome_chassis_slots:
88 hostname: "192.168.0.1"
89 username: "username"
90 password: "password"
91 ca_path: "/path/to/ca_cert.pem"
92 slot_options:
93 - chassis_service_tag: ABC1234
94 slots:
95 - slot_number: 1
96 slot_name: sled_name_1
97 - slot_number: 2
98 slot_name: sled_name_2
99 - chassis_service_tag: ABC1235
100 slots:
101 - slot_number: 1
102 slot_name: sled_name_1
103 - slot_number: 2
104 slot_name: sled_name_2
105
106 - name: Rename single slot name of the sled using sled ID
107 dellemc.openmanage.ome_chassis_slots:
108 hostname: "192.168.0.1"
109 username: "username"
110 password: "password"
111 ca_path: "/path/to/ca_cert.pem"
112 device_options:
113 - device_id: 10054
114 slot_name: slot_device_name_1
115
116 - name: Rename single slot name of the sled using sled service tag
117 dellemc.openmanage.ome_chassis_slots:
118 hostname: "192.168.0.1"
119 username: "username"
120 password: "password"
121 ca_path: "/path/to/ca_cert.pem"
122 device_options:
123 - device_service_tag: ABC1234
124 slot_name: service_tag_slot
125
126 - name: Rename multiple slot names of the devices
127 dellemc.openmanage.ome_chassis_slots:
128 hostname: "192.168.0.1"
129 username: "username"
130 password: "password"
131 ca_path: "/path/to/ca_cert.pem"
132 device_options:
133 - device_id: 10054
134 slot_name: sled_name_1
135 - device_service_tag: ABC1234
136 slot_name: sled_name_2
137 - device_id: 10055
138 slot_name: sled_name_3
139 - device_service_tag: PQR1234
140 slot_name: sled_name_4
141 """
142
143 RETURN = """
144 ---
145 msg:
146 type: str
147 description: Overall status of the slot rename operation.
148 returned: always
149 sample: "Successfully renamed the slot(s)."
150 slot_info:
151 description:
152 - Information of the slots that are renamed successfully.
153 - The C(DeviceServiceTag) and C(DeviceId) options are available only if I(device_options) is used.
154 - C(NOTE) Only the slots which were renamed are listed.
155 type: list
156 elements: dict
157 returned: if at least one slot renamed
158 sample: [
159 {
160 "ChassisId": 10053,
161 "ChassisServiceTag": "ABCD123",
162 "DeviceName": "",
163 "DeviceType": 1000,
164 "JobId": 15746,
165 "SlotId": "10072",
166 "SlotName": "slot_op2",
167 "SlotNumber": "6",
168 "SlotType": 2000
169 },
170 {
171 "ChassisId": 10053,
172 "ChassisName": "MX-ABCD123",
173 "ChassisServiceTag": "ABCD123",
174 "DeviceType": "3000",
175 "JobId": 15747,
176 "SlotId": "10070",
177 "SlotName": "slot_op2",
178 "SlotNumber": "4",
179 "SlotType": "2000"
180 },
181 {
182 "ChassisId": "10053",
183 "ChassisName": "MX-PQRS123",
184 "ChassisServiceTag": "PQRS123",
185 "DeviceId": "10054",
186 "DeviceServiceTag": "XYZ5678",
187 "DeviceType": "1000",
188 "JobId": 15761,
189 "SlotId": "10067",
190 "SlotName": "a1",
191 "SlotNumber": "1",
192 "SlotType": "2000"
193 }
194 ]
195 rename_failed_slots:
196 description:
197 - Information of the valid slots that are not renamed.
198 - C(JobStatus) is shown if rename job fails.
199 - C(NOTE) Only slots which were not renamed are listed.
200 type: list
201 elements: dict
202 returned: if at least one slot renaming fails
203 sample: [
204 {
205 "ChassisId": "12345",
206 "ChassisName": "MX-ABCD123",
207 "ChassisServiceTag": "ABCD123",
208 "DeviceType": "4000",
209 "JobId": 1234,
210 "JobStatus": "Aborted",
211 "SlotId": "10061",
212 "SlotName": "c2",
213 "SlotNumber": "1",
214 "SlotType": "4000"
215 },
216 {
217 "ChassisId": "10053",
218 "ChassisName": "MX-PQRS123",
219 "ChassisServiceTag": "PQRS123",
220 "DeviceType": "1000",
221 "JobId": 0,
222 "JobStatus": "HTTP Error 400: Bad Request",
223 "SlotId": "10069",
224 "SlotName": "b2",
225 "SlotNumber": "3",
226 "SlotType": "2000"
227 }
228 ]
229 error_info:
230 description: Details of the HTTP Error.
231 returned: on HTTP error
232 type: dict
233 sample: {
234 "error": {
235 "code": "Base.1.0.GeneralError",
236 "message": "A general error has occurred. See ExtendedInfo for more information.",
237 "@Message.ExtendedInfo": [
238 {
239 "MessageId": "CGEN1014",
240 "RelatedProperties": [],
241 "Message": "Unable to complete the operation because an invalid value is entered for the property
242 Invalid json type: STRING for Edm.Int64 property: Id .",
243 "MessageArgs": [
244 "Invalid json type: STRING for Edm.Int64 property: Id"
245 ],
246 "Severity": "Critical",
247 "Resolution": "Enter a valid value for the property and retry the operation. For more information about
248 valid values, see the OpenManage Enterprise-Modular User's Guide available on the support site."
249 }
250 ]
251 }
252 }
253 """
254
255 import json
256 import time
257 from ssl import SSLError
258 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
259 from ansible.module_utils.urls import ConnectionError
260 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
261 from ansible.module_utils.common.dict_transformations import recursive_diff
262
263 DEVICE_URI = "DeviceService/Devices"
264 JOB_URI = "JobService/Jobs"
265 DEVICE_REPEATED = "Duplicate device entry found for devices with identifiers {0}."
266 INVALID_SLOT_DEVICE = "Unable to rename one or more slots because either the specified device is invalid or slots " \
267 "cannot be configured. The devices for which the slots cannot be renamed are: {0}."
268 JOBS_TRIG_FAIL = "Unable to initiate the slot name rename jobs."
269 SUCCESS_MSG = "Successfully renamed the slot(s)."
270 SUCCESS_REFRESH_MSG = "The rename slot job(s) completed successfully. " \
271 "For changes to reflect, refresh the inventory task manually."
272 FAILED_MSG = "Failed to rename {0} of {1} slot names."
273 NO_CHANGES_MSG = "No changes found to be applied."
274 CHANGES_FOUND = "Changes found to be applied."
275 SLOT_JOB_DESC = "The rename slot task initiated from OpenManage Ansible Module collections"
276 REFRESH_JOB_DESC = "The refresh inventory task initiated from OpenManage Ansible Module collections"
277 CHASSIS_TAG_INVALID = "Provided chassis {0} is invalid."
278 INVALID_SLOT_NUMBERS = "Unable to rename one or more slots because the slot number(s) are invalid: {0}."
279 SLOT_NUM_DUP = "Slot numbers are repeated for chassis {0}."
280 CHASSIS_REPEATED = "Duplicate chassis entry found for chassis with service tags {0}."
281 SETTLING_TIME = 2 # time gap between so consecutive job trigger
282 JOB_TIMEOUT = 300
283 JOB_INTERVAL = 5
284
285
286 def get_device_slot_config(module, rest_obj):
287 ids, tags = {}, {}
288 dvc_list = []
289 for dvc in module.params.get('device_options'):
290 sn = dvc.get('slot_name')
291 id = dvc.get('device_id')
292 st = dvc.get('device_service_tag')
293 if id:
294 ids[str(id)] = sn
295 dvc_list.append(str(id))
296 else:
297 tags[st] = sn
298 dvc_list.append(st)
299 duplicate = [x for i, x in enumerate(dvc_list) if i != dvc_list.index(x)]
300 if duplicate:
301 module.exit_json(msg=DEVICE_REPEATED.format((';'.join(set(duplicate)))), failed=True)
302 resp = rest_obj.get_all_items_with_pagination(DEVICE_URI)
303 devices = resp.get('value')
304 all_dvcs = {}
305 invalid_slots = set()
306 ident_map, name_map = {}, {}
307 for dvc in devices:
308 if not ids and not tags:
309 break
310 id = str(dvc.get('Id'))
311 tag = dvc.get('Identifier')
312 slot_cfg = dvc.get('SlotConfiguration')
313 all_dvcs[tag] = slot_cfg
314 if id in ids:
315 if not slot_cfg or not slot_cfg.get("SlotNumber"):
316 invalid_slots.add(id)
317 else:
318 ident_map[id] = tag
319 name_map[id] = slot_cfg['SlotName']
320 slot_cfg['new_name'] = ids[id]
321 slot_cfg['DeviceServiceTag'] = tag
322 slot_cfg['DeviceId'] = id
323 if tag in tags:
324 if not slot_cfg or not slot_cfg.get("SlotNumber"):
325 invalid_slots.add(tag)
326 else:
327 ident_map[tag] = tag
328 name_map[tag] = slot_cfg['SlotName']
329 slot_cfg['new_name'] = tags[tag]
330 slot_cfg['DeviceServiceTag'] = tag
331 slot_cfg['DeviceId'] = id
332 idf_list = list(ident_map.values())
333 duplicate = [x for i, x in enumerate(idf_list) if i != idf_list.index(x)]
334 if duplicate:
335 module.exit_json(msg=DEVICE_REPEATED.format((';'.join(set(duplicate)))), failed=True)
336 invalid_slots.update(set(ids.keys()) - set(ident_map.keys()))
337 invalid_slots.update(set(tags.keys()) - set(ident_map.keys()))
338 if invalid_slots:
339 module.exit_json(msg=INVALID_SLOT_DEVICE.format(';'.join(invalid_slots)), failed=True)
340 slot_dict_diff = {}
341 id_diff = recursive_diff(ids, name_map)
342 if id_diff and id_diff[0]:
343 diff = dict([(int(k), all_dvcs[ident_map[k]]) for k, v in (id_diff[0]).items()])
344 slot_dict_diff.update(diff)
345 tag_diff = recursive_diff(tags, name_map)
346 if tag_diff and tag_diff[0]:
347 diff = dict([(ident_map[k], all_dvcs[k]) for k, v in (tag_diff[0]).items()])
348 slot_dict_diff.update(diff)
349 if not slot_dict_diff:
350 module.exit_json(msg=NO_CHANGES_MSG)
351 if module.check_mode:
352 module.exit_json(msg=CHANGES_FOUND, changed=True)
353 return slot_dict_diff
354
355
356 def start_slot_name_jobs(rest_obj, slot_data):
357 slot_type = {'2000': "Sled Slot", '4000': "IO Module Slot", '2100': "Storage Sled"}
358 failed_jobs = {}
359 job_description = SLOT_JOB_DESC
360 job_type = {"Id": 3, "Name": "DeviceAction_Task"}
361 for k, slot in slot_data.items():
362 job_params, target_param = [{"Key": "operationName", "Value": "UPDATE_SLOT_DATA"}], []
363 num = slot.get('SlotNumber')
364 type_id = str(slot.get('SlotType'))
365 job_name = "Rename {0} {1}".format(slot_type.get(type_id, 'Slot'), num)
366 target_param.append({"Id": int(slot.get('ChassisId')), "Data": "",
367 "TargetType": {"Id": 1000, "Name": "DEVICE"}})
368 slot_config = "{0}|{1}|{2}".format(num, type_id, slot.get('new_name'))
369 job_params.append({'Key': 'slotConfig', 'Value': slot_config})
370 try:
371 job_resp = rest_obj.job_submission(job_name, job_description, target_param,
372 job_params, job_type)
373 slot['JobId'] = job_resp.json_data.get('Id', 0)
374 time.sleep(SETTLING_TIME)
375 except HTTPError as err:
376 slot['JobId'] = 0
377 slot['JobStatus'] = str(err)
378 failed_jobs[k] = slot
379 [slot_data.pop(key) for key in failed_jobs.keys()]
380 return failed_jobs
381
382
383 def get_job_states(module, rest_obj, slot_data):
384 job_dict = dict([(slot['JobId'], k) for k, slot in slot_data.items() if slot['JobId']])
385 query_params = {"$filter": "JobType/Id eq 3"} # optimize this
386 count = JOB_TIMEOUT // SETTLING_TIME
387 job_incomplete = [2050, 2030, 2040, 2080] # Running, Queued, Starting, New
388 while count > 0 and job_dict:
389 try:
390 job_resp = rest_obj.invoke_request("GET", JOB_URI, query_param=query_params)
391 jobs = job_resp.json_data.get('value')
392 except HTTPError:
393 count = count - 50 # 3 times retry for HTTP error
394 time.sleep(SETTLING_TIME)
395 continue
396 job_over = []
397 for job in jobs:
398 id = job.get('Id')
399 if id in job_dict:
400 lrs = job.get('LastRunStatus')
401 slot = slot_data[job_dict[id]]
402 if lrs.get('Id') in job_incomplete: # Running, not failed, not completed state
403 job_over.append(False)
404 elif lrs.get('Id') == 2060:
405 job_over.append(True)
406 slot['SlotName'] = slot.pop('new_name')
407 job_dict.pop(id)
408 else:
409 slot['JobStatus'] = lrs.get('Name')
410 job_over.append(True) # Failed states - job not running
411 if all(job_over) or not job_dict:
412 break
413 count = count - 1
414 time.sleep(SETTLING_TIME)
415 failed_jobs = dict([(k, slot_data.pop(k)) for k in job_dict.values()])
416 return failed_jobs
417
418
419 def trigger_refresh_inventory(rest_obj, slot_data):
420 chassis_dict = dict([(slot['ChassisId'], slot['ChassisServiceTag']) for slot in slot_data.values()])
421 jobs = []
422 for chassis in chassis_dict:
423 job_type = {"Id": 8, "Name": "Inventory_Task"}
424 job_name = "Refresh Inventory Chassis {0}".format(chassis_dict[chassis])
425 job_description = REFRESH_JOB_DESC
426 target_param = [{"Id": int(chassis), "Data": "''", "TargetType": {"Id": 1000, "Name": "DEVICE"}}]
427 job_params = [{"Key": "operationName", "Value": "EC_SLOT_DEVICE_INVENTORY_REFRESH"}]
428 job_resp = rest_obj.job_submission(job_name, job_description, target_param, job_params, job_type)
429 job_id = job_resp.json_data.get('Id')
430 jobs.append(int(job_id))
431 time.sleep(SETTLING_TIME)
432 return jobs
433
434
435 def trigger_all_inventory_task(rest_obj):
436 job_type = {"Id": 8, "Name": "Inventory_Task"}
437 job_name = "Refresh Inventory All Devices"
438 job_description = REFRESH_JOB_DESC
439 target_param = [{"Id": 500, "Data": "All-Devices", "TargetType": {"Id": 6000, "Name": "GROUP"}}]
440 job_params = [{"Key": "defaultInventoryTask", "Value": "TRUE"}]
441 job_resp = rest_obj.job_submission(job_name, job_description, target_param, job_params, job_type)
442 job_id = job_resp.json_data.get('Id')
443 return job_id
444
445
446 def get_formatted_slotlist(slot_dict):
447 slot_list = list(slot_dict.values())
448 req_tup = ('slot', 'job', 'chassis', 'device')
449 for slot in slot_list:
450 cp = slot.copy()
451 klist = cp.keys()
452 for k in klist:
453 if not str(k).lower().startswith(req_tup):
454 slot.pop(k)
455 return slot_list
456
457
458 def exit_slot_config(module, rest_obj, failed_jobs, invalid_jobs, slot_data):
459 failed_jobs.update(invalid_jobs)
460 if failed_jobs:
461 f = len(failed_jobs)
462 s = len(slot_data)
463 slot_info = get_formatted_slotlist(slot_data)
464 failed_jobs_list = get_formatted_slotlist(failed_jobs)
465 module.exit_json(msg=FAILED_MSG.format(f, s + f),
466 slot_info=slot_info, rename_failed_slots=failed_jobs_list, failed=True)
467 if slot_data:
468 job_failed_list = []
469 try:
470 rfrsh_job_list = trigger_refresh_inventory(rest_obj, slot_data)
471 for job in rfrsh_job_list:
472 job_failed, job_message = rest_obj.job_tracking(
473 job, job_wait_sec=JOB_TIMEOUT, sleep_time=JOB_INTERVAL)
474 job_failed_list.append(job_failed)
475 all_dv_rfrsh = trigger_all_inventory_task(rest_obj)
476 job_failed, job_message = rest_obj.job_tracking(
477 all_dv_rfrsh, job_wait_sec=JOB_TIMEOUT, sleep_time=JOB_INTERVAL)
478 job_failed_list.append(job_failed)
479 except Exception: # Refresh is secondary task hence not failing module
480 job_failed_list = [True]
481 if any(job_failed_list) is True:
482 slot_info = get_formatted_slotlist(slot_data)
483 failed_jobs_list = get_formatted_slotlist(failed_jobs)
484 module.exit_json(changed=True, msg=SUCCESS_REFRESH_MSG, slot_info=slot_info,
485 rename_failed_slots=failed_jobs_list)
486 slot_info = get_formatted_slotlist(slot_data)
487 module.exit_json(changed=True, msg=SUCCESS_MSG, slot_info=slot_info,
488 rename_failed_slots=list(failed_jobs.values()))
489
490
491 def get_device_type(rest_obj, type):
492 filter = {"$filter": "Type eq {0}".format(str(type))}
493 resp = rest_obj.invoke_request("GET", DEVICE_URI, query_param=filter)
494 return resp.json_data
495
496
497 def get_slot_data(module, rest_obj, ch_slots, chass_id):
498 uri = DEVICE_URI + "({0})/DeviceBladeSlots".format(chass_id)
499 chsvc_tag = ch_slots.get('chassis_service_tag')
500 resp = rest_obj.invoke_request("GET", uri)
501 blade_slots = resp.json_data.get('value')
502 if len(blade_slots) < 8:
503 # Storage type 3000
504 resp = get_device_type(rest_obj, 3000)
505 storage = resp.get('value')
506 for stx in storage:
507 if stx.get('ChassisServiceTag') == chsvc_tag:
508 blade_slots.append(stx.get('SlotConfiguration'))
509 blade_dict = {}
510 for slot in blade_slots:
511 slot["ChassisId"] = chass_id
512 slot["ChassisServiceTag"] = chsvc_tag
513 if slot.get('Id'):
514 slot["SlotId"] = str(slot.get('Id'))
515 blade_dict[slot['SlotNumber']] = slot
516 rest_obj.strip_substr_dict(slot)
517 inp_slots = ch_slots.get('slots')
518 existing_dict = dict([(slot['SlotNumber'], slot['SlotName']) for slot in blade_slots])
519 input_dict = dict([(str(slot['slot_number']), slot['slot_name']) for slot in inp_slots])
520 invalid_slot_number = set(input_dict.keys()) - set(existing_dict.keys())
521 if invalid_slot_number:
522 module.exit_json(msg=INVALID_SLOT_NUMBERS.format(';'.join(invalid_slot_number)), failed=True)
523 if len(input_dict) < len(inp_slots):
524 module.exit_json(msg=SLOT_NUM_DUP.format(chsvc_tag), failed=True)
525 slot_dict_diff = {}
526 slot_diff = recursive_diff(input_dict, existing_dict)
527 if slot_diff and slot_diff[0]:
528 diff = {}
529 for k, v in (slot_diff[0]).items():
530 blade_dict[k]['new_name'] = input_dict.get(k)
531 diff["{0}_{1}".format(chsvc_tag, k)] = blade_dict[k]
532 slot_dict_diff.update(diff)
533 return slot_dict_diff
534
535
536 def slot_number_config(module, rest_obj):
537 chslots = module.params.get("slot_options")
538 resp = get_device_type(rest_obj, 2000)
539 chassi_dict = dict([(chx['Identifier'], chx['Id']) for chx in resp.get('value')])
540 slot_data = {}
541 input_chassi_list = list(chx.get('chassis_service_tag') for chx in chslots)
542 duplicate = [x for i, x in enumerate(input_chassi_list) if i != input_chassi_list.index(x)]
543 if duplicate:
544 module.exit_json(msg=CHASSIS_REPEATED.format((';'.join(set(duplicate)))), failed=True)
545 for chx in chslots:
546 chsvc_tag = chx.get('chassis_service_tag')
547 if chsvc_tag not in chassi_dict.keys():
548 module.exit_json(msg=CHASSIS_TAG_INVALID.format(chsvc_tag), failed=True)
549 slot_dict = get_slot_data(module, rest_obj, chx, chassi_dict[chsvc_tag])
550 slot_data.update(slot_dict)
551 if not slot_data:
552 module.exit_json(msg=NO_CHANGES_MSG)
553 if module.check_mode:
554 module.exit_json(msg=CHANGES_FOUND, changed=True)
555 return slot_data
556
557
558 def main():
559 specs = {
560 "device_options": {"type": 'list', "elements": 'dict',
561 "options": {
562 "slot_name": {"required": True, 'type': 'str'},
563 "device_id": {"type": 'int'},
564 "device_service_tag": {"type": 'str'}
565 },
566 "mutually_exclusive": [('device_id', 'device_service_tag')],
567 "required_one_of": [('device_id', 'device_service_tag')]
568 },
569 "slot_options": {"type": 'list', "elements": 'dict',
570 "options": {
571 "chassis_service_tag": {"required": True, 'type': 'str'},
572 "slots": {"required": True, "type": 'list', "elements": 'dict',
573 "options": {
574 "slot_number": {"required": True, 'type': 'int'},
575 "slot_name": {"required": True, "type": 'str'}
576 },
577 },
578 },
579 },
580 }
581
582 module = OmeAnsibleModule(
583 argument_spec=specs,
584 required_one_of=[('slot_options', 'device_options')],
585 mutually_exclusive=[('slot_options', 'device_options')],
586 supports_check_mode=True
587 )
588
589 try:
590 with RestOME(module.params, req_session=True) as rest_obj:
591 if module.params.get("slot_options"):
592 slot_data = slot_number_config(module, rest_obj)
593 else:
594 slot_data = get_device_slot_config(module, rest_obj)
595 invalid_jobs = start_slot_name_jobs(rest_obj, slot_data)
596 failed_jobs = {}
597 if slot_data:
598 failed_jobs = get_job_states(module, rest_obj, slot_data)
599 else:
600 module.exit_json(msg=JOBS_TRIG_FAIL, rename_failed_slots=list(invalid_jobs.values()), failed=True)
601 exit_slot_config(module, rest_obj, failed_jobs, invalid_jobs, slot_data)
602 except HTTPError as err:
603 module.exit_json(msg=str(err), error_info=json.load(err), failed=True)
604 except URLError as err:
605 module.exit_json(msg=str(err), unreachable=True)
606 except (IOError, ValueError, SSLError, TypeError, ConnectionError, AttributeError, IndexError, KeyError, OSError) as err:
607 module.exit_json(msg=str(err), failed=True)
608
609
610 if __name__ == '__main__':
611 main()