Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_guest_localfilesystem_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_vm_guest_localfilesystem_info
12 short_description: Returns details of the local file systems in the guest operating
13 system.
14 description: Returns details of the local file systems in the guest operating system.
15 options:
16 session_timeout:
17 description:
18 - 'Timeout settings for client session. '
19 - 'The maximal number of seconds for the whole operation including connection
20 establishment, request sending and response. '
21 - The default value is 300s.
22 type: float
23 version_added: 2.1.0
24 vcenter_hostname:
25 description:
26 - The hostname or IP address of the vSphere vCenter
27 - If the value is not specified in the task, the value of environment variable
28 C(VMWARE_HOST) will be used instead.
29 required: true
30 type: str
31 vcenter_password:
32 description:
33 - The vSphere vCenter password
34 - If the value is not specified in the task, the value of environment variable
35 C(VMWARE_PASSWORD) will be used instead.
36 required: true
37 type: str
38 vcenter_rest_log_file:
39 description:
40 - 'You can use this optional parameter to set the location of a log file. '
41 - 'This file will be used to record the HTTP REST interaction. '
42 - 'The file will be stored on the host that runs the module. '
43 - 'If the value is not specified in the task, the value of '
44 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
45 type: str
46 vcenter_username:
47 description:
48 - The vSphere vCenter username
49 - If the value is not specified in the task, the value of environment variable
50 C(VMWARE_USER) will be used instead.
51 required: true
52 type: str
53 vcenter_validate_certs:
54 default: true
55 description:
56 - Allows connection when SSL certificates are not valid. Set to C(false) when
57 certificates are not trusted.
58 - If the value is not specified in the task, the value of environment variable
59 C(VMWARE_VALIDATE_CERTS) will be used instead.
60 type: bool
61 vm:
62 description:
63 - Identifier of the virtual machine.
64 - The parameter must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_info).
65 Required with I(state=['get'])
66 type: str
67 author:
68 - Ansible Cloud Team (@ansible-collections)
69 version_added: 0.1.0
70 requirements:
71 - vSphere 7.0.3 or greater
72 - python >= 3.6
73 - aiohttp
74 notes:
75 - Tested on vSphere 7.0.3
76 """
77
78 EXAMPLES = r"""
79 - name: Look up the VM called test_vm1 in the inventory
80 register: search_result
81 vmware.vmware_rest.vcenter_vm_info:
82 filter_names:
83 - test_vm1
84
85 - name: Collect information about a specific VM
86 vmware.vmware_rest.vcenter_vm_info:
87 vm: '{{ search_result.value[0].vm }}'
88 register: test_vm1_info
89
90 - name: Get guest filesystem information
91 vmware.vmware_rest.vcenter_vm_guest_localfilesystem_info:
92 vm: '{{ test_vm1_info.id }}'
93 register: _result
94 until:
95 - _result is not failed
96 retries: 60
97 delay: 5
98 """
99 RETURN = r"""
100 # content generated by the update_return_section callback# task: Get guest filesystem information
101 value:
102 description: Get guest filesystem information
103 returned: On success
104 sample:
105 /:
106 capacity: 2515173376
107 free_space: 774787072
108 mappings: []
109 type: dict
110 """
111
112
113 # This structure describes the format of the data expected by the end-points
114 PAYLOAD_FORMAT = {
115 "get": {"query": {}, "body": {}, "path": {"vm": "vm"}}
116 } # pylint: disable=line-too-long
117
118 from ansible.module_utils.basic import env_fallback
119 import os
120
121 if os.getenv("VMWARE_ENABLE_TURBO", False):
122 try:
123 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
124 AnsibleTurboModule as AnsibleModule,
125 )
126
127 AnsibleModule.collection_name = "vmware.vmware_rest"
128 except ImportError:
129 from ansible.module_utils.basic import AnsibleModule
130 else:
131 from ansible.module_utils.basic import AnsibleModule
132
133 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
134 gen_args,
135 open_session,
136 session_timeout,
137 update_changed_flag,
138 )
139
140
141 def prepare_argument_spec():
142 argument_spec = {
143 "vcenter_hostname": dict(
144 type="str",
145 required=True,
146 fallback=(env_fallback, ["VMWARE_HOST"]),
147 ),
148 "vcenter_username": dict(
149 type="str",
150 required=True,
151 fallback=(env_fallback, ["VMWARE_USER"]),
152 ),
153 "vcenter_password": dict(
154 type="str",
155 required=True,
156 no_log=True,
157 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
158 ),
159 "vcenter_validate_certs": dict(
160 type="bool",
161 required=False,
162 default=True,
163 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
164 ),
165 "vcenter_rest_log_file": dict(
166 type="str",
167 required=False,
168 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
169 ),
170 "session_timeout": dict(
171 type="float",
172 required=False,
173 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
174 ),
175 }
176
177 argument_spec["vm"] = {"type": "str"}
178
179 return argument_spec
180
181
182 async def main():
183 required_if = list([])
184
185 module_args = prepare_argument_spec()
186 module = AnsibleModule(
187 argument_spec=module_args, required_if=required_if, supports_check_mode=True
188 )
189 if not module.params["vcenter_hostname"]:
190 module.fail_json("vcenter_hostname cannot be empty")
191 if not module.params["vcenter_username"]:
192 module.fail_json("vcenter_username cannot be empty")
193 if not module.params["vcenter_password"]:
194 module.fail_json("vcenter_password cannot be empty")
195 try:
196 session = await open_session(
197 vcenter_hostname=module.params["vcenter_hostname"],
198 vcenter_username=module.params["vcenter_username"],
199 vcenter_password=module.params["vcenter_password"],
200 validate_certs=module.params["vcenter_validate_certs"],
201 log_file=module.params["vcenter_rest_log_file"],
202 )
203 except Exception as err:
204 if hasattr(err, "get_message"):
205 module.fail_json(err.get_message())
206 else:
207 module.fail_json(str(err))
208 result = await entry_point(module, session)
209 module.exit_json(**result)
210
211
212 # template: info_no_list_module.j2
213 def build_url(params):
214 return (
215 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/guest/local-filesystem"
216 ).format(**params)
217
218
219 async def entry_point(module, session):
220 return await _info(module.params, session)
221
222
223 async def _info(params, session):
224 payload_format = list(PAYLOAD_FORMAT.values())[0]
225 _in_query_parameters = payload_format["query"].keys()
226 _url = (
227 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/guest/local-filesystem"
228 ).format(**params) + gen_args(params, _in_query_parameters)
229 async with session.get(_url, **session_timeout(params)) as resp:
230 try:
231 if resp.headers["Content-Type"] == "application/json":
232 _json = await resp.json()
233 except KeyError:
234 _json = {}
235 return await update_changed_flag(_json, resp.status, "get")
236
237
238 if __name__ == "__main__":
239 import asyncio
240
241 current_loop = asyncio.new_event_loop()
242 try:
243 asyncio.set_event_loop(current_loop)
244 current_loop.run_until_complete(main())
245 finally:
246 current_loop.close()