feat(vm-consumption-report): add VM consumption reporting role#7
feat(vm-consumption-report): add VM consumption reporting role#7stevefulme1 wants to merge 15 commits into
Conversation
Move from openshift_virtualization_migration repo — this is day 2 ops functionality for generating consumption reports of running OCP VMs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add filename prefix to task names in _collect_vms.yml, _collect_vmis.yml, and _build_report.yml to satisfy ansible-lint name[prefix] rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-ansible manage deps/commands
sabre1041
left a comment
There was a problem hiding this comment.
@stevefulme1 Reviewed the report generation. There are some questions that I have based on this integration.
- See the additional filter for removing null values in the
lastTransitionTimeproperty - The reconciled field will never contain a positive value as a match is not possible
- Is the goal to have a set of hostnames/uuid's and check if a match is found in the cluster?
| last_transition: >- | ||
| {{ _vm.status.conditions | ||
| | default([]) | ||
| | sort(attribute='lastTransitionTime') |
There was a problem hiding this comment.
| | sort(attribute='lastTransitionTime') | |
| | selectattr('lastTransitionTime', 'defined') | rejectattr('lastTransitionTime', 'none') | |
| | sort(attribute='lastTransitionTime') |
Need to filter out items that contain null values
There was a problem hiding this comment.
Good catch — pushed this fix in 89241f3. Added selectattr('lastTransitionTime', 'defined') | rejectattr('lastTransitionTime', 'none') before the sort.
| | list | first | default({}) }} | ||
| _vm_uuid: "{{ _vm.metadata.uid }}" | ||
| _guest_hostname: >- | ||
| {{ _vmi_match.status.guestOSInfo.hostname | default('') }} |
There was a problem hiding this comment.
hostname is not a valid field for guestOSInfo so we will never have a reconcile entry
There was a problem hiding this comment.
You're right — guestOSInfo doesn't expose a hostname field. The guest agent hostname isn't available at that path in the VMI status.
The reconciliation still works via UUID and IP address matching, but the hostname branch of _direct_match is effectively dead code. I'll remove guestOSInfo.hostname as a matching source. If there's a different VMI status path you'd recommend for guest hostname, happy to wire that in instead.
There was a problem hiding this comment.
Targeting a VMI for reporting purposes is risky as no instance is created when a VM is not running.
There are a few options for looking into capturing VM information. It is not exposed in the status field, but you can check the .spec.template.spec.hostname field to see if it has been explicitly defined and maybe just fallback to metadata.name as that is used by default
Conditions with undefined or null lastTransitionTime values cause sort(attribute='lastTransitionTime') to fail. Filter them out with selectattr/rejectattr before sorting.
guestOSInfo does not expose a hostname field. Set _guest_hostname to empty string, disabling hostname-based reconciliation. UUID and IP address matching remain functional.
|
Addressing the review:
|
Use .spec.template.spec.hostname from the VM object with fallback to metadata.name rather than relying on VMI guestOSInfo. VMI does not exist when a VM is stopped, making it unreliable for reporting.
Summary
vm_consumption_reportrole and playbook for generating consumption reports of OpenShift Virtualization VMskubernetes.core.k8s_info, supporting namespace and label selector filteringMoved from
Originally submitted as redhat-cop/openshift_virtualization_migration#29 — relocated here as this is day 2 ops functionality (reporting/inventory of running VMs), not migration logic.
FQCN updated from
infra.openshift_virtualization_migrationtoinfra.openshift_virtualization_ops.Test plan
yamllintpassesansible-lint --offlinepasses production profilevm_consumption_report_direct_hostsentriesvm_consumption_report_include_status: falseto skip VMI queries🤖 Generated with Claude Code