Class: RbVmomi::VIM::ManagedObject

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#collect(*pathSet) {|*values| ... } ⇒ Array

Efficiently retrieve multiple properties from an object.

Parameters:

  • pathSet (Array)

    Properties to return.

Yields:

  • (*values)

    Property values in same order as pathSet.

Returns:

  • (Array)

    Property values in same order as pathSet, or the return value from the block if it is given.



54
55
56
57
58
59
60
61
62
# File 'lib/rbvmomi/vim/ManagedObject.rb', line 54

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

#collect!(*pathSet) ⇒ Hash

Efficiently retrieve multiple properties from an object.

Parameters:

  • pathSet (Array)

    Properties to return.

Returns:

  • (Hash)

    Hash from property paths to values.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbvmomi/vim/ManagedObject.rb', line 33

def collect! *pathSet
  spec = {
    :objectSet => [{ :obj => self }],
    :propSet => [{
      :pathSet => pathSet,
      :type => self.class.wsdl_name
    }]
  }
  ret = _connection.propertyCollector.RetrieveProperties(:specSet => [spec])
  if ret && ret.length > 0
    ret[0].to_hash
  else
    {}
  end
end

#wait_until(*pathSet) { ... } ⇒ Object

TODO:

Pass the current property values to the block.

Wait for updates on an object until a condition becomes true.

Parameters:

  • pathSet (Array)

    Property paths to wait for updates to.

Yields:

  • Called when an update to a subscribed property occurs.

Yield Returns:

  • (Boolean)

    Whether to stop waiting.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rbvmomi/vim/ManagedObject.rb', line 12

def wait_until *pathSet, &b
  all = pathSet.empty?
  filter = _connection.propertyCollector.CreateFilter :spec => {
    :propSet => [{ :type => self.class.wsdl_name, :all => all, :pathSet => pathSet }],
    :objectSet => [{ :obj => self }],
  }, :partialUpdates => false
  ver = ''
  loop do
    result = _connection.propertyCollector.WaitForUpdates(:version => ver)
    ver = result.version
    if x = b.call
      return x
    end
  end
ensure
  filter.DestroyPropertyFilter if filter
end