Skip to content

Commit

Permalink
move PropertyCollector#pathsOfMany to ManagedEntity#paths and reuse t…
Browse files Browse the repository at this point in the history
…hat in ManagedEntity#path
  • Loading branch information
cdickmann committed Nov 10, 2011
1 parent 47f7aa8 commit 769260b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 64 deletions.
63 changes: 38 additions & 25 deletions lib/rbvmomi/vim/ManagedEntity.rb
Expand Up @@ -2,39 +2,52 @@ class RbVmomi::VIM::ManagedEntity
# Retrieve the ancestors of the entity. # Retrieve the ancestors of the entity.
# @return [Array] Ancestors of this entity, starting with the root. # @return [Array] Ancestors of this entity, starting with the root.
def path 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( filterSpec = RbVmomi::VIM.PropertyFilterSpec(
:objectSet => [{ :objectSet => objs.map do |obj|
:obj => self, i += 1
:selectSet => [ RbVmomi::VIM.ObjectSpec(
RbVmomi::VIM.TraversalSpec( :obj => obj,
:name => 'tsME', :selectSet => [
:type => 'ManagedEntity', RbVmomi::VIM.TraversalSpec(
:path => 'parent', :name => "tsME-#{i}",
:skip => false, :type => 'ManagedEntity',
:selectSet => [ :path => 'parent',
RbVmomi::VIM.SelectionSpec(:name => 'tsME') :skip => false,
] :selectSet => [
) RbVmomi::VIM.SelectionSpec(:name => "tsME-#{i}")
] ]
}], )
]
)
end,
:propSet => [{ :propSet => [{
:pathSet => %w(name parent), :pathSet => %w(name parent),
:type => 'ManagedEntity' :type => 'ManagedEntity'
}] }]
) )


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


tree = {} Hash[objs.map do |obj|
result.each { |x| tree[x.obj] = [x['parent'], x['name']] } tree = {}
a = [] result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
cur = self a = []
while cur cur = obj
parent, name = *tree[cur] while cur
a << [cur, name] parent, name = *tree[cur]
cur = parent a << [cur, name]
end cur = parent
a.reverse end
[obj, a.reverse]
end]
end end


# Return a string representation of +path+ suitable for display. # Return a string representation of +path+ suitable for display.
Expand Down
40 changes: 1 addition & 39 deletions lib/rbvmomi/vim/PropertyCollector.rb
Expand Up @@ -24,44 +24,6 @@ def collectMultiple objs, *pathSet
end end


def pathsOfMany objs def pathsOfMany objs
i = 0 RbVmomi::VIM::ManagedEntity.paths objs
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]
end end
end end

0 comments on commit 769260b

Please sign in to comment.