Class: RbVmomi::VIM::Folder
- Inherits:
-
Object
- Object
- RbVmomi::VIM::Folder
- Defined in:
- lib/rbvmomi/vim/Folder.rb
Instance Method Summary collapse
-
#children ⇒ Object
Alias to
childEntity
. -
#find(name, type = Object) ⇒ VIM::ManagedEntity
Retrieve a child entity.
-
#findByDnsName(name, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by DNS name.
-
#findByIp(ip, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by IP address.
-
#findByUuid(uuid, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by BIOS UUID.
-
#inventory(propSpecs = {}) ⇒ Hash
Efficiently retrieve properties from descendants of this folder.
-
#traverse(path, type = Object, create = false) ⇒ VIM::ManagedEntity
Retrieve a descendant of this Folder.
-
#traverse!(path, type = Object) ⇒ Object
Alias to
traverse path, type, true
.
Instance Method Details
#children ⇒ Object
Alias to childEntity
.
95 96 97 |
# File 'lib/rbvmomi/vim/Folder.rb', line 95 def children childEntity end |
#find(name, type = Object) ⇒ VIM::ManagedEntity
Retrieve a child entity
6 7 8 9 |
# File 'lib/rbvmomi/vim/Folder.rb', line 6 def find name, type=Object x = @soap.searchIndex.FindChild(:entity => self, :name => name) x if x.is_a? type end |
#findByDnsName(name, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by DNS name
16 17 18 19 20 21 22 23 24 |
# File 'lib/rbvmomi/vim/Folder.rb', line 16 def findByDnsName name, type=RbVmomi::VIM::VirtualMachine, dc=nil propSpecs = { :entity => self, :dnsName => name, :vmSearch => type == RbVmomi::VIM::VirtualMachine } propSpecs[:datacenter] = dc if dc x = @soap.searchIndex.FindByDnsName(propSpecs) x if x.is_a? type end |
#findByIp(ip, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by IP address
31 32 33 34 35 36 37 38 39 |
# File 'lib/rbvmomi/vim/Folder.rb', line 31 def findByIp ip, type=RbVmomi::VIM::VirtualMachine, dc=nil propSpecs = { :entity => self, :ip => ip, :vmSearch => type == RbVmomi::VIM::VirtualMachine } propSpecs[:datacenter] = dc if dc x = @soap.searchIndex.FindByIp(propSpecs) x if x.is_a? type end |
#findByUuid(uuid, type = RbVmomi::VIM::VirtualMachine, dc = nil) ⇒ VIM::ManagedEntity
Retrieve a virtual machine or host by BIOS UUID.
46 47 48 49 50 51 52 53 54 |
# File 'lib/rbvmomi/vim/Folder.rb', line 46 def findByUuid uuid, type=RbVmomi::VIM::VirtualMachine, dc=nil propSpecs = { :entity => self, :uuid => uuid, :instanceUuid => false, :vmSearch => type == RbVmomi::VIM::VirtualMachine } propSpecs[:datacenter] = dc if dc x = @soap.searchIndex.FindByUuid(propSpecs) x if x.is_a? type end |
#inventory(propSpecs = {}) ⇒ Hash
TODO:
Return ObjectContent instead of the leaf hash.
Efficiently retrieve properties from descendants of this folder.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rbvmomi/vim/Folder.rb', line 112 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 |
#traverse(path, type = Object, create = false) ⇒ VIM::ManagedEntity
TODO:
Move create
functionality into another method.
Retrieve a descendant of this Folder.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rbvmomi/vim/Folder.rb', line 68 def traverse path, type=Object, create=false if path.is_a? String es = path.split('/').reject(&:empty?) elsif path.is_a? Enumerable es = path else fail "unexpected path class #{path.class}" end return self if es.empty? final = es.pop p = es.inject(self) do |f,e| f.find(e, RbVmomi::VIM::Folder) || (create && f.CreateFolder(:name => e)) || return end if x = p.find(final, type) x elsif create and type == RbVmomi::VIM::Folder p.CreateFolder(:name => final) elsif create and type == RbVmomi::VIM::Datacenter p.CreateDatacenter(:name => final) else nil end end |
#traverse!(path, type = Object) ⇒ Object
Alias to traverse path, type, true
58 59 60 |
# File 'lib/rbvmomi/vim/Folder.rb', line 58 def traverse! path, type=Object traverse path, type, true end |