ls_al
Contributor
Contributor

How to get VMs from datastore cluster?

Hi,

Im trying fetch VMs from specific storage pod (datastore cluster) using ContainerView and PropertyCollector (example code use rbvmomi but I think it's more generic question):

pc = @vim.serviceInstance.content.propertyCollector                                                                                                                            
viewmgr = @vim.serviceInstance.content.viewManager                                                                                                                                            
                                                                                                                                                                                                      
vmview = viewmgr.CreateContainerView({:container => pod_moref,                                                                                                                               
                                             :type => ['VirtualMachine'],                                                                                                                                         
                                             :recursive => true})                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                      
                                                                                                                                                                                                      
        filterSpec = RbVmomi::VIM.PropertyFilterSpec(                                                                                                                                                 
            :objectSet => [                                                                                                                                                                           
                :obj => vmview,                                                                                                                                                                       
                :skip => true,                                                                                                                                                                        
                :selectSet => [                                                                                                                                                                       
                    RbVmomi::VIM.TraversalSpec(                                                                                                                                                       
                        :name => "traverseEntities",                                                                                                                                                  
                        :type => "ContainerView",                                                                                                                                                     
                        :path => "view",                                                                                                                                                              
                        :skip => false                                                                                                                                                                
                    )]                                                                                                                                                                                
            ],                                                                                                                                                                                        
            :propSet => [                                                                                                                                                                             
                { :type => 'VirtualMachine', :pathSet => ['name']}                                                                                                                                                  
            ]                                                                                                                                                                                         
        )                                                                                                                                                                                             
                                                                                                                                                                                                      
                                                                                                                                                                                                      
        result = pc.RetrieveProperties(:specSet => [filterSpec])           

Unfortunately, I always get an empty result. If I create container view with container properties points to datacenter moref or host i got expected list of VMs.

For now I can get Datastores in pod (the same method as shown  but type set to 'Datastore') and then use on each datastore object vm method to get VMs reside on datastore, but I think there is one request method to do that.

0 Kudos
0 Replies