0

If the virtual machine being searched for does not exist, the delay in returning output is about one minute. If the virtual machine being searched for does exist, the delay is about two seconds. I know I'm hitting a timeout value, but is there a quicker way to get to a search failure perhaps? We have very large vSphere environments, so things run fine in the lab, but prod ;)

def getobject(vimtype, name):
    obj = None
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    for c in container.view:
        if c.name == name:
            obj = c
            break
    return obj

vm = getobject([vim.VirtualMachine], "vm name")

print(vm)
markc
  • 1
  • 3

1 Answers1

0

I don't know for what purpose exactly you are using pyVmomi (Web API, GUI, CMD tool), but notice that you must consider the option to search VMs by their UUID, which takes 1-2 seconds approximately, even if the environment has thousand VMs.

You cant escape the time wait when you are iterating over 1000 VMs and searching for the specific VM by name.

It's like you will have not sorted array of 1000 numbers, and you are searching for the number 658, who knows where is that number, and when the array is growing the time is growing too.

Have notice to this code:

Searching for VM by UUID

Emanuel
  • 640
  • 1
  • 7
  • 25