1 2 3 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
class RbVmomi::VIM::ManagedObject
# Wait for updates on an object until a condition becomes true.
#
# @param pathSet [Array] Property paths to wait for updates to.
# @yield Called when an update to a subscribed property occurs.
# @yieldreturn [Boolean] Whether to stop waiting.
#
# @todo Pass the current property values to the block.
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
# Efficiently retrieve multiple properties from an object.
# @param pathSet [Array] Properties to return.
# @return [Hash] Hash from property paths to values.
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
# Efficiently retrieve multiple properties from an object.
# @param pathSet (see #collect!)
# @yield [*values] Property values in same order as +pathSet+.
# @return [Array] Property values in same order as +pathSet+, or the return
# value from the block if it is given.
def collect *pathSet
h = collect! *pathSet
a = pathSet.map { |k| h[k.to_s] }
if block_given?
yield a
else
a
end
end
end
|