Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.8.0
7 # Copyright (C) 2024-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
14 __metaclass__ = type
15
16 DOCUMENTATION = r"""
17 ---
18 module: omevv_firmware_repository_profile_info
19 short_description: Retrieve OMEVV firmware repository profile information.
20 version_added: "9.8.0"
21 description:
22 - This module allows you to retrieve the OMEVV firmware repository profile information.
23 extends_documentation_fragment:
24 - dellemc.openmanage.omevv_auth_options
25 options:
26 name:
27 description:
28 - Name of the OMEVV firmware repository profile.
29 - If I(name) is provided, the module retrieves only specified firmware repository profile information.
30 type: str
31 requirements:
32 - "python >= 3.9.6"
33 author:
34 - "Lovepreet Singh (@singh-lovepreet1)"
35 attributes:
36 check_mode:
37 description: Runs task to validate without performing action on the target machine.
38 support: full
39 notes:
40 - This module supports IPv4 and IPv6 addresses.
41 """
42
43
44 EXAMPLES = r"""
45 ---
46 - name: Retrieve all firmware repository profile information.
47 dellemc.openmanage.omevv_firmware_repository_profile_info:
48 hostname: "192.168.0.1"
49 vcenter_uuid: "xxxxxx"
50 vcenter_username: "username"
51 vcenter_password: "password"
52 ca_path: "path/to/ca_file"
53
54 - name: Retrieve specific firmware repository profile information using profile name.
55 dellemc.openmanage.omevv_firmware_repository_profile_info:
56 hostname: "192.168.0.1"
57 vcenter_uuid: "xxxxxx"
58 vcenter_username: "username"
59 vcenter_password: "password"
60 ca_path: "path/to/ca_file"
61 name: profile-1
62 """
63
64 RETURN = r"""
65 ---
66 msg:
67 description: Status of the firmare repository profile information for the retrieve operation.
68 returned: always
69 type: str
70 sample: "Successfully retrieved the firmware repository profile information."
71 profile_info:
72 description: Information on the vCenter.
73 returned: success
74 type: list
75 elements: dict
76 sample:
77 [
78 {
79 "id": 1000,
80 "profileName": "Dell Default Catalog",
81 "description": "Latest Firmware From Dell",
82 "profileType": "Firmware",
83 "sharePath": "https://downloads.dell.com//catalog/catalog.xml.gz",
84 "fileName": "catalog.xml",
85 "status": "Success",
86 "factoryCreated": true,
87 "factoryType": "Default",
88 "catalogCreatedDate": "2024-08-27T01:58:10Z",
89 "catalogLastChecked": "2024-09-09T19:30:16Z",
90 "checkCertificate": null,
91 "protocolType": "HTTPS",
92 "createdBy": "OMEVV Default",
93 "modifiedBy": null,
94 "owner": "OMEVV"
95 },
96 {
97 "id": 1001,
98 "profileName": "Dell Default Catalog",
99 "description": "Latest Firmware From Dell",
100 "profileType": "Firmware",
101 "sharePath": "https://downloads.dell.com//catalog/catalog.xml.gz",
102 "fileName": "catalog.xml",
103 "status": "Success",
104 "factoryCreated": true,
105 "factoryType": "Default",
106 "catalogCreatedDate": "2024-08-27T01:58:10Z",
107 "catalogLastChecked": "2024-09-09T19:30:16Z",
108 "checkCertificate": null,
109 "protocolType": "HTTPS",
110 "createdBy": "OMEVV Default",
111 "modifiedBy": null,
112 "owner": "OMEVV"
113 }
114 ]
115 error_info:
116 description: Details of the HTTP Error.
117 returned: on HTTP error
118 type: dict
119 sample: {
120 "error": {
121 "code": "Base.1.0.GeneralError",
122 "message": "A general error has occurred. See ExtendedInfo for more information.",
123 "@Message.ExtendedInfo": [
124 {
125 "MessageId": "GEN1234",
126 "RelatedProperties": [],
127 "Message": "Unable to process the request because an error occurred.",
128 "MessageArgs": [],
129 "Severity": "Critical",
130 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
131 }
132 ]
133 }
134 }
135 """
136
137 import json
138 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
139 from ansible.module_utils.urls import ConnectionError, SSLValidationError
140 from ansible_collections.dellemc.openmanage.plugins.module_utils.omevv import RestOMEVV, OMEVVAnsibleModule
141 from ansible_collections.dellemc.openmanage.plugins.module_utils.omevv_utils.omevv_firmware_utils import OMEVVFirmwareProfile
142
143 SUCCESS_MSG = "Successfully retrieved the firmware repository profile information."
144 NO_PROFILE_MSG = "'{profile_name}' firmware repository profile name does not exist in OMEVV."
145 ERROR_CODES = ["12027"]
146
147
148 class OmevvFirmwareProfileInfo:
149
150 def __init__(self, module, rest_obj) -> None:
151 """
152 Initializes a new instance of the class.
153 Args:
154 module (object): The module object.
155 rest_obj (object): The REST object.
156 Returns:
157 None
158 """
159 self.module = module
160 self.obj = rest_obj
161
162 def perform_module_operation(self) -> dict:
163 """
164 Retrieves the firmware repository profile information.
165 Returns:
166 dict: A dictionary containing the message and the firmware repository profile information.
167 - msg (str): The success message or the error message.
168 - profile_info (list): The list of firmware repository profile information.
169 """
170 profile_name = self.module.params.get("name")
171 self.omevv_utils_obj = OMEVVFirmwareProfile(self.obj)
172 resp = self.omevv_utils_obj.get_firmware_repository_profile(profile_name)
173 result = {'msg': SUCCESS_MSG, 'profile_info': resp}
174 if profile_name and not resp:
175 result['msg'] = NO_PROFILE_MSG.format(profile_name=profile_name)
176 return result
177
178
179 def main():
180 """
181 Retrieves the firmware repository profile information.
182
183 Returns:
184 dict: A dictionary containing the message and the firmware repository profile information.
185 - msg (str): The success message or the error message.
186 - profile_info (list): The list of firmware repository profile information.
187
188 Error Codes:
189 - 12027: The specified vCenter UUID is not registered in OME.
190 """
191 argument_spec = {
192 "name": {"type": 'str'}
193 }
194 module = OMEVVAnsibleModule(argument_spec=argument_spec,
195 supports_check_mode=True)
196 try:
197 with RestOMEVV(module.params) as rest_obj:
198 omevv_obj = OmevvFirmwareProfileInfo(module, rest_obj)
199 resp = omevv_obj.perform_module_operation()
200 module.exit_json(msg=resp['msg'], profile_info=resp['profile_info'])
201 except HTTPError as err:
202 error_info = json.load(err)
203 code = error_info.get('errorCode')
204 message = error_info.get('message')
205 if code in ERROR_CODES:
206 module.exit_json(msg=message, skipped=True)
207 module.exit_json(msg=str(err), error_info=error_info, failed=True)
208 except URLError as err:
209 module.exit_json(msg=str(err), unreachable=True)
210 except (IOError, ValueError, SSLValidationError, TypeError, ConnectionError,
211 AttributeError, IndexError, KeyError, OSError) as err:
212 module.exit_json(msg=str(err), failed=True)
213
214
215 if __name__ == '__main__':
216 main()