Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use the new VM's ems_ref instead of an annotation #408

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ 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)

case task&.info&.state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good. Since we are referencing task&.info in 5 places we should set that to a variable to avoid the lookup each time: task_info = task&.info

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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&.info&.state
end
end
end
Expand All @@ -18,11 +23,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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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