Sha256: 07c30b626b7e4113558c576257c8b407a1928e4beccddc00a7526169a85219a8

Contents?: true

Size: 1.79 KB

Versions: 14

Compression:

Stored size: 1.79 KB

Contents

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

14 entries across 14 versions & 3 rubygems

Version Path
rbvmomi-1.8.5 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.4 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.3 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.4 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.3 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.2 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.9.0 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.2 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.2.pre lib/rbvmomi/vim/ManagedObject.rb
mkuzmin-rbvmomi-1.8.2.1 lib/rbvmomi/vim/ManagedObject.rb
vagrant-rbvmomi-1.8.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.1 lib/rbvmomi/vim/ManagedObject.rb
rbvmomi-1.8.0 lib/rbvmomi/vim/ManagedObject.rb