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

vmware_guest_disk: Backport #1466 #1478

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- vmware_guest_disk - Adding `iolimit` modifications of an existing disk without changing size (https://github.com/ansible-collections/community.vmware/pull/1466).
32 changes: 28 additions & 4 deletions plugins/modules/vmware_guest_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def ensure_disks(self, vm_obj=None):
disk_change_list = list()
results = dict(changed=False, disk_data=None, disk_changes=dict())
new_added_disk_ctl = list()
sharesval = {'low': 500, 'normal': 1000, 'high': 2000}

# Deal with controller
for disk in disk_data:
Expand Down Expand Up @@ -696,6 +697,7 @@ def ensure_disks(self, vm_obj=None):
# Deal with Disks
for disk in disk_data:
disk_found = False
update_io = False
disk_change = False
ctl_found = False
for device in self.vm.config.hardware.device:
Expand All @@ -706,8 +708,27 @@ def ensure_disks(self, vm_obj=None):
disk_found = True
if disk['state'] == 'present':
disk_spec = vim.vm.device.VirtualDeviceSpec()
# set the operation to edit so that it knows to keep other settings
disk_spec.device = disk_device
# Deal with iolimit. Note that if iolimit is set, you HAVE TO both set limit and shares,
# or ansible will break with "'NoneType' object is not subscriptable"
if 'iolimit' in disk:
if disk['iolimit']['limit'] != disk_spec.device.storageIOAllocation.limit:
update_io = True

if 'shares' in disk['iolimit']:
# 'low', 'normal' and 'high' values in disk['iolimit']['shares']['level'] are converted to int values on vcenter side
if (disk['iolimit']['shares']['level'] != 'custom'
and sharesval.get(disk['iolimit']['shares']['level'], 0) != disk_spec.device.storageIOAllocation.shares.shares) or \
(disk['iolimit']['shares']['level'] == 'custom'
and disk['iolimit']['shares']['level_value'] != disk_spec.device.storageIOAllocation.shares.shares):
update_io = True

if update_io:
# set the operation to edit so that it knows to keep other settings
disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
disk_spec = self.get_ioandshares_diskconfig(disk_spec, disk)
disk_change = True

# If this is an RDM ignore disk size
if disk['disk_type'] != 'rdm':
if disk['size'] < disk_spec.device.capacityInKB:
Expand All @@ -716,14 +737,17 @@ def ensure_disks(self, vm_obj=None):
% (disk['disk_index'], disk['size'],
disk_spec.device.capacityInKB))
if disk['size'] != disk_spec.device.capacityInKB:
# set the operation to edit so that it knows to keep other settings
disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
if disk['disk_type'] != 'vpmemdisk':
disk_spec = self.get_ioandshares_diskconfig(disk_spec, disk)
disk_spec.device.capacityInKB = disk['size']
self.config_spec.deviceChange.append(disk_spec)
disk_change = True
disk_change_list.append(disk_change)
results['disk_changes'][disk['disk_index']] = "Disk reconfigured."

if disk_change:
self.config_spec.deviceChange.append(disk_spec)
disk_change_list.append(disk_change)
results['disk_changes'][disk['disk_index']] = "Disk reconfigured."

elif disk['state'] == 'absent':
# Disk already exists, deleting
Expand Down