module CustomizationHelper

The Customization helper for sysprep

Public Class Methods

query_customization_succeeded(vm, vem) click to toggle source

Confirm that cspec is done

@param [Object] vm The VM object to connect to @param [Object] vem The vem TODO

# 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) click to toggle source

Wait for sysprep

@param [Object] vm The VM object to connect to @param [Object] vim_connection The vim_connection object settings to connect for @param [String] timeout A string to set the timeout @param [String] sleep_time A string to set the a sleep_time

# 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