Class: RbVmomi::VIM::ManagedEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvmomi/vim/ManagedEntity.rb

Overview

Copyright © 2011-2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MIT

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.paths(objs) ⇒ Hash

Retrieve the ancestors of a list of entries.

Returns:

  • (Hash)

    Object-indexed hash of ancestors of entities, starting with the root.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rbvmomi/vim/ManagedEntity.rb', line 13

def self.paths objs
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
    :objectSet => objs.map do |obj|
      RbVmomi::VIM.ObjectSpec(
        :obj => obj,
        :selectSet => [
          RbVmomi::VIM.TraversalSpec(
            :name => "tsME",
            :type => 'ManagedEntity',
            :path => 'parent',
            :skip => false,
            :selectSet => [
              RbVmomi::VIM.SelectionSpec(:name => "tsME")
            ]
          )
        ]
      )
    end,
    :propSet => [{
      :pathSet => %w(name parent),
      :type => 'ManagedEntity'
    }]
  )

  propCollector = objs.first._connection.propertyCollector
  result = propCollector.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

Instance Method Details

#pathArray

Retrieve the ancestors of the entity.

Returns:

  • (Array)

    Ancestors of this entity, starting with the root.



7
8
9
# File 'lib/rbvmomi/vim/ManagedEntity.rb', line 7

def path
  self.class.paths([self])[self]
end

#pretty_pathString

Return a string representation of path suitable for display.

Returns:

See Also:



57
58
59
# File 'lib/rbvmomi/vim/ManagedEntity.rb', line 57

def pretty_path
  path[1..-1].map { |x| x[1] } * '/'
end