Skip to content

Commit

Permalink
XenServer: Minor changes and fixes in xenserver_guest (ansible#55678)
Browse files Browse the repository at this point in the history
* XenServer: Minor changes and fixes in xenserver_guest

 - xenserver_guest module: ignore wait_for_ip_address when
   state=absent (fixes ansible#55348). Module docs are updated to reflect this.
 - xenserver_guest module: show proper error message when maximum number
   of network interfaces is reached and multiple network interfaces are
   added at once (fix for changes introduced in ansible#54697).
 - xenserver_guest module: fixed a bug in reconfigure() where VM would
   be powered off even though check mode is used when reconfiguration
   needs VM to be powered off.

* Added changelog fragment
  • Loading branch information
bvitnik authored and ansibot committed May 8, 2019
1 parent 5a6f888 commit 2a39dc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
minor_changes:
- xenserver_guest - wait_for_ip_address is now ignored when state=absent (https://github.com/ansible/ansible/issues/55348).

bugfixes:
- xenserver_guest - proper error message is shown when maximum number of network interfaces is reached and multiple network interfaces are added at once.
- xenserver_guest - fixed an issue where VM whould be powered off even though check mode is used if reconfiguration requires VM to be powered off.
15 changes: 8 additions & 7 deletions lib/ansible/modules/cloud/xenserver/xenserver_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
type: list
wait_for_ip_address:
description:
- Wait until XenServer detects an IP address for the VM.
- Wait until XenServer detects an IP address for the VM. If C(state) is set to C(absent), this parameter is ignored.
- This requires XenServer Tools to be preinstalled on the VM to work properly.
type: bool
default: no
Expand Down Expand Up @@ -597,16 +597,16 @@ def reconfigure(self):

vm_power_state_save = self.vm_params['power_state'].lower()

if "need_poweredoff" in config_changes and vm_power_state_save != 'halted':
if self.module.params['force']:
self.set_power_state("shutdownguest")
else:
self.module.fail_json(msg="VM reconfigure: VM has to be in powered off state to reconfigure but force was not specified!")
if "need_poweredoff" in config_changes and vm_power_state_save != 'halted' and not self.module.params['force']:
self.module.fail_json(msg="VM reconfigure: VM has to be in powered off state to reconfigure but force was not specified!")

# Support for Ansible check mode.
if self.module.check_mode:
return config_changes

if "need_poweredoff" in config_changes and vm_power_state_save != 'halted' and self.module.params['force']:
self.set_power_state("shutdownguest")

try:
for change in config_changes:
if isinstance(change, six.string_types):
Expand Down Expand Up @@ -1632,6 +1632,7 @@ def get_changes(self):
if vif_device not in vif_devices_allowed:
self.module.fail_json(msg="VM check networks[%s]: new network interface position %s is out of bounds!" % (position, vif_device))

vif_devices_allowed.remove(vif_device)
vif_device_highest = vif_device

# For new VIFs we only track their position.
Expand Down Expand Up @@ -1911,7 +1912,7 @@ def main():
vm.deploy()
result['changed'] = True

if module.params['wait_for_ip_address']:
if module.params['wait_for_ip_address'] and module.params['state'] != "absent":
vm.wait_for_ip_address()

result['instance'] = vm.gather_facts()
Expand Down

0 comments on commit 2a39dc8

Please sign in to comment.