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

Commit

Permalink
Place dockvols to datastore root. Fixed #449
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Sterin committed Jun 9, 2016
1 parent 762be39 commit 03d20d5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions esx_service/vmdk_ops.py
Expand Up @@ -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 <vm_datastore>/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.
Expand Down Expand Up @@ -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,
# "[<datastore name>] <parent-directory>/<vmdk-descriptor-name>".
# 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:
# "[<datastore name>] <parent-directory>/<vmdk-descriptor-name>"
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
Expand Down

0 comments on commit 03d20d5

Please sign in to comment.