Skip to content

Commit

Permalink
Use folder attribute for host and dc module only (#79)
Browse files Browse the repository at this point in the history
There is folder attribute only for vcenter_host and vcenter_datacenter
modules only, for other modules it shouldn't be used and caused issues.

With this PR, we fix the vcenter_vm module and others to return the
real REST object data, instead of error ALREADY_EXISTS in case of the
rerun of the module.

Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra authored Mar 13, 2024
1 parent e775adc commit f32c824
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/76-vmware_rest-dont_use_folder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Use folder attribute for host and dc module only (https://github.com/ansible-community/ansible.content_builder/pull/79)."
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ async def _{{ operation }}(params, session):
comp_func = None

async def lookup_with_filters(params, session, url):
# e.g: for the datacenter resources
search_filter = ''
{% if name in ["vcenter_host", "vcenter_datacenter"] %}
if "folder" not in params:
return
search_filter = f"&folders={params.get['folder']}"
{% endif %}
if "name" not in params:
return
async with session.get(f"{url}?names={params['name']}&folders={params['folder']}") as resp:
async with session.get(f"{url}?names={params['name']}{search_filter}") as resp:
_json = await resp.json()
if isinstance(_json, list) and len(_json) == 1:
return await get_device_info(session, url, _json[0]["{{list_index}}"])
Expand Down

0 comments on commit f32c824

Please sign in to comment.