Class: RbVmomi::VIM::ServiceInstance

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

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 ‘/’.

Returns:



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

#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.



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
# 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 = @soap.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 = @soap.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
    end
  ensure
    @soap.propertyCollector.CancelWaitForUpdates
    filter.DestroyPropertyFilter
  end
end