I have a situation in which I have the name value of the VM in which I need to return the vCACVM object. I have found a solution that seems to be working, but wonder if there is a better way to achieve the same outcome.
As a side note, I am hoping someone would be able to provide a brief explanation on the substringof() eq "true" found in the code. I understand it is attempting to match the value supplied in vmName, and match it to the value being found in VirtualMachineName and if it returns true, that is the vCACVM I am looking for. I guess I am looking for a bit deeper understanding of the method, and perhaps some accompanying documentation explaining why it was available for use inside of Server.findAllForType().
Solution was derived from: https://communities.vmware.com/message/2622002#2622002.
Inputs:
vmName(string)
Attributes:
vcaccafehost(VCACCAFE:VCACHost)
Code:
var vm= Server.findAllForType("vCAC:VirtualMachine", "substringof('" + vmName + "',VirtualMachineName) eq true")
System.log("vCACObj: " + vm);
The second parameter of Server.findAllForType() is a plug-in-specific query. In this particular plug-in case, it is OData filter parameter.
You can check the documentation of substringof here - http://docs.oasis-open.org/odata/odata/v4.0/csprd01/part2-url-conventions/odata-v4.0-csprd01-part2-u...
In your code sample, the filter will look something like substringof('somename',VirtualMachineName) eq true , and this filter expression will match all entities whose VirtualMachineName property contains somename as a sub string, and so only these vms will be returned by Server.findAllForType() call.
The second parameter of Server.findAllForType() is a plug-in-specific query. In this particular plug-in case, it is OData filter parameter.
You can check the documentation of substringof here - http://docs.oasis-open.org/odata/odata/v4.0/csprd01/part2-url-conventions/odata-v4.0-csprd01-part2-u...
In your code sample, the filter will look something like substringof('somename',VirtualMachineName) eq true , and this filter expression will match all entities whose VirtualMachineName property contains somename as a sub string, and so only these vms will be returned by Server.findAllForType() call.
Great explanation and I appreciate the link to the documentation. Thank you.