Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Handling dockvols symlink on vsanDatastore to update volume status on…
Browse files Browse the repository at this point in the history
… VM poweroff event (#1235)

* Handling dockvols symlink on vsanDatastore to update volume status on VM poweroff event
  • Loading branch information
Shahzeb Patel authored May 10, 2017
1 parent d0620dc commit 0577889
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions esx_service/utils/vmdk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand All @@ -342,15 +345,20 @@ def find_dvs_volume(dev):
# Filename format is as follows:
# "[<datastore name>] <parent-directory>/tenant/<vmdk-descriptor-name>"
# 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

Expand Down

0 comments on commit 0577889

Please sign in to comment.