Skip to content

Commit

Permalink
vmware_guest_disk: Avoid using in maintenance DS (#1321)
Browse files Browse the repository at this point in the history
vmware_guest_disk: Avoid using in maintenance DS

The get_recommended_datastore from the vmware_guest_disk filters out
datastores using the one with the greater amount of free space.
However, it doesn't check the datastore status (eg. inMaintenance).
When running the task on an SDRS cluster, which have a datastore in
maintenance, and that datastore is the one with the greater amount of
free space, the module fails with a pyvmomi error like:
"This operation is not allowed in the current state of the datastore".
This commit ensure to skip the selection of in-maintenance datastores by
not even checking their size, and exclude them immediately.
SUMMARY
Avoid recommending in-maintenance datastores when trying to create
a disk with vmware_guest_disk.
(Not able to find issues reported for this error, but IIRC I've seen at least one
in the previous days...)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
vmware_guest_disk
ADDITIONAL INFORMATION
The get_recommended_datastore from the vmware_guest_disk filters out
datastores using the one with the greater amount of free space.
However, it doesn't check the datastore status (eg. inMaintenance).
When running the task on an SDRS cluster, which have a datastore in
maintenance, and that datastore is the one with the greater amount of
free space, the module fails with a pyvmomi error like:
"This operation is not allowed in the current state of the datastore".
This is because the recommended datastore is in-maintenance, and VMware
refuses to operate on a datastore with this state.
This commit ensure to skip the selection of in-maintenance datastores by
not even checking their size, and exclude them immediately.
Note that it may be required in other contexts such as :

https://github.com/ansible-collections/community.vmware/blob/main/plugins/module_utils/vmware.py#L1669
Used by https://github.com/ansible-collections/community.vmware/blob/main/plugins/modules/vmware_recommended_datastore.py#L90

Reviewed-by: Mario Lenz <[email protected]>
  • Loading branch information
Tireg authored Jun 17, 2022
1 parent 96cfc76 commit c673d75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- vmware_guest_disk - Ignore datastores in maintenance mode
(https://github.com/ansible-collections/community.vmware/pull/1321).
2 changes: 2 additions & 0 deletions plugins/modules/vmware_guest_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ def get_recommended_datastore(self, datastore_cluster_obj, disk_spec_obj):
datastore = None
datastore_freespace = 0
for ds in datastore_cluster_obj.childEntity:
if ds.summary.maintenanceMode == "inMaintenance":
continue
if ds.summary.freeSpace > datastore_freespace:
# If datastore field is provided, filter destination datastores
datastore = ds
Expand Down

0 comments on commit c673d75

Please sign in to comment.