moved code that gets the vm's current hard drive profile and checks if vm_disk definition count is higher than actual vm drive count out of for loop for efficiency

reviewable/pr18780/r1
Sebastien Couture 9 years ago
parent 080b158a29
commit 22b6e6a0ce

@ -861,6 +861,13 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
# Resize hard drives # Resize hard drives
if vm_disk: if vm_disk:
spec = spec_singleton(spec, request, vm) spec = spec_singleton(spec, request, vm)
# Get a list of the VM's hard drives
dev_list = [d for d in vm.properties.config.hardware.device if d._type=='VirtualDisk']
if len(vm_disk) > len(dev_list):
vsphere_client.disconnect()
module.fail_json(msg="Error in vm_disk definition. Too many disks defined in comparison to the VM's disk profile.")
disk_num = 0 disk_num = 0
dev_changes = [] dev_changes = []
disks_changed = {} disks_changed = {}
@ -872,12 +879,6 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
except (KeyError, ValueError): except (KeyError, ValueError):
vsphere_client.disconnect() vsphere_client.disconnect()
module.fail_json(msg="Error in '%s' definition. Size needs to be specified as an integer." % disk) module.fail_json(msg="Error in '%s' definition. Size needs to be specified as an integer." % disk)
# Get a list of the hard drives
dev_list = [d for d in vm.properties.config.hardware.device if d._type=='VirtualDisk']
if disk_num >= len(dev_list):
vsphere_client.disconnect()
module.fail_json(msg="Error in '%s' definition. Too many disks defined in comparison to the VM's disk profile." % disk)
# Make sure the new disk size is higher than the current value # Make sure the new disk size is higher than the current value
dev = dev_list[disk_num] dev = dev_list[disk_num]
@ -901,7 +902,7 @@ def reconfigure_vm(vsphere_client, vm, module, esxi, resource_pool, cluster_name
spec.set_element_deviceChange(dev_changes) spec.set_element_deviceChange(dev_changes)
changes['disks'] = disks_changed changes['disks'] = disks_changed
if len(changes): if len(changes):
if shutdown and vm.is_powered_on(): if shutdown and vm.is_powered_on():

Loading…
Cancel
Save