Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.12.3
7 # Copyright (C) 2019-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 = r'''
18 ---
19 module: ome_firmware_catalog
20 short_description: Create, modify, or delete a firmware catalog on OpenManage Enterprise or OpenManage Enterprise Modular
21 version_added: "2.0.0"
22 description: This module allows to create, modify, or delete a firmware catalog on OpenManage Enterprise or OpenManage Enterprise Modular.
23 extends_documentation_fragment:
24 - dellemc.openmanage.ome_auth_options
25 options:
26 state:
27 description:
28 - C(present) creates or modifies a catalog.
29 - C(absent) deletes an existing catalog.
30 choices: [present, absent]
31 default: present
32 type: str
33 version_added: 3.4.0
34 catalog_name:
35 type: list
36 elements: str
37 description:
38 - Name of the firmware catalog to be created.
39 - This option is mutually exclusive with I(catalog_id).
40 - Provide the list of firmware catalog names that are supported when I(state) is C(absent).
41 new_catalog_name:
42 type: str
43 description:
44 - New name of the firmware catalog.
45 version_added: 3.4.0
46 catalog_id:
47 type: list
48 elements: int
49 description:
50 - ID of the catalog.
51 - This option is mutually exclusive with I(catalog_name).
52 - Provide the list of firmware catalog IDs that are supported when I(state) is C(absent).
53 version_added: 3.4.0
54 catalog_description:
55 type: str
56 description:
57 - Description for the catalog.
58 source:
59 type: str
60 description:
61 - The IP address of the system where the firmware catalog is stored on the local network.
62 - By default, this option is set to downloads.dell.com when I(repository_type) is C(DELL_ONLINE).
63 source_path:
64 type: str
65 description:
66 - Specify the complete path of the catalog file location without the file name.
67 - This is option ignored when I(repository_type) is C(DELL_ONLINE).
68 file_name:
69 type: str
70 description:
71 - Catalog file name associated with the I(source_path).
72 - This option is ignored when I(repository_type) is C(DELL_ONLINE).
73 repository_type:
74 type: str
75 description:
76 - Type of repository. The supported types are NFS, CIFS, HTTP, HTTPS,and DELL_ONLINE.
77 choices: ["NFS", "CIFS", "HTTP", "HTTPS", "DELL_ONLINE"]
78 repository_username:
79 type: str
80 description:
81 - User name of the repository where the catalog is stored.
82 - This option is mandatory when I(repository_type) is CIFS.
83 - This option is ignored when I(repository_type) is C(DELL_ONLINE).
84 repository_password:
85 type: str
86 description:
87 - Password to access the repository.
88 - This option is mandatory when I(repository_type) is CIFS.
89 - This option is ignored when I(repository_type) is C(DELL_ONLINE).
90 - C(NOTE) The module always reports the changed status, when this is provided.
91 repository_domain:
92 type: str
93 description:
94 - Domain name of the repository.
95 - This option is ignored when I(repository_type) is C(DELL_ONLINE).
96 check_certificate:
97 type: bool
98 description:
99 - The certificate warnings are ignored when I(repository_type) is HTTPS. If C(true). If not, certificate warnings
100 are not ignored.
101 default: false
102 job_wait:
103 description:
104 - Provides the option to wait for job completion.
105 - This option is applicable when I(state) is C(present).
106 type: bool
107 default: true
108 version_added: 3.4.0
109 job_wait_timeout:
110 description:
111 - The maximum wait time of I(job_wait) in seconds. The job is tracked only for this duration.
112 - This option is applicable when I(job_wait) is C(true).
113 type: int
114 default: 600
115 version_added: 3.4.0
116 requirements:
117 - "python >= 3.9.6"
118 author:
119 - "Sajna Shetty(@Sajna-Shetty)"
120 - "Jagadeesh N V(@jagadeeshnv)"
121 - "Krunal Thakkar(@Krunal-Thakkar)"
122 notes:
123 - If I(repository_password) is provided, then the module always reports the changed status.
124 - Run this module from a system that has direct access to Dell OpenManage Enterprise or OpenManage Enterprise Modular.
125 - This module supports IPv4 and IPv6 addresses.
126 - This module supports C(check_mode).
127 '''
128
129 EXAMPLES = r'''
130 ---
131 - name: Create a catalog from HTTPS repository
132 dellemc.openmanage.ome_firmware_catalog:
133 hostname: "192.168.0.1"
134 username: "username"
135 password: "password"
136 ca_path: "/path/to/ca_cert.pem"
137 catalog_name: "catalog_name"
138 catalog_description: "catalog_description"
139 repository_type: "HTTPS"
140 source: "downloads.dell.com"
141 source_path: "catalog"
142 file_name: "catalog.gz"
143 check_certificate: true
144
145 - name: Create a catalog from HTTP repository
146 dellemc.openmanage.ome_firmware_catalog:
147 hostname: "192.168.0.1"
148 username: "username"
149 password: "password"
150 ca_path: "/path/to/ca_cert.pem"
151 catalog_name: "catalog_name"
152 catalog_description: "catalog_description"
153 repository_type: "HTTP"
154 source: "downloads.dell.com"
155 source_path: "catalog"
156 file_name: "catalog.gz"
157
158 - name: Create a catalog using CIFS share
159 dellemc.openmanage.ome_firmware_catalog:
160 hostname: "192.168.0.1"
161 username: "username"
162 password: "password"
163 ca_path: "/path/to/ca_cert.pem"
164 catalog_name: "catalog_name"
165 catalog_description: "catalog_description"
166 repository_type: "CIFS"
167 source: "192.167.0.1"
168 source_path: "cifs/R940"
169 file_name: "catalog.gz"
170 repository_username: "repository_username"
171 repository_password: "repository_password"
172 repository_domain: "repository_domain"
173
174 - name: Create a catalog using NFS share
175 dellemc.openmanage.ome_firmware_catalog:
176 hostname: "192.168.0.1"
177 username: "username"
178 password: "password"
179 ca_path: "/path/to/ca_cert.pem"
180 catalog_name: "catalog_name"
181 catalog_description: "catalog_description"
182 repository_type: "NFS"
183 source: "192.166.0.2"
184 source_path: "/nfs/R940"
185 file_name: "catalog.xml"
186
187 - name: Create a catalog using repository from Dell.com
188 dellemc.openmanage.ome_firmware_catalog:
189 hostname: "192.168.0.1"
190 username: "username"
191 password: "password"
192 ca_path: "/path/to/ca_cert.pem"
193 catalog_name: "catalog_name"
194 catalog_description: "catalog_description"
195 repository_type: "DELL_ONLINE"
196 check_certificate: true
197
198 - name: Modify a catalog using a repository from CIFS share
199 dellemc.openmanage.ome_firmware_catalog:
200 hostname: "192.168.0.1"
201 username: "username"
202 password: "password"
203 ca_path: "/path/to/ca_cert.pem"
204 catalog_name: "catalog_name"
205 catalog_description: "new catalog_description"
206 repository_type: "CIFS"
207 source: "192.167.0.2"
208 source_path: "cifs/R941"
209 file_name: "catalog1.gz"
210 repository_username: "repository_username"
211 repository_password: "repository_password"
212 repository_domain: "repository_domain"
213
214 - name: Modify a catalog using a repository from Dell.com
215 dellemc.openmanage.ome_firmware_catalog:
216 hostname: "192.168.0.1"
217 username: "username"
218 password: "password"
219 ca_path: "/path/to/ca_cert.pem"
220 catalog_id: 10
221 new_catalog_name: "new_catalog_name"
222 repository_type: "DELL_ONLINE"
223 catalog_description: "catalog_description"
224
225 - name: Delete catalog using catalog name
226 dellemc.openmanage.ome_firmware_catalog:
227 hostname: "192.168.0.1"
228 username: "username"
229 password: "password"
230 ca_path: "/path/to/ca_cert.pem"
231 state: absent
232 catalog_name: ["catalog_name1", "catalog_name2"]
233
234 - name: Delete catalog using catalog id
235 dellemc.openmanage.ome_firmware_catalog:
236 hostname: "192.168.0.1"
237 username: "username"
238 password: "password"
239 ca_path: "/path/to/ca_cert.pem"
240 state: absent
241 catalog_id: [11, 34]
242 '''
243
244 RETURN = r'''
245 ---
246 msg:
247 description: Overall status of the firmware catalog operation.
248 returned: always
249 type: str
250 sample: "Successfully triggered the job to create a catalog with Task ID : 10094"
251 catalog_status:
252 description: Details of the catalog operation.
253 returned: When I(state) is C(present)
254 type: dict
255 sample: {
256 "AssociatedBaselines": [],
257 "BaseLocation": null,
258 "BundlesCount": 0,
259 "Filename": "catalog.gz",
260 "Id": 12,
261 "LastUpdated": null,
262 "ManifestIdentifier": null,
263 "ManifestVersion": null,
264 "NextUpdate": null,
265 "PredecessorIdentifier": null,
266 "ReleaseDate": null,
267 "ReleaseIdentifier": null,
268 "Repository": {
269 "CheckCertificate": true,
270 "Description": "HTTPS Desc",
271 "DomainName": null,
272 "Id": null,
273 "Name": "catalog4",
274 "Password": null,
275 "RepositoryType": "HTTPS",
276 "Source": "company.com",
277 "Username": null
278 },
279 "Schedule": null,
280 "SourcePath": "catalog",
281 "Status": null,
282 "TaskId": 10094
283 }
284 job_id:
285 description: Job ID of the catalog task.
286 returned: When catalog job is in a running state
287 type: int
288 sample: 10123
289 catalog_id:
290 description: IDs of the deleted catalog.
291 returned: When I(state) is C(absent)
292 type: int
293 sample: 10123
294 associated_baselines:
295 description: IDs of the baselines associated with catalog.
296 returned: When I(state) is C(absent)
297 type: list
298 elements: dict
299 sample: [
300 {
301 "BaselineId": 24,
302 "BaselineName": "new"
303 },
304 {
305 "BaselineId": 25,
306 "BaselineName": "c7"
307 },
308 {
309 "BaselineId": 27,
310 "BaselineName": "c4"
311 }
312 ]
313 error_info:
314 type: dict
315 description: Details of the http error.
316 returned: on http error
317 sample: {
318 "error": {
319 "@Message.ExtendedInfo": [
320 {
321 "Message": "Unable to create or update the catalog because a
322 repository with the same name already exists.",
323 "Resolution": "Enter a different name and retry the operation.",
324 "Severity": "Critical"
325 }
326 ],
327 "code": "Base.1.0.GeneralError",
328 "message": "A general error has occurred. See ExtendedInfo for more information."
329 }
330 }
331
332 '''
333
334 JOB_URI = "JobService/Jobs({TaskId})"
335 BASELINE_URI = "UpdateService/Baselines"
336 CATALOG_URI = "UpdateService/Catalogs"
337 CATALOG_URI_ID = "UpdateService/Catalogs({Id})"
338 DELETE_CATALOG_URI = "UpdateService/Actions/UpdateService.RemoveCatalogs"
339 CATALOG_JOB_RUNNING = "Catalog job '{name}' with ID {id} is running.Retry after job completion."
340 CHECK_MODE_CHANGE_FOUND_MSG = "Changes found to be applied."
341 CHECK_MODE_CHANGE_NOT_FOUND_MSG = "No changes found to be applied."
342 INVALID_CATALOG_ID = "Invalid catalog ID provided."
343 CATALOG_DEL_SUCCESS = "Successfully deleted the firmware catalog(s)."
344 CATALOG_BASELINE_ATTACHED = "Unable to delete the catalog as it is with baseline(s)."
345 CATALOG_EXISTS = "The catalog with the name '{new_name}' already exists in the system."
346 DELL_ONLINE_EXISTS = "Catalog with 'DELL_ONLINE' repository already exists with the name '{catalog_name}'."
347 NAMES_ERROR = "Only delete operations accept multiple catalog names or IDs."
348 CATALOG_ID_NOT_FOUND = "Catalog with ID '{catalog_id}' not found."
349 CATALOG_NAME_NOT_FOUND = "Catalog '{catalog_name}' not found."
350 CATALOG_UPDATED = "Successfully {operation} the firmware catalog."
351 JOB_POLL_INTERVAL = 10
352 SETTLING_TIME = 3
353
354 import json
355 import time
356 import os
357 from ssl import SSLError
358 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
359 from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import remove_key
360 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
361 from ansible.module_utils.urls import ConnectionError, SSLValidationError
362
363
364 def check_existing_catalog(module, rest_obj, state, name=None):
365 catalog_cfgs = []
366 if name:
367 catalog_id = None
368 catalog_name = [name]
369 else:
370 catalog_id = module.params.get("catalog_id")
371 catalog_name = module.params.get("catalog_name")
372 resp = rest_obj.get_all_items_with_pagination(CATALOG_URI)
373 catalogs_detail = resp.get("value")
374 all_catalog = {}
375 if state == "present":
376 all_catalog = dict(
377 [(each_catalog["Repository"]["Name"], each_catalog["Repository"]["RepositoryType"]) for each_catalog in
378 catalogs_detail])
379 for each_catalog in catalogs_detail:
380 if catalog_name:
381 if each_catalog['Repository']['Name'] in catalog_name:
382 catalog_cfgs.append(each_catalog)
383 if state == "present":
384 break
385 continue
386 if catalog_id:
387 if each_catalog['Id'] in catalog_id:
388 catalog_cfgs.append(each_catalog)
389 if state == "present":
390 break
391 continue
392 return catalog_cfgs, all_catalog
393
394
395 def get_updated_catalog_info(module, rest_obj, catalog_resp):
396 try:
397 catalog, all_catalog = check_existing_catalog(module, rest_obj, "present", name=catalog_resp["Repository"]["Name"])
398 except Exception:
399 catalog = catalog_resp
400 return catalog[0]
401
402
403 def exit_catalog(module, rest_obj, catalog_resp, operation, msg):
404 if module.params.get("job_wait"):
405 job_failed, job_message = rest_obj.job_tracking(
406 catalog_resp.get('TaskId'), job_wait_sec=module.params["job_wait_timeout"], sleep_time=JOB_POLL_INTERVAL)
407 catalog = get_updated_catalog_info(module, rest_obj, catalog_resp)
408 if job_failed is True:
409 module.exit_json(msg=job_message, catalog_status=catalog, failed=True)
410 catalog_resp = catalog
411 msg = CATALOG_UPDATED.format(operation=operation)
412 time.sleep(SETTLING_TIME)
413 catalog = get_updated_catalog_info(module, rest_obj, catalog_resp)
414 module.exit_json(msg=msg, catalog_status=remove_key(catalog), changed=True)
415
416
417 def _get_catalog_payload(params, name):
418 catalog_payload = {}
419 repository_type = params.get("repository_type")
420 if params.get("file_name") is not None:
421 catalog_payload["Filename"] = params["file_name"]
422 if params.get("source_path") is not None:
423 catalog_payload["SourcePath"] = params["source_path"]
424 repository_dict = {
425 "Name": name,
426 "Description": params.get("catalog_description"),
427 "RepositoryType": repository_type,
428 "Source": params.get("source"),
429 "CheckCertificate": params.get("check_certificate"),
430 }
431 if repository_type != "DELL_ONLINE":
432 repository_dict.update({"DomainName": params.get("repository_domain"),
433 "Username": params.get("repository_username"),
434 "Password": params.get("repository_password")
435 })
436 if repository_type == "DELL_ONLINE" and not params.get("source"):
437 repository_dict["Source"] = "downloads.dell.com"
438 repository_payload = dict([(k, v) for k, v in repository_dict.items() if v is not None])
439 if repository_payload:
440 catalog_payload["Repository"] = repository_payload
441 return catalog_payload
442
443
444 def validate_dell_online(all_catalog, module):
445 """
446 only one dell_online repository type catalog creation is possible from ome
447 """
448 catalog_name = module.params["catalog_name"][0]
449 for name, repo_type in all_catalog.items():
450 if repo_type == "DELL_ONLINE" and name != catalog_name:
451 module.exit_json(
452 msg=DELL_ONLINE_EXISTS.format(
453 catalog_name=name), failed=True)
454
455
456 def create_catalog(module, rest_obj):
457 if module.check_mode:
458 module.exit_json(msg=CHECK_MODE_CHANGE_FOUND_MSG, changed=True)
459 payload = _get_catalog_payload(module.params, module.params.get("catalog_name")[0])
460 resp = rest_obj.invoke_request("POST", CATALOG_URI, data=payload)
461 resp_data = resp.json_data
462 job_id = resp_data.get("TaskId")
463 msg = "Successfully triggered the job to create a catalog with Task Id : {0}".format(job_id)
464 exit_catalog(module, rest_obj, resp_data, "created", msg)
465
466
467 def get_current_catalog_settings(current_payload):
468 catalog_payload = {}
469 if current_payload.get("Filename") is not None:
470 catalog_payload["Filename"] = current_payload["Filename"]
471 if current_payload.get("SourcePath") is not None:
472 catalog_payload["SourcePath"] = current_payload["SourcePath"]
473 repository_dict = {
474 "Name": current_payload["Repository"].get("Name"),
475 "Id": current_payload["Repository"].get("Id"),
476 "Description": current_payload["Repository"].get("Description"),
477 "RepositoryType": current_payload["Repository"].get("RepositoryType"),
478 "Source": current_payload["Repository"].get("Source"),
479 "DomainName": current_payload["Repository"].get("DomainName"),
480 "Username": current_payload["Repository"].get("Username"),
481 "Password": current_payload["Repository"].get("Password"),
482 "CheckCertificate": current_payload["Repository"].get("CheckCertificate"),
483 }
484 repository_payload = dict([(k, v) for k, v in repository_dict.items() if v is not None])
485 if repository_payload:
486 catalog_payload["Repository"] = repository_payload
487 return catalog_payload
488
489
490 def compare_payloads(modify_payload, current_payload):
491 """
492 :param modify_payload: payload created to update existing setting
493 :param current_payload: already existing payload for specified baseline
494 :return: bool - compare existing and requested setting values of baseline in case of modify operations
495 if both are same return True
496 """
497 diff = False
498 for key, val in modify_payload.items():
499 if current_payload is None or current_payload.get(key) is None:
500 return True
501 elif isinstance(val, dict):
502 if compare_payloads(val, current_payload.get(key)):
503 return True
504 elif val != current_payload.get(key):
505 return True
506 return diff
507
508
509 def modify_catalog(module, rest_obj, catalog_list, all_catalog):
510 params = module.params
511 catalog_id = catalog_list[0]["Id"]
512 name = catalog_list[0]["Repository"]["Name"]
513 modify_payload = _get_catalog_payload(module.params, name)
514 new_catalog_name = params.get("new_catalog_name")
515 if new_catalog_name:
516 if new_catalog_name != name and new_catalog_name in all_catalog:
517 module.exit_json(msg=CATALOG_EXISTS.format(new_name=new_catalog_name), failed=True)
518 modify_payload["Repository"]["Name"] = new_catalog_name
519 catalog_payload = get_current_catalog_settings(catalog_list[0])
520 if modify_payload.get("Repository") and \
521 modify_payload.get("Repository").get("RepositoryType") and \
522 modify_payload.get("Repository").get("RepositoryType") != catalog_payload["Repository"]["RepositoryType"]:
523 module.exit_json(msg="Repository type cannot be changed to another repository type.", failed=True)
524 new_catalog_current_setting = catalog_payload.copy()
525 repo_id = new_catalog_current_setting["Repository"]["Id"]
526 del new_catalog_current_setting["Repository"]["Id"]
527 fname = modify_payload.get('Filename')
528 # Special case handling for .gz catalog files
529 if fname and fname.lower().endswith('.gz'):
530 modify_payload['Filename'] = new_catalog_current_setting.get('Filename')
531 src_path = modify_payload.get('SourcePath')
532 if src_path is None:
533 src_path = new_catalog_current_setting.get('SourcePath', "")
534 if src_path.lower().endswith('.gz'):
535 src_path = os.path.dirname(src_path)
536 modify_payload['SourcePath'] = os.path.join(src_path, fname)
537 diff = compare_payloads(modify_payload, new_catalog_current_setting)
538 if not diff:
539 module.exit_json(msg=CHECK_MODE_CHANGE_NOT_FOUND_MSG, changed=False)
540 if module.check_mode:
541 module.exit_json(msg=CHECK_MODE_CHANGE_FOUND_MSG, changed=True)
542 new_catalog_current_setting["Repository"].update(modify_payload["Repository"])
543 catalog_payload.update(modify_payload)
544 catalog_payload["Repository"] = new_catalog_current_setting["Repository"]
545 catalog_payload["Repository"]["Id"] = repo_id
546 catalog_payload["Id"] = catalog_id
547 catalog_put_uri = CATALOG_URI_ID.format(Id=catalog_id)
548 resp = rest_obj.invoke_request('PUT', catalog_put_uri, data=catalog_payload)
549 resp_data = resp.json_data
550 job_id = resp_data.get("TaskId")
551 msg = "Successfully triggered the job to update a catalog with Task Id : {0}".format(job_id)
552 exit_catalog(module, rest_obj, resp_data, "modified", msg)
553
554
555 def validate_delete_operation(rest_obj, module, catalog_list, delete_ids):
556 associated_baselines = []
557 for catalog in catalog_list:
558 if catalog.get('AssociatedBaselines'):
559 associated_baselines.append({"catalog_id": catalog["Id"],
560 "associated_baselines": catalog.get("AssociatedBaselines")})
561 if catalog.get('Status') != "Completed":
562 resp = rest_obj.invoke_request("GET", JOB_URI.format(TaskId=catalog['TaskId']))
563 job_data = resp.json_data
564 if job_data['LastRunStatus']['Id'] == 2050:
565 module.exit_json(msg=CATALOG_JOB_RUNNING.format(name=catalog["Name"], id=catalog["Id"]),
566 job_id=catalog['TaskId'], failed=True)
567 if associated_baselines:
568 module.exit_json(msg=CATALOG_BASELINE_ATTACHED, associated_baselines=associated_baselines, failed=True)
569 if module.check_mode and len(catalog_list) > 0:
570 module.exit_json(msg=CHECK_MODE_CHANGE_FOUND_MSG, changed=True, catalog_id=delete_ids)
571 if len(catalog_list) == 0:
572 module.exit_json(msg=CHECK_MODE_CHANGE_NOT_FOUND_MSG, changed=False)
573
574
575 def delete_catalog(module, rest_obj, catalog_list):
576 delete_ids = [d["Id"] for d in catalog_list]
577 validate_delete_operation(rest_obj, module, catalog_list, delete_ids)
578 delete_payload = {"CatalogIds": delete_ids}
579 rest_obj.invoke_request('POST', DELETE_CATALOG_URI, data=delete_payload)
580 module.exit_json(msg=CATALOG_DEL_SUCCESS, changed=True, catalog_id=delete_ids)
581
582
583 def validate_names(state, module):
584 """
585 The state present doest not supports more than one name/id
586 """
587 catalog_name = module.params.get("catalog_name", [])
588 catalog_id = module.params.get("catalog_id", [])
589 if state != "absent" and ((catalog_name and len(catalog_name) > 1) or (catalog_id and len(catalog_id) > 1)):
590 module.exit_json(msg=NAMES_ERROR, failed=True)
591
592
593 def perform_present_action(module, rest_obj, requested_catalog_list, all_catalog):
594 if requested_catalog_list:
595 modify_catalog(module, rest_obj, requested_catalog_list, all_catalog)
596 else:
597 if module.params.get('catalog_id'):
598 module.exit_json(msg=INVALID_CATALOG_ID, failed=True)
599 repository_type = module.params.get("repository_type")
600 if repository_type and repository_type == "DELL_ONLINE":
601 validate_dell_online(all_catalog, module)
602 create_catalog(module, rest_obj)
603
604
605 def main():
606 specs = {
607 "state": {"default": "present", "choices": ['present', 'absent']},
608 "catalog_name": {"type": 'list', "elements": 'str'},
609 "new_catalog_name": {"type": 'str'},
610 "catalog_id": {"type": 'list', "elements": 'int'},
611 "catalog_description": {"required": False, "type": 'str'},
612 "source": {"required": False, "type": 'str'},
613 "source_path": {"required": False, "type": 'str'},
614 "file_name": {"required": False, "type": 'str'},
615 "repository_type": {"required": False,
616 "choices": ["NFS", "CIFS", "HTTP", "HTTPS", "DELL_ONLINE"]},
617 "repository_username": {"required": False, "type": 'str'},
618 "repository_password": {"required": False, "type": 'str', "no_log": True},
619 "repository_domain": {"required": False, "type": 'str'},
620 "check_certificate": {"required": False, "type": 'bool', "default": False},
621 "job_wait": {"type": 'bool', "default": True},
622 "job_wait_timeout": {"type": 'int', "default": 600}
623 }
624
625 module = OmeAnsibleModule(
626 argument_spec=specs,
627 required_if=[
628 ['state', 'present',
629 ['repository_type'], False],
630 ['state', 'present',
631 ['new_catalog_name', 'catalog_description', 'catalog_name', 'catalog_id', 'source', 'source_path',
632 'file_name', 'repository_type', 'repository_username', 'repository_password',
633 'repository_domain', 'check_certificate'], True],
634 ],
635 mutually_exclusive=[('catalog_name', 'catalog_id')],
636 required_one_of=[('catalog_name', 'catalog_id')],
637 supports_check_mode=True)
638
639 try:
640 with RestOME(module.params, req_session=True) as rest_obj:
641 state = module.params['state']
642 validate_names(state, module)
643 requested_catalog_list, all_catalog = check_existing_catalog(module, rest_obj, state)
644 if state == 'absent':
645 delete_catalog(module, rest_obj, requested_catalog_list)
646 else:
647 perform_present_action(module, rest_obj, requested_catalog_list, all_catalog)
648 except HTTPError as err:
649 module.exit_json(msg=str(err), error_info=json.load(err), failed=True)
650 except URLError as err:
651 module.exit_json(msg=str(err), unreachable=True)
652 except (IOError, ValueError, TypeError, SSLError, ConnectionError, SSLValidationError, OSError) as err:
653 module.exit_json(msg=str(err), failed=True)
654
655
656 if __name__ == '__main__':
657 main()