Sha256: 7cb8ec8ff60c07cef4a842e4a37c3919c400eea945b17adb0bb7f243103155da

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 KB

Contents

# Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
# SPDX-License-Identifier: MIT

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

Version data entries

19 entries across 17 versions & 2 rubygems

Version Path
rbvmomi-2.1.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-2.1.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-2.0.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-2.0.0 lib/rbvmomi/vim/ManagedObject.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rbvmomi-1.13.0/lib/rbvmomi/vim/ManagedObject.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rbvmomi-1.13.0/lib/rbvmomi/vim/ManagedObject.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rbvmomi-1.13.0/lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.13.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.12.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.7 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.6 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.5 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.4 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.3 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.2 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.11.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.10.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.5 lib/rbvmomi/vim/ManagedObject.rb