lib/vmreverter/hypervisor/vsphere_helper.rb
# an easier wrapper around the horrid PropertyCollector interface,
# necessary for searching VMs in all Datacenters that may be nested
# within folders of arbitrary depth
# returns a hash array of <name> => <VirtualMachine ManagedObjects>
an easier wrapper around the horrid PropertyCollector interface,
necessary for searching VMs in all Datacenters that may be nested
within folders of arbitrary depth
returns a hash array of  => 
an easier wrapper around the horrid PropertyCollector interface necessary for searching VMs in all Datacenters that may be nested within folders of arbitrary depth returns a hash array of = >
def find_vms names, connection = @connection
    names = names.is_a?(Array) ? names : [ names ]
    containerView = get_base_vm_container_from connection
    propertyCollector = connection.propertyCollector
    objectSet = [{
      :obj => containerView,
      :skip => true,
      :selectSet => [ RbVmomi::VIM::TraversalSpec.new({
          :name => 'gettingTheVMs',
          :path => 'view',
          :skip => false,
          :type => 'ContainerView'
      }) ]
    }]
    propSet = [{
      :pathSet => [ 'name' ],
      :type => 'VirtualMachine'
    }]
    results = propertyCollector.RetrievePropertiesEx({
      :specSet => [{
        :objectSet => objectSet,
        :propSet   => propSet
      }],
      :options => { :maxObjects => nil }
    })
    vms = {}
    results.objects.each do |result|
      name = result.propSet.first.val
      next unless names.include? name
      vms[name] = result.obj
    end
    while results.token do
      results = propertyCollector.ContinueRetrievePropertiesEx({:token => results.token})
      results.objects.each do |result|
        name = result.propSet.first.val
        next unless names.include? name
        vms[name] = result.obj
      end
    end
    vms
  end
def find_vms names , connection = @connection names = names . is_a? ( Array ) ? names : [ names ] containerView = get_base_vm_container_from connection propertyCollector = connection . propertyCollector objectSet = [ { :obj => containerView , :skip => true , :selectSet => [ RbVmomi :: VIM :: TraversalSpec . new ( { :name => 'gettingTheVMs' , :path => 'view' , :skip => false , :type => 'ContainerView' } ) ] } ] propSet = [ { :pathSet => [ 'name' ] , :type => 'VirtualMachine' } ] results = propertyCollector . RetrievePropertiesEx ( { :specSet => [ { :objectSet => objectSet , :propSet => propSet } ] , :options => { :maxObjects => nil } } ) vms = { } results . objects . each do | result | name = result . propSet . first . val next unless names . include? name vms [ name ] = result . obj end while results . token do results = propertyCollector . ContinueRetrievePropertiesEx ( { :token => results . token } ) results . objects . each do | result | name = result . propSet . first . val next unless names . include? name vms [ name ] = result . obj end end vms end
an easier wrapper around the horrid PropertyCollector interface,
necessary for searching VMs in all Datacenters that may be nested
within folders of arbitrary depth
returns a hash array of <name> => <VirtualMachine ManagedObjects>
an easier wrapper around the horrid PropertyCollector interface necessary for searching VMs in all Datacenters that may be nested within folders of arbitrary depth returns a hash array of <name > = > <VirtualMachine ManagedObjects >
names
<not_specific>
connection
<not_specific>