Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Wait for windows sysprep during clone #199

Merged
1 commit merged into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/vSphere/action/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,46 @@ def call(env)

machine.id = new_vm.config.uuid

wait_for_sysprep(env, new_vm, connection, 600, 10) if machine.config.vm.guest.eql?(:windows)

env[:ui].info I18n.t('vsphere.vm_clone_success')

@app.call env
end

private

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

wait = true
waited_seconds = 0

env[:ui].info I18n.t('vsphere.wait_sysprep')
while wait
events = query_customization_succeeded(vm, vem)

if events.size > 0
events.each do |e|
env[:ui].info e.fullFormattedMessage
end
wait = false
elsif waited_seconds >= timeout
fail Errors::VSphereError, :'sysprep_timeout'
else
sleep(sleep_time)
waited_seconds += sleep_time
end
end
end

def 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

def get_customization_spec(machine, spec_info)
customization_spec = spec_info.spec.clone

Expand Down
4 changes: 4 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ en:
The VM has not been created
vm_not_running: |-
The VM is not running
wait_sysprep: |-
Waiting for sysprep

errors:
missing_template: |-
Expand Down Expand Up @@ -48,6 +50,8 @@ en:
Cannot use Linked Clone with Storage DRS
multiple_interface_with_real_nic_ip_set: |-
real_nic_ip filtering set with multiple valid VM interfaces available
sysprep_timeout: |-
Customization of VM not succeeded within timeout.

config:
host: |-
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def call
communicator: nil,
networks: [[:private_network, { ip: '0.0.0.0' }]],
boot_timeout: 1,
graceful_halt_timeout: 0.1),
graceful_halt_timeout: 0.1,
guest: nil),
validate: []
)
@app = double 'app', call: true
Expand Down