Skip to content

Commit

Permalink
vmware_maintenancemode: Add support for check_mode (#1311)
Browse files Browse the repository at this point in the history
vmware_maintenancemode: Add support for check_mode

SUMMARY
Add support for check_mode to the vmware_maintenancemode module.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
vmware_maintenancemode
ADDITIONAL INFORMATION

Reviewed-by: Mario Lenz <[email protected]>
  • Loading branch information
jiuka authored May 7, 2022
1 parent 5f3ea63 commit d2123bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- vmware_maintenancemode - Add support for check_mode
(https://github.com/ansible-collections/community.vmware/pull/1311).
21 changes: 14 additions & 7 deletions plugins/modules/vmware_maintenancemode.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ def EnterMaintenanceMode(self):
spec.vsanMode.objectAction = self.vsan

try:
task = self.host.EnterMaintenanceMode_Task(self.module.params['timeout'],
self.module.params['evacuate'],
spec)
if not self.module.check_mode:
task = self.host.EnterMaintenanceMode_Task(self.module.params['timeout'],
self.module.params['evacuate'],
spec)

success, result = wait_for_task(task)
success, result = wait_for_task(task)
else:
success = True

self.module.exit_json(changed=success,
hostsystem=str(self.host),
Expand All @@ -156,9 +159,12 @@ def ExitMaintenanceMode(self):
msg='Host %s not in maintenance mode' % self.esxi_hostname)

try:
task = self.host.ExitMaintenanceMode_Task(self.module.params['timeout'])
if not self.module.check_mode:
task = self.host.ExitMaintenanceMode_Task(self.module.params['timeout'])

success, result = wait_for_task(task)
success, result = wait_for_task(task)
else:
success = True

self.module.exit_json(changed=success,
hostsystem=str(self.host),
Expand All @@ -184,7 +190,8 @@ def main():
)
)

module = AnsibleModule(argument_spec=spec)
module = AnsibleModule(argument_spec=spec,
supports_check_mode=True)

host_maintenance_mgr = VmwareMaintenanceMgr(module=module)

Expand Down

0 comments on commit d2123bb

Please sign in to comment.