Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing VirtualMachine->snapshot when there are not snapshots creates an infinite loop #9

Open
rgrwkmn opened this issue Nov 1, 2013 · 0 comments

Comments

@rgrwkmn
Copy link

rgrwkmn commented Nov 1, 2013

vm-123 has no snapshots.

$vm = $vhost->findOneManagedObject('VirtualMachine', 'vm-123');
$vm->snapshot; //infinite loop
$vm->hasSnapshots(); // tries to get $this->snapshot, infinite loop

The problem is that when there are no snapshots for the virtual machine, vSphere does not return a snapshot index at all. I verified this by inspecting the result from PropertyCollector->collectPropertiesFor. When it tries to access snapshot on that object it just starts the process all over again and loops until the maximum amount of nested function calls is reached.

Luckily, checking for the existence of snapshot with isset in Service->getQueriedProperty solves the issue:

    private function getQueriedProperty($method, $arguments) {
        $propertyToRetrieve = $this->generateNameForThePropertyToRetrieve($method);
        $content = $this->getServiceContent();
        if (isset($content->$propertyToRetrieve)) return $content->$propertyToRetrieve;
        $managedObject = $arguments[0];
        $foundManagedObject = $this->findOneManagedObject($managedObject->getReferenceType(),
            $managedObject->getReferenceId(), array($propertyToRetrieve));
        if (!isset($foundManagedObject->$propertyToRetrieve)) return null;
        return $foundManagedObject->$propertyToRetrieve;
    }

I'm going to make a pull request for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant