From 4ac92c97a3d1e1d93d49bd006f771e3eb7e0a7ee Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 6 Feb 2018 17:04:53 +0530 Subject: [PATCH] VMware: Detect SDRS for datastore cluster (#35644) This fix adds a fallback mechanism where Storage Datacluster is not enabled with SDRS. If user has Storage Datacluster without SDRS then we will not get any datastore recommendation. This will fallback to normal datastore selection method. Signed-off-by: Abhijeet Kasurde --- .../modules/cloud/vmware/vmware_guest.py | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index e46974ebabf..22514415812 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1303,20 +1303,33 @@ class PyVmomiHelper(PyVmomi): """ if datastore_cluster_obj is None: return None - pod_sel_spec = vim.storageDrs.PodSelectionSpec() - pod_sel_spec.storagePod = datastore_cluster_obj - storage_spec = vim.storageDrs.StoragePlacementSpec() - storage_spec.podSelectionSpec = pod_sel_spec - storage_spec.type = 'create' + # Check if Datastore Cluster provided by user is SDRS ready + sdrs_status = datastore_cluster_obj.podStorageDrsEntry.storageDrsConfig.podConfig.enabled + if sdrs_status: + # We can get storage recommendation only if SDRS is enabled on given datastorage cluster + pod_sel_spec = vim.storageDrs.PodSelectionSpec() + pod_sel_spec.storagePod = datastore_cluster_obj + storage_spec = vim.storageDrs.StoragePlacementSpec() + storage_spec.podSelectionSpec = pod_sel_spec + storage_spec.type = 'create' - try: - rec = self.content.storageResourceManager.RecommendDatastores(storageSpec=storage_spec) - rec_action = rec.recommendations[0].action[0] - real_datastore_name = rec_action.destination.name - except Exception as e: - # There is some error so we fall back to general workflow - return None - return real_datastore_name + try: + rec = self.content.storageResourceManager.RecommendDatastores(storageSpec=storage_spec) + rec_action = rec.recommendations[0].action[0] + return rec_action.destination.name + except Exception as e: + # There is some error so we fall back to general workflow + pass + datastore = None + datastore_freespace = 0 + for ds in datastore_cluster_obj.childEntity: + if isinstance(ds, vim.Datastore) and ds.summary.freeSpace > datastore_freespace: + # If datastore field is provided, filter destination datastores + datastore = ds + datastore_freespace = ds.summary.freeSpace + if datastore: + return datastore.name + return None def select_datastore(self, vm_obj=None): datastore = None