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

Commit

Permalink
Use SearchIndex and Find* methods for VM-Name <-> UUID conversion. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pdhamdhere authored Mar 29, 2017
1 parent aac06cd commit b15c20b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions esx_service/utils/vmdk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import auth
import auth_data_const

import pyVim
from pyVim.invt import GetVmFolder, FindChild

# datastores should not change during 'vmdkops_admin' run,
# so using global to avoid multiple scans of /vmfs/volumes
datastores = None
Expand Down Expand Up @@ -274,26 +277,25 @@ def get_vm_uuid_by_name(vm_name):
""" Returns vm_uuid for given vm_name, or None """
si = vmdk_ops.get_si()
try:
vm = [d for d in si.content.rootFolder.childEntity[0].vmFolder.childEntity if d.config.name == vm_name]
return vm[0].config.uuid
vm = FindChild(GetVmFolder(), vm_name)
return vm.config.uuid
except:
return None

def get_vm_name_by_uuid(vm_uuid):
""" Returns vm_name for given vm_uuid, or None """
si = vmdk_ops.get_si()
try:
vm = [d for d in si.content.rootFolder.childEntity[0].vmFolder.childEntity if d.config.uuid == vm_uuid]
return vm[0].config.name
return vmdk_ops.vm_uuid2name(vm_uuid)
except:
return None

def get_vm_config_path(vm_name):
"""Returns vm_uuid for given vm_name, or None """
si = vmdk_ops.get_si()
try:
vm = [d for d in si.content.rootFolder.childEntity[0].vmFolder.childEntity if d.config.name == vm_name]
config_path = vm[0].summary.config.vmPathName
vm = FindChild(GetVmFolder(), vm_name)
config_path = vm.summary.config.vmPathName
except:
return None

Expand Down

0 comments on commit b15c20b

Please # to comment.