Skip to content

Commit

Permalink
Wait for sys prep is now renamed wait for customization. Customizatio…
Browse files Browse the repository at this point in the history
…n can occur on other operating systems.

You can choose to wait for customization to complete, as not everyone uses VSphere customizations.
  • Loading branch information
taliesins committed Nov 17, 2016
1 parent 0875f61 commit 06def27
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ This provider has the following settings, all are required unless noted:
where the key must start with `guestinfo.`. VMs with VWware Tools installed can
retrieve the value of these variables using the `vmtoolsd` command: `vmtoolsd --cmd 'info-get guestinfo.some.variable'`.
* `notes` - _Optional_ string - Add arbitrary notes to the VM
* `wait_for_customization` - _Optional_ boolean - Wait for customization to complete before
continuing. Set to false by default.
* `wait_for_customization_timeout` - _Optional_ integer - Timeout in seconds to wait for
customization to complete before continuing. Set to 600 by default.
* `management_network_adapter_slot` - _Optional_ integer - zero based array of the card index.
This will be the network card to get the ip address from to use for communication between
Vagrant and the vm. If this is not set we will use the one detected by VSphere.
Expand Down
3 changes: 3 additions & 0 deletions lib/vSphere/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def initialize(serial_port_config)
attr_accessor :mem_reservation
attr_accessor :extra_config
attr_accessor :notes
attr_accessor :wait_for_customization
attr_accessor :wait_for_customization_timeout

attr_accessor :destroy_unused_network_interfaces
attr_accessor :destroy_unused_serial_ports
Expand All @@ -134,6 +136,7 @@ def initialize(serial_port_config)
attr_reader :custom_attributes

def initialize
wait_for_customization_timeout = 600
@destroy_unused_network_interfaces = UNSET_VALUE
@destroy_unused_serial_ports = UNSET_VALUE
@network_adapters = {}
Expand Down
33 changes: 29 additions & 4 deletions lib/vSphere/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,36 @@ def clone(root_path)
new_vm = task.wait_for_completion
end
@logger.info("Finished cloning vm #{@machine.id}")
end

config.custom_attributes.each do |k, v|
new_vm.setCustomValue(key: k, value: v)
end
config.custom_attributes.each do |k, v|
new_vm.setCustomValue(key: k, value: v)
end

if config.wait_for_customization
@logger.info I18n.t('vsphere.wait_for_customization')
vem = connection.serviceContent.eventManager

wait = true
waited_seconds = 0
sleep_time = 5

while wait
events = vem.QueryEvents(filter:RbVmomi::VIM::EventFilterSpec(entity:RbVmomi::VIM::EventFilterSpecByEntity(entity: new_vm, recursion:RbVmomi::VIM::EventFilterSpecRecursionOption(:self)), eventTypeId: ['CustomizationSucceeded']))

if events.size > 0
events.each do |e|
@logger.info e.fullFormattedMessage
end
wait = false
elsif waited_seconds >= config.wait_for_customization_timeout
fail Errors::VSphereError, :'customization_timeout'
else
sleep(sleep_time)
waited_seconds += sleep_time
end
end
end
rescue Errors::VSphereError
raise
#rescue StandardError => e
Expand Down Expand Up @@ -540,7 +565,7 @@ def get_customization_spec(machine, spec_info)
end

customization_spec
end
end

def get_location(datastore, dc, machine, template)
if machine.provider_config.linked_clone
Expand Down
8 changes: 3 additions & 5 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ en:
The VM has not been created
vm_not_running: |-
The VM is not running
wait_sysprep: |-
Waiting for sysprep
wait_for_customization: |-
Waiting for customization
errors:
missing_template: |-
Expand Down Expand Up @@ -50,10 +50,8 @@ en:
Cannot use Linked Clone with Storage DRS
specified_mangement_interface_does_not_exist: |-
specified management interface does not exist
sysprep_timeout: |-
customization_timeout: |-
Customization of VM not succeeded within timeout.
wait_for_ip_address_timeout: |-
Timeout while waiting for ip address
config:
host: |-
Expand Down

0 comments on commit 06def27

Please sign in to comment.