I am currently using the marvelous listVMByFolder script (http://communities.vmware.com/docs/DOC-10059), and I would like to know how I can retrieve the power status of each VM I list. I have been using the Perl SDK for about 2 days (yeah, it is not a lot), and while I understand how I would do "normally", I do not figure out how to retrieve this information while being in such a statement :
if ( $child_view->isa("VirtualMachine") )
# Some code here
How can I retrieve this information since I am not really working on a VM object, like I would find in any tutorial out there, like something like this :
my $vms = Vim::find_entity_views(view_type => 'VirtualMachine');
print "VM: " . $_->config->name . ", powerstate: " . $_->runtime->powerState->val . "\n";
Thank you very much and have a nice day !
That's an old one I wrote
In that script, the generic child_view call is just a cheap, fast way to get the name and object type. I cheat a bit and use a common property 'name' in the Vim:get_view() call to do a the printing on both folders and VMs.
But if you wanted the VM power state, you would have to get the power state property as well. Not the most efficient way of getting the data, but should work without major script rework (should work not tested, but idea is sound) --
You could also check the MOREF type and have an if around the call to get the $child_view (if VirtualMachine, then call get_view with the runtime.powerstate, if not, just call 'name').