server/lib/deltacloud/drivers/vsphere/vsphere_client.rb
# This helper will traverse across all datacenters and datastores and gather
# all virtual machines available on vSphere
#
This helper will traverse across all datacenters and datastores and gather
all virtual machines available on vSphere
This helper will traverse across all datacenters and datastores and gather all virtual machines available on vSphere
def list_virtual_machines(credentials)
      vsphere = new_client(credentials)
      vms = []
      rootFolder = vsphere.serviceInstance.content.rootFolder
      rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).each do |dc|
        list_datastores(dc.datastoreFolder).each do  |datastore|
          if datastore.class == RbVmomi::VIM::StoragePod
            storagepod_name = datastore.summary['name']
            vms += datastore.childEntity.grep(RbVmomi::VIM::VirtualMachine).collect { |vm| { :instance => vm, :datastore => storagepod_name } }
          else
            vms += datastore.vm.collect { |vm| { :instance => vm, :datastore => datastore.name } unless vm.nil? }
            stored_tasks(datastore, vsphere) do |task|
              if task.info.entity.class == RbVmomi::VIM::VirtualMachine
                vms << { :stored_instance => load_serialized_instance(datastore, task.info.key), :datastore => datastore.name }
              end
            end
          end
        end
      end
      vms.flatten.compact
    end
def list_virtual_machines ( credentials ) vsphere = new_client ( credentials ) vms = [ ] rootFolder = vsphere . serviceInstance . content . rootFolder rootFolder . childEntity . grep ( RbVmomi :: VIM :: Datacenter ) . each do | dc | list_datastores ( dc . datastoreFolder ) . each do | datastore | if datastore . class == RbVmomi :: VIM :: StoragePod storagepod_name = datastore . summary [ 'name' ] vms += datastore . childEntity . grep ( RbVmomi :: VIM :: VirtualMachine ) . collect { | vm | { :instance => vm , :datastore => storagepod_name } } else vms += datastore . vm . collect { | vm | { :instance => vm , :datastore => datastore . name } unless vm . nil? } stored_tasks ( datastore , vsphere ) do | task | if task . info . entity . class == RbVmomi :: VIM :: VirtualMachine vms << { :stored_instance => load_serialized_instance ( datastore , task . info . key ) , :datastore => datastore . name } end end end end end vms . flatten . compact end
This helper will traverse across all datacenters and datastores and gather
all virtual machines available on vSphere
This helper will traverse across all datacenters and datastores and gather all virtual machines available on vSphere
credentials
<not_specific>