Class: RbVmomi::VIM::ManagedObject

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

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.



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

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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/rbvmomi/vim/ManagedObject.rb', line 30

def collect! *pathSet
  spec = {
    :objectSet => [{ :obj => self }],
    :propSet => [{
      :pathSet => pathSet,
      :type => self.class.wsdl_name
    }]
  }
  @soap.propertyCollector.RetrieveProperties(:specSet => [spec])[0].to_hash
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.



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

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