Added poweroff_guest vm and reboot_guest vm in vsphere_guest (#34348)

pull/37908/head
Heusini 7 years ago committed by Abhijeet Kasurde
parent adbda67151
commit 702b5a3e81

@ -64,7 +64,7 @@ options:
- Indicate desired state of the vm. 'reconfigured' only applies changes to 'vm_cdrom', 'memory_mb', and 'num_cpus' in vm_hardware parameter. - Indicate desired state of the vm. 'reconfigured' only applies changes to 'vm_cdrom', 'memory_mb', and 'num_cpus' in vm_hardware parameter.
The 'memory_mb' and 'num_cpus' changes are applied to powered-on vms when hot-plugging is enabled for the guest. The 'memory_mb' and 'num_cpus' changes are applied to powered-on vms when hot-plugging is enabled for the guest.
default: present default: present
choices: ['present', 'powered_off', 'absent', 'powered_on', 'restarted', 'reconfigured'] choices: ['present', 'powered_off', 'absent', 'powered_on', 'restarted', 'reconfigured', 'reboot_guest', 'poweroff_guest']
from_template: from_template:
version_added: "1.9" version_added: "1.9"
description: description:
@ -1537,10 +1537,27 @@ def power_state(vm, state, force):
try: try:
if state == 'powered_off': if state == 'powered_off':
vm.power_off(sync_run=True) vm.power_off(sync_run=True)
elif state == 'poweroff_guest':
if power_status in ('POWERED ON'):
vm.shutdown_guest()
elif power_status in ('POWERED OFF'):
return False
else:
return "Cannot poweroff_guest VM in the current state %s" \
% power_status
elif state == 'powered_on': elif state == 'powered_on':
vm.power_on(sync_run=True) vm.power_on(sync_run=True)
elif state == 'reboot_guest':
if power_status in ('POWERED ON'):
vm.reboot_guest()
elif power_status in ('POWERED OFF'):
vm.power_on(sync_run=True)
else:
return "Cannot reboot_guest VM in the current state %s" \
% power_status
elif state == 'restarted': elif state == 'restarted':
if power_status in ('POWERED ON', 'POWERING ON', 'RESETTING'): if power_status in ('POWERED ON', 'POWERING ON', 'RESETTING'):
vm.reset(sync_run=False) vm.reset(sync_run=False)
@ -1715,7 +1732,9 @@ def main():
'present', 'present',
'absent', 'absent',
'restarted', 'restarted',
'reconfigured' 'reconfigured',
'reboot_guest',
'poweroff_guest'
], ],
default='present'), default='present'),
vmware_guest_facts=dict(required=False, type='bool'), vmware_guest_facts=dict(required=False, type='bool'),
@ -1812,7 +1831,7 @@ def main():
module.fail_json(msg="Fact gather failed with exception %s" module.fail_json(msg="Fact gather failed with exception %s"
% to_native(e), exception=traceback.format_exc()) % to_native(e), exception=traceback.format_exc())
# Power Changes # Power Changes
elif state in ['powered_on', 'powered_off', 'restarted']: elif state in ['powered_on', 'powered_off', 'restarted', 'reboot_guest', 'poweroff_guest']:
state_result = power_state(vm, state, force) state_result = power_state(vm, state, force)
# Failure # Failure

Loading…
Cancel
Save