Class: RbVmomi::VIM::Datacenter

Inherits:
Object
  • Object
show all
Defined in:
lib/vmonkey/vim/Datacenter.rb

Instance Method Summary collapse

Instance Method Details

#find_pool(pool_path = '/') ⇒ Object

modified from knife-vsphere / base_vsphere_command.rb



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vmonkey/vim/Datacenter.rb', line 4

def find_pool(pool_path = '/')
  parent = self.hostFolder

  pool_path.split('/').each do |path_element|
    next if path_element == ''

    case parent
    when RbVmomi::VIM::Folder
      chilln = parent.childEntity
    when RbVmomi::VIM::ClusterComputeResource, RbVmomi::VIM::ComputeResource
      chilln = parent.resourcePool.resourcePool
    when RbVmomi::VIM::ResourcePool
      chilln = parent.resourcePool
    else
      parent = nil
      break
    end

    parent = chilln.find { |f| f.name == path_element }
  end

  unless parent.is_a?(RbVmomi::VIM::ResourcePool)
    if parent.respond_to?(:resourcePool)
      parent = parent.resourcePool
    end
  end

  parent
end