Class: RbVmomi::VIM::ServiceInstance

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

Instance Method Summary (collapse)

Instance Method Details

- (Datacenter) find_datacenter(path = nil)

Retrieve a Datacenter. If no path is given the first datacenter will be returned.



6
7
8
9
10
11
12
# File 'lib/rbvmomi/vim/ServiceInstance.rb', line 6

def find_datacenter path=nil
  if path
    content.rootFolder.traverse path, RbVmomi::VIM::Datacenter
  else
    content.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).first
  end
end

- (void) wait_for_multiple_tasks(interested, tasks) {|Hash| ... }

This method returns an undefined value.

Wait for several tasks to complete.

Yields:

  • (Hash)

    Called when a property is updated on a task. The parameter is a hash from tasks to hashes from property path to value.



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
# File 'lib/rbvmomi/vim/ServiceInstance.rb', line 21

def wait_for_multiple_tasks interested, tasks
  version = ''
  interested = (interested + ['info.state']).uniq
  task_props = Hash.new { |h,k| h[k] = {} }

  filter = _connection.propertyCollector.CreateFilter :spec => {
    :propSet => [{ :type => 'Task', :all => false, :pathSet => interested }],
    :objectSet => tasks.map { |x| { :obj => x } },
  }, :partialUpdates => false

  begin
    until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
      result = _connection.propertyCollector.WaitForUpdates(:version => version)
      version = result.version
      os = result.filterSet[0].objectSet

      os.each do |o|
        changes = Hash[o.changeSet.map { |x| [x.name, x.val] }]

        interested.each do |k|
          task = tasks.find { |x| x._ref == o.obj._ref }
          task_props[task][k] = changes[k] if changes.member? k
        end
      end

      yield task_props if block_given?
    end
  ensure
    _connection.propertyCollector.CancelWaitForUpdates
    filter.DestroyPropertyFilter
  end

  task_props
end