lib/rbvmomi/vim/Folder.rb
def inventory propSpecs={}
    propSet = [{ :type => 'Folder', :pathSet => ['name', 'parent'] }]
    propSpecs.each do |k,v|
      case k
      when RbVmomi::VIM::ManagedEntity
        k = k.wsdl_name
      when Symbol, String
        k = k.to_s
      else
        fail "key must be a ManagedEntity"
      end

      h = { :type => k }
      if v == :all
        h[:all] = true
      elsif v.is_a? Array
        h[:pathSet] = v + %w(parent)
      else
        fail "value must be an array of property paths or :all"
      end
      propSet << h
    end

    filterSpec = RbVmomi::VIM.PropertyFilterSpec(
      :objectSet => [
        :obj => self,
        :selectSet => [
          RbVmomi::VIM.TraversalSpec(
            :name => 'tsFolder',
            :type => 'Folder',
            :path => 'childEntity',
            :skip => false,
            :selectSet => [
              RbVmomi::VIM.SelectionSpec(:name => 'tsFolder')
            ]
          )
        ]
      ],
      :propSet => propSet
    )

    result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])

    tree = { self => {} }
    result.each do |x|
      obj = x.obj
      next if obj == self
      h = Hash[x.propSet.map { |y| [y.name, y.val] }]
      tree[h['parent']][h['name']] = [obj, h]
      tree[obj] = {} if obj.is_a? RbVmomi::VIM::Folder
    end
    tree
  end
# Efficiently retrieve properties from descendants of this folder.
#
# @param propSpecs [Hash] Specification of which properties to retrieve from
#                         which entities. Keys may be symbols, strings, or
#                         classes identifying ManagedEntity subtypes to be
#                         included in the results. Values are an array of
#                         property paths (strings) or the symbol :all.
#
# @return [Hash] Tree of inventory items. Folders are hashes from child name
#                to child result. Objects are hashes from property path to
#                value.
#
# @todo Return ObjectContent instead of the leaf hash.
Efficiently retrieve properties from descendants of this folder.
Efficiently retrieve properties from descendants of this folder .
def inventory propSpecs={}
    propSet = [{ :type => 'Folder', :pathSet => ['name', 'parent'] }]
    propSpecs.each do |k,v|
      case k
      when RbVmomi::VIM::ManagedEntity
        k = k.wsdl_name
      when Symbol, String
        k = k.to_s
      else
        fail "key must be a ManagedEntity"
      end
      h = { :type => k }
      if v == :all
        h[:all] = true
      elsif v.is_a? Array
        h[:pathSet] = v + %w(parent)
      else
        fail "value must be an array of property paths or :all"
      end
      propSet << h
    end
    filterSpec = RbVmomi::VIM.PropertyFilterSpec(
      :objectSet => [
        :obj => self,
        :selectSet => [
          RbVmomi::VIM.TraversalSpec(
            :name => 'tsFolder',
            :type => 'Folder',
            :path => 'childEntity',
            :skip => false,
            :selectSet => [
              RbVmomi::VIM.SelectionSpec(:name => 'tsFolder')
            ]
          )
        ]
      ],
      :propSet => propSet
    )
    result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
    tree = { self => {} }
    result.each do |x|
      obj = x.obj
      next if obj == self
      h = Hash[x.propSet.map { |y| [y.name, y.val] }]
      tree[h['parent']][h['name']] = [obj, h]
      tree[obj] = {} if obj.is_a? RbVmomi::VIM::Folder
    end
    tree
  end
def inventory propSpecs = { } propSet = [ { :type => 'Folder' , :pathSet => [ 'name' , 'parent' ] } ] propSpecs . each do | k , v | case k when RbVmomi :: VIM :: ManagedEntity k = k . wsdl_name when Symbol , String k = k . to_s else fail "key must be a ManagedEntity" end h = { :type => k } if v == :all h [ :all ] = true elsif v . is_a? Array h [ :pathSet ] = v + %w( parent ) else fail "value must be an array of property paths or :all" end propSet << h end filterSpec = RbVmomi :: VIM . PropertyFilterSpec ( :objectSet => [ :obj => self , :selectSet => [ RbVmomi :: VIM . TraversalSpec ( :name => 'tsFolder' , :type => 'Folder' , :path => 'childEntity' , :skip => false , :selectSet => [ RbVmomi :: VIM . SelectionSpec ( :name => 'tsFolder' ) ] ) ] ] , :propSet => propSet ) result = @soap . propertyCollector . RetrieveProperties ( :specSet => [ filterSpec ] ) tree = { self => { } } result . each do | x | obj = x . obj next if obj == self h = Hash [ x . propSet . map { | y | [ y . name , y . val ] } ] tree [ h [ 'parent' ] ] [ h [ 'name' ] ] = [ obj , h ] tree [ obj ] = { } if obj . is_a? RbVmomi :: VIM :: Folder end tree end
Efficiently retrieve properties from descendants of this folder.
Efficiently retrieve properties from descendants of this folder .
Tree of inventory items. Folders are hashes from child name to child result. Objects are hashes from property path to value.
Tree of inventory items . Folders are hashes from child name to child result . Objects are hashes from property path to value .
Hash
propSpecs
Specification of which properties to retrieve from which entities. Keys may be symbols, strings, or classes identifying ManagedEntity subtypes to be included in the results. Values are an array of property paths (strings) or the symbol :all.
Specification of which properties to retrieve from which entities . Keys may be symbols strings or classes identifying ManagedEntity subtypes to be included in the results . Values are an array of property paths ( strings ) or the symbol : all .
todo
Return ObjectContent instead of the leaf hash.
Return ObjectContent instead of the leaf hash .