Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vmtemplate_libraryitems_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2021, Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # template: header.j2
6 # This module is autogenerated using the ansible.content_builder.
7 # See: https://github.com/ansible-community/ansible.content_builder
8
9
10 DOCUMENTATION = r"""
11 module: vcenter_vmtemplate_libraryitems_info
12 short_description: Returns information about a virtual machine template contained
13 in the library item specified by templateLibraryItem
14 description: Returns information about a virtual machine template contained in the
15 library item specified by templateLibraryItem
16 deprecated:
17 removed_in: 5.0.0
18 why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880)
19 alternative: Use M(vmware.vmware.content_library_item_info) instead.
20 options:
21 session_timeout:
22 description:
23 - 'Timeout settings for client session. '
24 - 'The maximal number of seconds for the whole operation including connection
25 establishment, request sending and response. '
26 - The default value is 300s.
27 type: float
28 version_added: 2.1.0
29 template_library_item:
30 description:
31 - identifier of the library item containing the virtual machine template.
32 - The parameter must be the id of a resource returned by M(vmware.vmware_rest.content_library_item_info).
33 Required with I(state=['get'])
34 type: str
35 vcenter_hostname:
36 description:
37 - The hostname or IP address of the vSphere vCenter
38 - If the value is not specified in the task, the value of environment variable
39 C(VMWARE_HOST) will be used instead.
40 required: true
41 type: str
42 vcenter_password:
43 description:
44 - The vSphere vCenter password
45 - If the value is not specified in the task, the value of environment variable
46 C(VMWARE_PASSWORD) will be used instead.
47 required: true
48 type: str
49 vcenter_rest_log_file:
50 description:
51 - 'You can use this optional parameter to set the location of a log file. '
52 - 'This file will be used to record the HTTP REST interaction. '
53 - 'The file will be stored on the host that runs the module. '
54 - 'If the value is not specified in the task, the value of '
55 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
56 type: str
57 vcenter_username:
58 description:
59 - The vSphere vCenter username
60 - If the value is not specified in the task, the value of environment variable
61 C(VMWARE_USER) will be used instead.
62 required: true
63 type: str
64 vcenter_validate_certs:
65 default: true
66 description:
67 - Allows connection when SSL certificates are not valid. Set to C(false) when
68 certificates are not trusted.
69 - If the value is not specified in the task, the value of environment variable
70 C(VMWARE_VALIDATE_CERTS) will be used instead.
71 type: bool
72 author:
73 - Ansible Cloud Team (@ansible-collections)
74 version_added: 2.2.0
75 requirements:
76 - vSphere 7.0.3 or greater
77 - python >= 3.6
78 - aiohttp
79 notes:
80 - Tested on vSphere 7.0.3
81 """
82
83 EXAMPLES = r"""
84 """
85 RETURN = r"""
86 """
87
88
89 # This structure describes the format of the data expected by the end-points
90 PAYLOAD_FORMAT = {
91 "get": {
92 "query": {},
93 "body": {},
94 "path": {"template_library_item": "template_library_item"},
95 }
96 } # pylint: disable=line-too-long
97
98 from ansible.module_utils.basic import env_fallback
99 import os
100
101 if os.getenv("VMWARE_ENABLE_TURBO", False):
102 try:
103 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
104 AnsibleTurboModule as AnsibleModule,
105 )
106
107 AnsibleModule.collection_name = "vmware.vmware_rest"
108 except ImportError:
109 from ansible.module_utils.basic import AnsibleModule
110 else:
111 from ansible.module_utils.basic import AnsibleModule
112
113 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
114 gen_args,
115 open_session,
116 session_timeout,
117 update_changed_flag,
118 )
119
120
121 def prepare_argument_spec():
122 argument_spec = {
123 "vcenter_hostname": dict(
124 type="str",
125 required=True,
126 fallback=(env_fallback, ["VMWARE_HOST"]),
127 ),
128 "vcenter_username": dict(
129 type="str",
130 required=True,
131 fallback=(env_fallback, ["VMWARE_USER"]),
132 ),
133 "vcenter_password": dict(
134 type="str",
135 required=True,
136 no_log=True,
137 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
138 ),
139 "vcenter_validate_certs": dict(
140 type="bool",
141 required=False,
142 default=True,
143 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
144 ),
145 "vcenter_rest_log_file": dict(
146 type="str",
147 required=False,
148 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
149 ),
150 "session_timeout": dict(
151 type="float",
152 required=False,
153 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
154 ),
155 }
156
157 argument_spec["template_library_item"] = {"type": "str"}
158
159 return argument_spec
160
161
162 async def main():
163 required_if = list([])
164
165 module_args = prepare_argument_spec()
166 module = AnsibleModule(
167 argument_spec=module_args, required_if=required_if, supports_check_mode=True
168 )
169 if not module.params["vcenter_hostname"]:
170 module.fail_json("vcenter_hostname cannot be empty")
171 if not module.params["vcenter_username"]:
172 module.fail_json("vcenter_username cannot be empty")
173 if not module.params["vcenter_password"]:
174 module.fail_json("vcenter_password cannot be empty")
175 try:
176 session = await open_session(
177 vcenter_hostname=module.params["vcenter_hostname"],
178 vcenter_username=module.params["vcenter_username"],
179 vcenter_password=module.params["vcenter_password"],
180 validate_certs=module.params["vcenter_validate_certs"],
181 log_file=module.params["vcenter_rest_log_file"],
182 )
183 except Exception as err:
184 if hasattr(err, "get_message"):
185 module.fail_json(err.get_message())
186 else:
187 module.fail_json(str(err))
188 result = await entry_point(module, session)
189 module.exit_json(**result)
190
191
192 # template: info_no_list_module.j2
193 def build_url(params):
194 return (
195 "https://{vcenter_hostname}" "/api/vcenter/vm-template/library-items"
196 ).format(**params)
197
198
199 async def entry_point(module, session):
200 return await _info(module.params, session)
201
202
203 async def _info(params, session):
204 payload_format = list(PAYLOAD_FORMAT.values())[0]
205 _in_query_parameters = payload_format["query"].keys()
206 _url = (
207 "https://{vcenter_hostname}" "/api/vcenter/vm-template/library-items"
208 ).format(**params) + gen_args(params, _in_query_parameters)
209 async with session.get(_url, **session_timeout(params)) as resp:
210 try:
211 if resp.headers["Content-Type"] == "application/json":
212 _json = await resp.json()
213 except KeyError:
214 _json = {}
215 return await update_changed_flag(_json, resp.status, "get")
216
217
218 if __name__ == "__main__":
219 import asyncio
220
221 current_loop = asyncio.new_event_loop()
222 try:
223 asyncio.set_event_loop(current_loop)
224 current_loop.run_until_complete(main())
225 finally:
226 current_loop.close()