From 0577889da5a5bee63f507248fcf8e99240cbf923 Mon Sep 17 00:00:00 2001 From: Shahzeb Patel Date: Wed, 10 May 2017 13:32:14 -0700 Subject: [PATCH] Handling dockvols symlink on vsanDatastore to update volume status on VM poweroff event (#1235) * Handling dockvols symlink on vsanDatastore to update volume status on VM poweroff event --- esx_service/utils/vmdk_utils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/esx_service/utils/vmdk_utils.py b/esx_service/utils/vmdk_utils.py index fdec554dd..77bcac1bc 100644 --- a/esx_service/utils/vmdk_utils.py +++ b/esx_service/utils/vmdk_utils.py @@ -64,6 +64,9 @@ VMDK_RETRY_COUNT = 5 VMDK_RETRY_SLEEP = 1 +# root for all the volumes +VOLUME_ROOT = "/vmfs/volumes/" + # For managing resource locks. lockManager = threadutils.LockManager() @@ -333,7 +336,7 @@ def get_vm_config_path(vm_name): def find_dvs_volume(dev): """ - If the @param dev is a dvs managed volume, return its vmdk path + If the @param dev (type is vim.vm.device) a vDVS managed volume, return its vmdk path """ # if device is not a virtual disk, skip this device if type(dev) != vim.vm.device.VirtualDisk: @@ -342,15 +345,20 @@ def find_dvs_volume(dev): # Filename format is as follows: # "[] /tenant/" # Trim the datastore name and keep disk path. - datastore, disk_path = dev.backing.fileName.rsplit("]", 1) + datastore_name, disk_path = dev.backing.fileName.rsplit("]", 1) logging.info("backing disk name is %s", disk_path) # name formatting to remove unwanted characters - datastore = datastore[1:] + datastore_name = datastore_name[1:] disk_path = disk_path.lstrip() - if disk_path.startswith(vmdk_ops.DOCK_VOLS_DIR): - # returning the vmdk path for dvs volume - return os.path.join("/vmfs/volumes/", datastore, disk_path) + # find the dockvols dir on current datastore and resolve symlinks if any + dvol_dir_path = os.path.realpath(os.path.join(VOLUME_ROOT, + datastore_name, vmdk_ops.DOCK_VOLS_DIR)) + dvol_dir = os.path.basename(dvol_dir_path) + + if disk_path.startswith(dvol_dir): + # returning the vmdk path for vDVS volume + return os.path.join(VOLUME_ROOT, datastore_name, disk_path) return None