Permalink
Browse files

move PropertyCollector#pathsOfMany to ManagedEntity#paths and reuse t…

…hat in ManagedEntity#path
  • Loading branch information...
1 parent d8490cf commit 138f503e410aea7dc3fdd0aa5b355dfdfce3f336 Christian Dickmann committed Nov 10, 2011
Showing with 39 additions and 64 deletions.
  1. +38 −25 lib/rbvmomi/vim/ManagedEntity.rb
  2. +1 −39 lib/rbvmomi/vim/PropertyCollector.rb
@@ -2,39 +2,52 @@ class RbVmomi::VIM::ManagedEntity
# Retrieve the ancestors of the entity.
# @return [Array] Ancestors of this entity, starting with the root.
def path
+ self.class.paths([self])[self]
+ end
+
+ # Retrieve the ancestors of a list of entries.
+ # @return [Hash] Object-indexed hash of ancestors of entities, starting with the root.
+ def self.paths objs
+ i = 0
filterSpec = RbVmomi::VIM.PropertyFilterSpec(
- :objectSet => [{
- :obj => self,
- :selectSet => [
- RbVmomi::VIM.TraversalSpec(
- :name => 'tsME',
- :type => 'ManagedEntity',
- :path => 'parent',
- :skip => false,
- :selectSet => [
- RbVmomi::VIM.SelectionSpec(:name => 'tsME')
- ]
- )
- ]
- }],
+ :objectSet => objs.map do |obj|
+ i += 1
+ RbVmomi::VIM.ObjectSpec(
+ :obj => obj,
+ :selectSet => [
+ RbVmomi::VIM.TraversalSpec(
+ :name => "tsME-#{i}",
+ :type => 'ManagedEntity',
+ :path => 'parent',
+ :skip => false,
+ :selectSet => [
+ RbVmomi::VIM.SelectionSpec(:name => "tsME-#{i}")
+ ]
+ )
+ ]
+ )
+ end,
:propSet => [{
:pathSet => %w(name parent),
:type => 'ManagedEntity'
}]
)
- result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
+ propCollector = objs.first.propertyCollector
+ result = propCollector.RetrieveProperties(:specSet => [filterSpec])
- tree = {}
- result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
- a = []
- cur = self
- while cur
- parent, name = *tree[cur]
- a << [cur, name]
- cur = parent
- end
- a.reverse
+ Hash[objs.map do |obj|
+ tree = {}
+ result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
+ a = []
+ cur = obj
+ while cur
+ parent, name = *tree[cur]
+ a << [cur, name]
+ cur = parent
+ end
+ [obj, a.reverse]
+ end]
end
# Return a string representation of +path+ suitable for display.
@@ -24,44 +24,6 @@ def collectMultiple objs, *pathSet
end
def pathsOfMany objs
- i = 0
- filterSpec = RbVmomi::VIM.PropertyFilterSpec(
- :objectSet => objs.map do |obj|
- i += 1
- RbVmomi::VIM.ObjectSpec(
- :obj => obj,
- :selectSet => [
- RbVmomi::VIM.TraversalSpec(
- :name => "tsME-#{i}",
- :type => 'ManagedEntity',
- :path => 'parent',
- :skip => false,
- :selectSet => [
- RbVmomi::VIM.SelectionSpec(:name => "tsME-#{i}")
- ]
- )
- ]
- )
- end,
- :propSet => [{
- :pathSet => %w(name parent),
- :type => 'ManagedEntity'
- }]
- )
-
- result = self.RetrieveProperties(:specSet => [filterSpec])
-
- Hash[objs.map do |obj|
- tree = {}
- result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
- a = []
- cur = obj
- while cur
- parent, name = *tree[cur]
- a << [cur, name]
- cur = parent
- end
- [obj, a.reverse]
- end]
+ RbVmomi::VIM::ManagedEntity.paths objs
end
end

0 comments on commit 138f503

Please sign in to comment.