Skip to content

Commit

Permalink
Merge pull request #408 from agrare/bz_1724751_use_vm_ems_ref_to_find…
Browse files Browse the repository at this point in the history
…_in_vmdb

Use the new VM's ems_ref instead of an annotation
  • Loading branch information
gmcculloug authored Jul 23, 2019
2 parents 1ff3e7b + e91a334 commit 1875eb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ module ManageIQ::Providers::Vmware::InfraManager::Provision::Cloning
def do_clone_task_check(clone_task_mor)
source.with_provider_connection do |vim|
begin
state, val = vim.pollTask(clone_task_mor, "VMClone")
case state
task_props = ["info.state", "info.error", "info.result", "info.progress", "info.completeTime"]
task = vim.getMoProp(clone_task_mor, task_props)

task_info = task&.info
task_state = task_info&.state

case task_state
when TaskInfoState::Success
phase_context[:new_vm_ems_ref] = task_info&.result
phase_context[:clone_vm_task_completion_time] = task_info&.completeTime
return true
when TaskInfoState::Running
return false, val.nil? ? "beginning" : "#{val}% complete"
progress = task_info&.progress
return false, progress.nil? ? "beginning" : "#{progress}% complete"
else
return false, state
return false, task_state
end
end
end
Expand All @@ -18,11 +26,11 @@ def do_clone_task_check(clone_task_mor)
end

def find_destination_in_vmdb
# The new VM will have the guid we placed in the annotations field
validation_guid = phase_context[:new_vm_validation_guid]
VmOrTemplate.where(:name => dest_name).detect do |v|
v.hardware.annotation && v.hardware.annotation.include?(validation_guid)
end
# Check that the EMS inventory is as up to date as the CloneVM_Task completeTime
# to prevent issues with post-provision depending on data that isn't in VMDB yet
return if source.ext_management_system.last_inventory_date < phase_context[:clone_vm_task_completion_time]

source.ext_management_system.vms.find_by(:ems_ref => phase_context[:new_vm_ems_ref])
end

def prepare_for_clone_task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def poll_destination_in_vmdb
phase_context.delete(:new_vm_validation_guid)
signal :customize_destination
else
_log.info("Unable to find #{destination_type} [#{dest_name}] with validation guid [#{phase_context[:new_vm_validation_guid]}], will retry")
_log.info("Unable to find #{destination_type} [#{dest_name}] with ems_ref [#{phase_context[:new_vm_ems_ref]}], will retry")
requeue_phase
end
end
Expand Down

0 comments on commit 1875eb5

Please sign in to comment.