Class: RbVmomi::VIM::ServiceInstance

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

Overview

Copyright © 2011-2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MIT

Instance Method Summary collapse

Instance Method Details

#find_datacenter(path = nil) ⇒ Datacenter

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

Parameters:

  • path (String) (defaults to: nil)

    Path delimited by '/', or an array of path elements.

Returns:


10
11
12
13
14
15
16
# File 'lib/rbvmomi/vim/ServiceInstance.rb', line 10

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

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

This method returns an undefined value.

Wait for several tasks to complete.

Parameters:

  • interested (Array)

    Property paths to watch for updates.

  • tasks (Array)

    Tasks to wait on.

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.


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

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