Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.9.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 from __future__ import (absolute_import, division, print_function)
12
13 __metaclass__ = type
14
15 DOCUMENTATION = r"""
16 ---
17 module: omevv_baseline_profile_info
18 short_description: Retrieve OMEVV baseline profile information.
19 version_added: "9.9.0"
20 description:
21 - This module allows you to retrieve all or the specific OMEVV baseline profile information.
22 extends_documentation_fragment:
23 - dellemc.openmanage.omevv_auth_options
24 options:
25 name:
26 description:
27 - Name of the baseline profile.
28 - If I(name) is provided, the module retrieves only specified baseline profile information.
29 type: str
30 requirements:
31 - "python >= 3.9.6"
32 author:
33 - "Kritika Bhateja (@Kritika-Bhateja-03)"
34 attributes:
35 check_mode:
36 description: Runs task to validate without performing action on the target machine.
37 support: full
38 notes:
39 - Run this module from a system that has direct access to Dell OpenManage Enterprise.
40 """
41
42
43 EXAMPLES = r"""
44 ---
45 - name: Retrieve all baseline profile information.
46 dellemc.openmanage.omevv_baseline_profile_info:
47 hostname: "192.168.0.1"
48 vcenter_uuid: "xxxxxx"
49 vcenter_username: "username"
50 vcenter_password: "password"
51 ca_path: "path/to/ca_file"
52
53 - name: Retrieve specific baseline profile information using profile name.
54 dellemc.openmanage.omevv_baseline_profile_info:
55 hostname: "192.168.0.1"
56 vcenter_uuid: "xxxxxx"
57 vcenter_username: "username"
58 vcenter_password: "password"
59 ca_path: "path/to/ca_file"
60 name: profile-1
61 """
62
63 RETURN = r"""
64 ---
65 msg:
66 description: Status of the baseline profile information for the retrieve operation.
67 returned: always
68 type: str
69 sample: "Successfully retrieved the baseline profile information."
70 baseline_profile_info:
71 description: Information on the vCenter.
72 returned: success
73 type: list
74 elements: dict
75 sample:
76 [
77 {
78 "id": 1000,
79 "name": "Baseline-1",
80 "description": "Baseline-1 desc",
81 "consoleId": "xxxxx",
82 "consoleAddress": "xx.xx.xx.xx",
83 "firmwareRepoId": 1000,
84 "firmwareRepoName": "Dell Default Catalog",
85 "configurationRepoId": null,
86 "configurationRepoName": null,
87 "driverRepoId": null,
88 "driverRepoName": null,
89 "driftJobId": 1743,
90 "driftJobName": "BP-Baseline-1-Host-Firmware-Drift-Detection",
91 "dateCreated": "2024-10-16T10:25:29.786Z",
92 "dateModified": null,
93 "lastmodifiedBy": "[email protected]",
94 "version": "1.0.0-0",
95 "lastSuccessfulUpdatedTime": "2024-10-16T10:27:35.212Z",
96 "clusterGroups": [],
97 "datacenter_standAloneHostsGroups": [],
98 "baselineType": null,
99 "status": "SUCCESSFUL"
100 },
101 {
102 "id": 1001,
103 "name": "Baseline - 2",
104 "description": "Baseline - 2 description",
105 "consoleId": "xxxxx",
106 "consoleAddress": "xx.xx.xx.xx",
107 "firmwareRepoId": 1000,
108 "firmwareRepoName": "Dell Default Catalog",
109 "configurationRepoId": null,
110 "configurationRepoName": null,
111 "driverRepoId": null,
112 "driverRepoName": null,
113 "driftJobId": 1812,
114 "driftJobName": "BP-Baseline - 2-Host-Firmware-Drift-Detection",
115 "dateCreated": "2024-10-16T12:38:56.581Z",
116 "dateModified": null,
117 "lastmodifiedBy": "[email protected]",
118 "version": "1.0.0-0",
119 "lastSuccessfulUpdatedTime": "2024-10-16T12:41:02.641Z",
120 "clusterGroups": [],
121 "datacenter_standAloneHostsGroups": [
122 {
123 "associated_datacenterID": "datacenter-1001",
124 "associated_datacenterName": "Standalone Hosts-Test-DC",
125 "omevv_groupID": 1002
126 }
127 ],
128 "baselineType": "DATACENTER_NONCLUSTER",
129 "status": "SUCCESSFUL"
130 }
131 ]
132 error_info:
133 description: Details of the HTTP Error.
134 returned: on HTTP error
135 type: dict
136 sample: {
137 "error": {
138 "code": "Base.1.0.GeneralError",
139 "message": "A general error has occurred. See ExtendedInfo for more information.",
140 "@Message.ExtendedInfo": [
141 {
142 "MessageId": "GEN1234",
143 "RelatedProperties": [],
144 "Message": "Unable to process the request because an error occurred.",
145 "MessageArgs": [],
146 "Severity": "Critical",
147 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
148 }
149 ]
150 }
151 }
152 """
153
154 import json
155 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
156 from ansible.module_utils.urls import ConnectionError, SSLValidationError
157 from ansible_collections.dellemc.openmanage.plugins.module_utils.omevv import RestOMEVV, OMEVVAnsibleModule
158 from ansible_collections.dellemc.openmanage.plugins.module_utils.omevv_utils.omevv_firmware_utils import OMEVVBaselineProfile
159
160 SUCCESS_MSG = "Successfully retrieved the baseline profile information."
161 NO_PROFILE_MSG = "'{profile_name}' baseline profile name does not exist in OMEVV."
162 ERROR_CODES = ["12027"]
163
164
165 class OMEVVBaselineProfileInfo:
166
167 def __init__(self, module, rest_obj) -> None:
168 """
169 Initializes a new instance of the class.
170 Args:
171 module (object): The module object.
172 rest_obj (object): The REST object.
173 Returns:
174 None
175 """
176 self.module = module
177 self.obj = rest_obj
178
179 def perform_module_operation(self) -> dict:
180 """
181 Retrieves the baseline profile information.
182 Returns:
183 dict: A dictionary containing the message and the baseline profile information.
184 - msg (str): The success message or the error message.
185 - profile_info (list): The list of baseline profile information.
186 """
187 profile_name = self.module.params.get("name")
188 uuid = self.module.params.get("vcenter_uuid")
189 self.omevv_utils_obj = OMEVVBaselineProfile(self.obj)
190 if profile_name:
191 resp = self.omevv_utils_obj.get_baseline_profile_by_name(profile_name, uuid)
192 else:
193 resp = self.omevv_utils_obj.get_baseline_profiles(uuid)
194 result = {'msg': SUCCESS_MSG, 'profile_info': resp}
195 if not resp:
196 result['msg'] = NO_PROFILE_MSG.format(profile_name=profile_name)
197 return result
198
199
200 def main():
201 """
202 Retrieves the baseline profile information.
203
204 Returns:
205 dict: A dictionary containing the message and the baseline profile information.
206 - msg (str): The success message or the error message.
207 - profile_info (list): The list of baseline profile information.
208
209 Error Codes:
210 - 12027: The specified vCenter UUID is not registered in OME.
211 """
212 argument_spec = {
213 "name": {"type": 'str'}
214 }
215 module = OMEVVAnsibleModule(argument_spec=argument_spec,
216 supports_check_mode=True)
217 try:
218 with RestOMEVV(module.params) as rest_obj:
219 omevv_obj = OMEVVBaselineProfileInfo(module, rest_obj)
220 resp = omevv_obj.perform_module_operation()
221 module.exit_json(msg=resp['msg'], profile_info=resp['profile_info'])
222 except HTTPError as err:
223 error_info = json.load(err)
224 message = error_info.get('message')
225 code = error_info.get('errorCode')
226 if code in ERROR_CODES:
227 module.exit_json(msg=message, skipped=True)
228 module.exit_json(msg=str(err), error_info=error_info, failed=True)
229 except URLError as err:
230 module.exit_json(msg=str(err), unreachable=True)
231 except (SSLValidationError, TypeError, ConnectionError, IOError, ValueError,
232 AttributeError, OSError, IndexError, KeyError,) as err:
233 module.exit_json(msg=str(err), failed=True)
234
235
236 if __name__ == '__main__':
237 main()