Module: CustomizationHelper

Defined in:
lib/chef/knife/helpers/customization_helper.rb

Overview

The Customization helper for sysprep

Class Method Summary collapse

Class Method Details

.query_customization_succeeded(vm, vem) ⇒ Object

Confirm that cspec is done

Parameters:

  • vm (Object)

    The VM object to connect to

  • vem (Object)

    The vem TODO



45
46
47
48
49
50
# File 'lib/chef/knife/helpers/customization_helper.rb', line 45

def self.query_customization_succeeded(vm, vem)
  vem.QueryEvents(filter:
      RbVmomi::VIM::EventFilterSpec(entity:
      RbVmomi::VIM::EventFilterSpecByEntity(entity: vm, recursion:
      RbVmomi::VIM::EventFilterSpecRecursionOption(:self)), eventTypeId: ["CustomizationSucceeded"]))
end

.wait_for_sysprep(vm, vim_connection, timeout, sleep_time) ⇒ Object

Wait for sysprep

Parameters:

  • vm (Object)

    The VM object to connect to

  • vim_connection (Object)

    The vim_connection object settings to connect for

  • timeout (String)

    A string to set the timeout

  • sleep_time (String)

    A string to set the a sleep_time



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chef/knife/helpers/customization_helper.rb', line 16

def self.wait_for_sysprep(vm, vim_connection, timeout, sleep_time)
  vem = vim_connection.serviceContent.eventManager

  wait = true
  waited_seconds = 0

  print "Waiting for sysprep..."
  while wait
    events = query_customization_succeeded(vm, vem)

    if events.size > 0
      events.each do |e|
        puts "\n#{e.fullFormattedMessage}"
      end
      wait = false
    elsif waited_seconds >= timeout
      abort "\nCustomization of VM #{vm.name} not succeeded within #{timeout} seconds."
    else
      print "."
      sleep(sleep_time)
      waited_seconds += sleep_time
    end
  end
end