Class: RbVmomi::VIM::ManagedObject

Inherits:
ObjectWithMethods show all
Defined in:
lib/rbvmomi/types.rb,
lib/rbvmomi/extensions.rb

Instance Method Summary collapse

Methods inherited from ObjectWithMethods

full_methods_desc, initialize

Methods inherited from ObjectWithProperties

find_prop_desc, full_props_desc, initialize

Methods inherited from Base

initialize, to_s

Constructor Details

#initialize(soap, ref) ⇒ ManagedObject

Returns a new instance of ManagedObject.



225
226
227
228
229
# File 'lib/rbvmomi/types.rb', line 225

def initialize soap, ref
  super()
  @soap = soap
  @ref = ref
end

Instance Method Details

#==(x) ⇒ Object Also known as: eql?



271
272
273
# File 'lib/rbvmomi/types.rb', line 271

def == x
  x.class == self.class and x._ref == @ref
end

#[](k) ⇒ Object



267
268
269
# File 'lib/rbvmomi/types.rb', line 267

def [] k
  _get_property k
end

#_call(method, o = {}) ⇒ Object



253
254
255
256
257
# File 'lib/rbvmomi/types.rb', line 253

def _call method, o={}
  fail "parameters must be passed as a hash" unless o.is_a? Hash
  desc = self.class.full_methods_desc[method.to_s] or fail "unknown method"
  @soap.call method, desc, self, o
end

#_get_property(sym) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/rbvmomi/types.rb', line 235

def _get_property sym
  ret = @soap.propertyCollector.RetrieveProperties(:specSet => [{
    :propSet => [{ :type => self.class.wsdl_name, :pathSet => [sym.to_s] }],
    :objectSet => [{ :obj => self }],
  }])[0]

  if ret.propSet.empty?
    fail if ret.missingSet.empty?
    raise ret.missingSet[0].fault
  else
    ret.propSet[0].val
  end
end

#_refObject



231
232
233
# File 'lib/rbvmomi/types.rb', line 231

def _ref
  @ref
end

#_set_property(sym, val) ⇒ Object



249
250
251
# File 'lib/rbvmomi/types.rb', line 249

def _set_property sym, val
  fail 'unimplemented'
end

#collect(*props) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/rbvmomi/extensions.rb', line 46

def collect *props
  h = collect! *props
  a = props.map { |k| h[k.to_s] }
  if block_given?
    yield a
  else
    a
  end
end

#collect!(*props) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/rbvmomi/extensions.rb', line 35

def collect! *props
  spec = {
    objectSet: [{ obj: self }],
    propSet: [{
      pathSet: props,
      type: self.class.wsdl_name
    }]
  }
  @soap.propertyCollector.RetrieveProperties(specSet: [spec])[0].to_hash
end

#hashObject



277
278
279
# File 'lib/rbvmomi/types.rb', line 277

def hash
  [self.class, @ref].hash
end

#pretty_print(pp) ⇒ Object



263
264
265
# File 'lib/rbvmomi/types.rb', line 263

def pretty_print pp
  pp.text to_s
end

#to_sObject



259
260
261
# File 'lib/rbvmomi/types.rb', line 259

def to_s
  "#{self.class.wsdl_name}(#{@ref.inspect})"
end

#wait(version, *pathSet) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rbvmomi/extensions.rb', line 7

def wait version, *pathSet
  version ||= ''
  all = pathSet.empty?
  filter = @soap.propertyCollector.CreateFilter :spec => {
    :propSet => [{ :type => self.class.wsdl_name, :all => all, :pathSet => pathSet }],
    :objectSet => [{ :obj => self }],
  }, :partialUpdates => false
  result = @soap.propertyCollector.WaitForUpdates(version: version)
  filter.DestroyPropertyFilter
  changes = result.filterSet[0].objectSet[0].changeSet
  changes.map { |h| [h.name.split('.').map(&:to_sym), h.val] }.each do |path,v|
    k = path.pop
    o = path.inject(self) { |b,k| b[k] }
    o._set_property k, v unless o == self
  end
  result.version
end

#wait_until(*pathSet, &b) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rbvmomi/extensions.rb', line 25

def wait_until *pathSet, &b
  ver = nil
  loop do
    ver = wait ver, *pathSet
    if x = b.call
      return x
    end
  end
end