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

Feature/migrate esxi host inventory #91

Conversation

mikemorency
Copy link
Collaborator

@mikemorency mikemorency commented Dec 16, 2024

SUMMARY

Adds an ESXi host inventory plugin. This plugin was originally going to be a migration from the community collection, but I dont think I can call it that at this point.

While the output is largely the same, some redundant properties have been removed and some data has been manipulated to be more useful (i.e. tags now return the tag ID and tag name instead of just the tag name, which is not unique).
Additionally, some community options seemed confusing, conflicted with options we have for info modules, or are no longer relevant.

Also, Im not able to use the existing pyvmomi class in the inventory plugin since it is tightly coupled to modules. The community collection works around this by maintaining two nearly identical versions of the pyvmomi/rest utilities for modules and for plugins.
I think we can break some of the pyvmomi/rest utils into more generic "client" classes. Those can be used by module or plugin base classes (like i do in this PR for the inventory plugin), and then those base classes can be extended by individual modules and plugins.
This approach has greatly reduced the amount of duplicated code, and I think will make it easier for community to switch to the new utils.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

vmware.vmware.esxi_hosts

ADDITIONAL INFO

I tested the new "client" classes with the modules and it worked as expected. Fully switching them over would be a task for next release

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 25.05400% with 347 lines in your changes missing coverage. Please review.

Project coverage is 27.38%. Comparing base (bb1aba5) to head (ce44f60).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
plugins/inventory/esxi_hosts.py 22.56% 127 Missing ⚠️
plugins/module_utils/clients/_pyvmomi.py 20.95% 83 Missing ⚠️
plugins/module_utils/clients/_rest.py 32.63% 64 Missing ⚠️
plugins/inventory_utils/_base.py 20.77% 61 Missing ⚠️
plugins/module_utils/_vmware_facts.py 12.50% 7 Missing ⚠️
plugins/module_utils/clients/_errors.py 50.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
- Coverage   27.89%   27.38%   -0.52%     
==========================================
  Files          25       31       +6     
  Lines        2079     2542     +463     
  Branches      386      468      +82     
==========================================
+ Hits          580      696     +116     
- Misses       1499     1846     +347     
Flag Coverage Δ
sanity 27.38% <25.05%> (-0.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mikemorency mikemorency force-pushed the feature/migrate-esxi-host-inventory branch from fdaa257 to b4b6338 Compare December 16, 2024 22:43
@mikemorency mikemorency marked this pull request as ready for review December 16, 2024 22:45
@prabinovRedhat
Copy link
Collaborator

I see that the test failed due to the following error:

The conditional check 'first_host.ansible_host' failed. The error was: error while evaluating conditional (first_host.ansible_host): {{ (inventory_results._meta.hostvars.values() | first) }}: No first item, sequence was empty.

So, the inventory plugin did not return any hosts, causing inventory_results._meta.hostvars to be empty

plugins/inventory/esxi_hosts.py Outdated Show resolved Hide resolved
plugins/inventory/esxi_hosts.py Outdated Show resolved Hide resolved
plugins/inventory/esxi_hosts.py Outdated Show resolved Hide resolved
plugins/inventory/esxi_hosts.py Outdated Show resolved Hide resolved
plugins/inventory/esxi_hosts.py Outdated Show resolved Hide resolved
plugins/module_utils/clients/_pyvmomi.py Outdated Show resolved Hide resolved
plugins/module_utils/clients/_rest.py Outdated Show resolved Hide resolved
plugins/module_utils/clients/_rest.py Outdated Show resolved Hide resolved
plugins/module_utils/clients/_rest.py Outdated Show resolved Hide resolved
@prabinovRedhat
Copy link
Collaborator

Screenshot 2024-12-19 at 13 50 14

While testing the inventory plugin, I noticed that the initial output format looks a bit messy and difficult to read (as shown in the attached screenshot). However, below, I do see a more structured and readable version.

Could you confirm if this initial "user unfriendly" format is expected behavior? If so, is it something that could potentially be optimized for better readability during debugging?

@mikemorency
Copy link
Collaborator Author

@prabinovRedhat
I can try to print some more readable output first and then show the full output if the pretty print fails

@prabinovRedhat
Copy link
Collaborator

Thanks looks good!

Copy link
Collaborator

@prabinovRedhat prabinovRedhat left a comment

Choose a reason for hiding this comment

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

lgtm

@mikemorency mikemorency force-pushed the feature/migrate-esxi-host-inventory branch from d700808 to 27db3cb Compare December 19, 2024 15:38
@mikemorency mikemorency merged commit 22a8e3e into ansible-collections:main Dec 19, 2024
11 of 13 checks passed
@mikemorency mikemorency deleted the feature/migrate-esxi-host-inventory branch December 19, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants