Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/ome_template_info.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) 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 __metaclass__ = type
15
16 DOCUMENTATION = r'''
17 ---
18 module: ome_template_info
19 short_description: Retrieves template details from OpenManage Enterprise
20 version_added: "2.0.0"
21 description:
22 - This module retrieves the list and details of all the templates on OpenManage Enterprise.
23 extends_documentation_fragment:
24 - dellemc.openmanage.ome_auth_options
25 options:
26 template_id:
27 description: Unique Id of the template.
28 type: int
29 system_query_options:
30 description: Options for pagination of the output.
31 type: dict
32 suboptions:
33 filter:
34 description: Filter records by the supported values.
35 type: str
36 requirements:
37 - "python >= 3.9.6"
38 author:
39 - "Sajna Shetty(@Sajna-Shetty)"
40 - "Meenakshi Dembi (@meenakshidembi691)"
41 notes:
42 - Run this module from a system that has direct access to Dell OpenManage Enterprise.
43 - This module supports C(check_mode).
44
45 '''
46
47 EXAMPLES = r'''
48 ---
49 - name: Retrieve basic details of all templates
50 dellemc.openmanage.ome_template_info:
51 hostname: "192.168.0.1"
52 username: "username"
53 password: "password"
54 ca_path: "/path/to/ca_cert.pem"
55
56 - name: Retrieve details of a specific template identified by its template ID
57 dellemc.openmanage.ome_template_info:
58 hostname: "192.168.0.1"
59 username: "username"
60 password: "password"
61 ca_path: "/path/to/ca_cert.pem"
62 template_id: 1
63
64 - name: Get filtered template info based on name
65 dellemc.openmanage.ome_template_info:
66 hostname: "192.168.0.1"
67 username: "username"
68 password: "password"
69 ca_path: "/path/to/ca_cert.pem"
70 system_query_options:
71 filter: "Name eq 'new template'"
72 '''
73
74 RETURN = r'''
75 ---
76 msg:
77 type: str
78 description: Overall template facts status.
79 returned: on error
80 sample: "Failed to fetch the template facts"
81 template_info:
82 type: dict
83 description: Details of the templates.
84 returned: success
85 sample: {
86 "192.168.0.1": {
87 "CreatedBy": "system",
88 "CreationTime": "1970-01-31 00:00:56.372144",
89 "Description": "Tune workload for Performance Optimized Virtualization",
90 "HasIdentityAttributes": false,
91 "Id": 1,
92 "IdentityPoolId": 0,
93 "IsBuiltIn": true,
94 "IsPersistencePolicyValid": false,
95 "IsStatelessAvailable": false,
96 "LastUpdatedBy": null,
97 "LastUpdatedTime": "1970-01-31 00:00:56.372144",
98 "Name": "iDRAC Enable Performance Profile for Virtualization",
99 "SourceDeviceId": 0,
100 "Status": 0,
101 "TaskId": 0,
102 "TypeId": 2,
103 "ViewTypeId": 4
104 }
105 }
106 '''
107
108 import json
109 from ssl import SSLError
110 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
111 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
112 from ansible.module_utils.urls import ConnectionError, SSLValidationError
113
114
115 def _get_query_parameters(module_params):
116 """Builds query parameter.
117
118 :return: dict
119 :example: {"$filter": Name eq 'template name'}
120 """
121 system_query_param = module_params.get("system_query_options")
122 query_param = {}
123 if system_query_param:
124 query_param = dict([("$" + k, v) for k, v in system_query_param.items() if v is not None])
125 return query_param
126
127
128 def main():
129 specs = {
130 "template_id": {"type": 'int', "required": False},
131 "system_query_options": {"required": False, "type": 'dict',
132 "options": {"filter": {"type": 'str', "required": False}}
133 },
134 }
135
136 module = OmeAnsibleModule(
137 argument_spec=specs,
138 mutually_exclusive=[['template_id', 'system_query_options']],
139 supports_check_mode=True
140 )
141 template_uri = "TemplateService/Templates"
142 try:
143 with RestOME(module.params, req_session=True) as rest_obj:
144 query_param = None
145 if module.params.get("template_id") is not None:
146 # Fetch specific template
147 template_id = module.params.get("template_id")
148 template_path = "{0}({1})".format(template_uri, template_id)
149 elif module.params.get("system_query_options") is not None:
150 # Fetch all the templates based on Name
151 query_param = _get_query_parameters(module.params)
152 template_path = template_uri
153 else:
154 # Fetch all templates
155 template_path = template_uri
156 resp = rest_obj.invoke_request('GET', template_path, query_param=query_param)
157 template_facts = resp.json_data
158 if resp.status_code == 200:
159 module.exit_json(template_info={module.params["hostname"]: template_facts})
160 else:
161 module.exit_json(msg="Failed to fetch the template facts", failed=True)
162 except HTTPError as err:
163 module.exit_json(msg=json.load(err), failed=True)
164 except (URLError, SSLValidationError, ConnectionError, TypeError, ValueError, OSError, SSLError) as err:
165 module.exit_json(msg=str(err), failed=True)
166
167
168 if __name__ == '__main__':
169 main()