diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index bb9063db4..fe61825dc 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -331,9 +331,10 @@ def detachVMDK(vmdk_path, vm_name): # Check existence (and creates if needed) the path def getVolPath(vm_config_path): - # The volumes folder is created in the parent of the given VM's folder. - path = os.path.join( - os.path.dirname(os.path.dirname(vm_config_path)), DOCK_VOLS_DIR) + # The folder for Docker volumes is created on /DOCK_VOLS_DIR + # On ESX the path is always /vmfs/volume/datastore/... , so we can do this: + vm_datastore = "/".join(vm_config_path.split("/")[0:4]) + path = os.path.join(vm_datastore, DOCK_VOLS_DIR) if os.path.isdir(path): # If the path exists then return it as is. @@ -404,23 +405,22 @@ def connectLocal(): def findDeviceByPath(vmdk_path, vm): - for d in vm.config.hardware.device: if type(d) != vim.vm.device.VirtualDisk: continue -# Disks of all backing have a backing object with -# a filename attribute in it. The filename identifies the -# virtual disk by name and can be used to try a match -# with the given name. Filename has format like, -# "[] /". + # Disks of all backing have a backing object with a filename attribute. + # The filename identifies the virtual disk by name and can be used + # to match with the given name. + # Filename format is as follows: + # "[] /" backing_disk = d.backing.fileName.split(" ")[1] # Construct the parent dir and vmdk name, resolving # links if any. dvol_dir = os.path.dirname(vmdk_path) real_vol_dir = os.path.basename(os.path.realpath(dvol_dir)) - virtual_disk = real_vol_dir + "/" + os.path.basename(vmdk_path) + virtual_disk = os.path.join(real_vol_dir, os.path.basename(vmdk_path)) if virtual_disk == backing_disk: logging.debug("findDeviceByPath: MATCH: %s", backing_disk) return d