From 5c8649d384a7ab0355f3c4a0ceaf1feb93ff07c8 Mon Sep 17 00:00:00 2001 From: Marknl Date: Fri, 23 Jun 2017 10:56:25 +0200 Subject: [PATCH] Added search for InstanceUuid In a situation where you have multiple hosts with the same name, you can only find one with the current code. The global unique identifier for the hosts is the instanceUuid within the VirtualMachineConfigInfo object. You can use this one to find the specific host. --- library/Vmwarephp/Service.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/Vmwarephp/Service.php b/library/Vmwarephp/Service.php index 52030ed..76d349c 100644 --- a/library/Vmwarephp/Service.php +++ b/library/Vmwarephp/Service.php @@ -42,6 +42,15 @@ function findManagedObjectByName($objectType, $name, $propertiesToCollect = arra }); return empty($objects) ? null : end($objects); } + + function findManagedObjectByInstanceUuid($objectType, $uuid, $propertiesToCollect = array()) { + $propertiesToCollect = array_merge($propertiesToCollect, ['config']); + $allObjects = $this->findAllManagedObjects($objectType, $propertiesToCollect); + $objects = array_filter($allObjects, function ($object) use ($uuid) { + return $object->config->instanceUuid == $uuid; + }); + return empty($objects) ? null : end($objects); + } function connect() { if ($this->session) {