Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_guest_info - Make "datacenter" property optional #2241

Conversation

PfurtschellerP
Copy link
Contributor

SUMMARY

We run a big VMware environment featuring multiple vCenters and multiple datacenters within them.
When automating the deployment of VMs at the moment we search for existing machines with the name of the to be deployed machine in order to perform clean-up activities. At the moment we use the guest find module, but it's slow.
Therefore we looked into the guest_info module and found that if the VM is unique, the datacenter property is never actually used as it is only relevant in case multiple VMs have been found.

In case multiple VMs are found, the folder and datacenter attributes are used to decide on "the right one".
Therefore, the datacenter property could as well be an optional parameter on the module and it could simply fail in case there is more than one VM matching and "datacenter" as well as "folder" are required.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • vmware_guest_info.py
  • vmware.py
ADDITIONAL INFORMATION

…VMs were found and make providing the datacenter property in the guest_info module optional.

Signed-off-by: Patrick Pfurtscheller <[email protected]>
Signed-off-by: Patrick Pfurtscheller <[email protected]>
@PfurtschellerP PfurtschellerP marked this pull request as ready for review November 14, 2024 13:29
@mariolenz
Copy link
Collaborator

The code you've changed in plugins/module_utils/vmware.py is used by a quite a lot of modules:

$ grep -r 'get_vm(' plugins/modules/ | cut -d ':' -f 1 | sort | uniq 
plugins/modules/vmware_content_deploy_ovf_template.py
plugins/modules/vmware_content_deploy_template.py
plugins/modules/vmware_deploy_ovf.py
plugins/modules/vmware_export_ovf.py
plugins/modules/vmware_guest_boot_info.py
plugins/modules/vmware_guest_boot_manager.py
plugins/modules/vmware_guest_controller.py
plugins/modules/vmware_guest_cross_vc_clone.py
plugins/modules/vmware_guest_custom_attributes.py
plugins/modules/vmware_guest_disk_info.py
plugins/modules/vmware_guest_disk.py
plugins/modules/vmware_guest_info.py
plugins/modules/vmware_guest_move.py
plugins/modules/vmware_guest_network.py
plugins/modules/vmware_guest_powerstate.py
plugins/modules/vmware_guest.py
plugins/modules/vmware_guest_register_operation.py
plugins/modules/vmware_guest_screenshot.py
plugins/modules/vmware_guest_sendkey.py
plugins/modules/vmware_guest_serial_port.py
plugins/modules/vmware_guest_snapshot_info.py
plugins/modules/vmware_guest_snapshot.py
plugins/modules/vmware_guest_storage_policy.py
plugins/modules/vmware_guest_tools_info.py
plugins/modules/vmware_guest_tools_upgrade.py
plugins/modules/vmware_guest_tools_wait.py
plugins/modules/vmware_guest_tpm.py
plugins/modules/vmware_guest_vgpu_info.py
plugins/modules/vmware_guest_vgpu.py
plugins/modules/vmware_guest_video.py
plugins/modules/vmware_host_auto_start.py
plugins/modules/vmware_vmotion.py

So we'll have to make sure that it's really safe and we don't break anything by accident. Apropos of breaking things, this might be considered a breaking change because people are used to the current behavior. And that means we might have to wait for the next major release to implement this.

@PfurtschellerP
Copy link
Contributor Author

@mariolenz Okay, what would be the best approach here going foreward?

Copy link
Collaborator

@mariolenz mariolenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, what would be the best approach here going foreward?

I've had a look at those other modules and think that your changes should be OK. Let's give it a try! Although we might revert this in a future minor or bugfix release if it turns out to be problematic later.

There's just one minor thing I see in the error message. I should say it hasn't been that great before, but maybe we should improve it a bit while we're at it.

cc @ihumster

plugins/module_utils/vmware.py Outdated Show resolved Hide resolved
@ihumster
Copy link
Collaborator

@mariolenz I looked at the vmware.py library code and I think the changes Patrick made are pretty safe for the modules to function. And indeed, if something goes wrong, we will release a rollback fix.

@mariolenz
Copy link
Collaborator

recheck

@mariolenz
Copy link
Collaborator

recheck

Copy link
Collaborator

@mariolenz mariolenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @PfurtschellerP!

Thanks for reviewing @ihumster!

Copy link

Build succeeded (gate pipeline).
https://ansible.softwarefactory-project.io/zuul/buildset/0de8d710e6194f23b7e037cf4d7531f0

✔️ ansible-tox-linters SUCCESS in 4m 36s
✔️ build-ansible-collection SUCCESS in 7m 15s
✔️ ansible-galaxy-importer SUCCESS in 3m 12s

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 5bca41c into ansible-collections:main Nov 29, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants