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

fix dpm automation level option #75

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
3 changes: 3 additions & 0 deletions changelogs/fragments/75-fix-dpm-automation-level-terms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- cluster_dpm - Change automation level option from 'automated' to 'automatic' so it matches the vCenter UI
26 changes: 19 additions & 7 deletions plugins/modules/cluster_dpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
automatically or manually.
- If set to V(manual), then vCenter generates host power operation and related virtual machine
migration recommendations are made, but they are not automatically run.
- If set to V(automated), then vCenter host power operations are automatically run if
- If set to V(automatic), then vCenter host power operations are automatically run if
related virtual machine migrations can all be run automatically.
type: str
default: automated
choices: [ automated, manual ]
default: automatic
choices: [ automatic, manual ]
recommendation_priority_threshold:
description:
- Threshold for generated host power recommendations ranging from V(1) (most conservative) to V(5) (most aggressive).
Expand Down Expand Up @@ -128,6 +128,18 @@
datacenter = self.get_datacenter_by_name(self.params.get('datacenter'), fail_on_missing=True)
self.cluster = self.get_cluster_by_name(self.params.get('cluster'), fail_on_missing=True, datacenter=datacenter)

@property
def automation_level(self):
"""
The vCenter UI and docs say the automation level can be manual or automatic. When setting this option
in the API, it expects manual or automated. So if the user chose 'automatic', we need to change it to
automated in code.
"""
if self.params['automation_level'] == 'automatic':
return 'automated'

Check warning on line 139 in plugins/modules/cluster_dpm.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_dpm.py#L139

Added line #L139 was not covered by tests

return self.params['automation_level']

Check warning on line 141 in plugins/modules/cluster_dpm.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_dpm.py#L141

Added line #L141 was not covered by tests

@property
def recommendation_priority_threshold(self):
"""
Expand All @@ -150,7 +162,7 @@
dpm_config = self.cluster.configurationEx.dpmConfigInfo

if (dpm_config.enabled != self.params['enable'] or
dpm_config.defaultDpmBehavior != self.params['automation_level'] or
dpm_config.defaultDpmBehavior != self.automation_level or
dpm_config.hostPowerActionRate != self.recommendation_priority_threshold):
return True

Expand All @@ -166,7 +178,7 @@
cluster_config_spec = vim.cluster.ConfigSpecEx()
cluster_config_spec.dpmConfig = vim.cluster.DpmConfigInfo()
cluster_config_spec.dpmConfig.enabled = self.params['enable']
cluster_config_spec.dpmConfig.defaultDpmBehavior = self.params['automation_level']
cluster_config_spec.dpmConfig.defaultDpmBehavior = self.automation_level

Check warning on line 181 in plugins/modules/cluster_dpm.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/cluster_dpm.py#L181

Added line #L181 was not covered by tests
cluster_config_spec.dpmConfig.hostPowerActionRate = self.recommendation_priority_threshold

return cluster_config_spec
Expand Down Expand Up @@ -199,8 +211,8 @@
enable=dict(type='bool', default=True),
automation_level=dict(
type='str',
choices=['automated', 'manual'],
default='automated'
choices=['automatic', 'manual'],
default='automatic'
),
recommendation_priority_threshold=dict(type='int', choices=[1, 2, 3, 4, 5], default=3)
)
Expand Down
Loading