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

Mm feature/migrate drs recommendations #74

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- cluster_drs_recommendations - Fix issue where no task object is returned when applying DRS recommendations. Lookup the latest task instead
27 changes: 20 additions & 7 deletions plugins/modules/cluster_drs_recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
short_description: Apply Distributed Resource Scheduler (DRS) recommendations on VMware vSphere clusters
description:
- Applies DRS recommendations on VMware vSphere clusters.
- >-
DRS recommendations are made based on a variety of factors such as resource usage, host health, and some advanced settings like TryBalanceVmsPerHost.
The cluster may not recommend moving a VM if the cost of moving the VM is greater than the benefit that would come after the move.
- >-
Recommendations may only be made if the VM can be vMotioned onto another host. Even if a host is clearly overloaded, if the VMs cannot move
to another host then no recommendations will appear.
- >-
If you try manually vMotioning a VM through the GUI, vCenter will validate the vMotion options at each step. This can be useful when determining
why a VM is not able to move to another host and why no recommendations are being made.
author:
- Ansible Cloud Team (@ansible-collections)

Expand Down Expand Up @@ -57,7 +66,7 @@
type: list
sample: [
{
"description": "server1 move from host1 to host2.",
"description": "server1 will move from host1 to host2.",
"task_result": {
"completion_time": "2024-07-29T15:27:37.041577+00:00",
"entity_name": "test-5fb1_cluster_drs_test",
Expand All @@ -67,7 +76,7 @@
}
},
{
"description": "server2 move from host1 to host2.",
"description": "server2 will move from host1 to host2.",
"task_result": {
"completion_time": "2024-07-29T15:27:37.041577+00:00",
"entity_name": "test-5fb1_cluster_drs_test",
Expand Down Expand Up @@ -123,16 +132,20 @@
applied_recommendation_descriptions = []
applied_recommendation_tasks = []
for recommendation in self.cluster.recommendation:
# since these are vmotion recommendations, there's only ever one action
action = recommendation.action[0]

Check warning on line 136 in plugins/modules/cluster_drs_recommendations.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_drs_recommendations.py#L136

Added line #L136 was not covered by tests
applied_recommendation_descriptions.append(
"%s move from %s to %s." % (
recommendation.action[0].target.name,
recommendation.action[0].drsMigration.source.name,
recommendation.action[0].drsMigration.destination.name
"%s will move from %s to %s." % (
action.target.name,
action.drsMigration.source.name,
action.drsMigration.destination.name
)
)

if not self.module.check_mode:
applied_recommendation_tasks.append(self.cluster.ApplyRecommendation(recommendation.key))
self.cluster.ApplyRecommendation(recommendation.key)

Check warning on line 146 in plugins/modules/cluster_drs_recommendations.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_drs_recommendations.py#L146

Added line #L146 was not covered by tests
# get the most recent task for the target VM, which should be the vmotion task we just triggered
applied_recommendation_tasks.append(action.target.recentTask[0])

Check warning on line 148 in plugins/modules/cluster_drs_recommendations.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_drs_recommendations.py#L148

Added line #L148 was not covered by tests

task_results = self.__wait_for_recommendation_task_results(applied_recommendation_tasks)
combined_results = zip_longest(applied_recommendation_descriptions, task_results, fillvalue=dict())
Expand Down
Loading