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

Add Live Migrate actions to the task queue. #208

Merged
merged 4 commits into from
Jan 31, 2017
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
75 changes: 46 additions & 29 deletions app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def livemigratevms

def live_migrate
assert_privileges("instance_live_migrate")
@record ||= VmOrTemplate.find_by_id(params[:rec_id])
@record ||= VmOrTemplate.find_by(:id => params[:rec_id])
drop_breadcrumb(
:name => _("Live Migrate Instance '%{name}'") % {:name => @record.name},
:url => "/vm_cloud/live_migrate"
Expand Down Expand Up @@ -497,53 +497,70 @@ def live_migrate_form_fields

def live_migrate_vm
assert_privileges("instance_live_migrate")
@record = VmOrTemplate.find_by_id(params[:id])
@record = VmOrTemplate.find_by(:id => params[:id])
case params[:button]
when "cancel"
add_flash(_("Live Migration of %{model} \"%{name}\" was cancelled by the user") % {
:model => ui_lookup(:table => "vm_cloud"), :name => @record.name})
:model => ui_lookup(:table => "vm_cloud"), :name => @record.name
})
@record = @sb[:action] = nil
when "submit"
if @record.supports_live_migrate?
if params['auto_select_host'] == 'on'
hostname = nil
else
hostname = params[:destination_host]
end
block_migration = params[:block_migration]
disk_over_commit = params[:disk_over_commit]
begin
@record.live_migrate(
:hostname => hostname,
:block_migration => block_migration == 'on',
:disk_over_commit => disk_over_commit == 'on'
)
add_flash(_("Live Migrating %{instance} \"%{name}\"") % {
:instance => ui_lookup(:table => 'vm_cloud'),
:name => @record.name})
rescue => ex
add_flash(_("Unable to live migrate %{instance} \"%{name}\": %{details}") % {
:instance => ui_lookup(:table => 'vm_cloud'),
:name => @record.name,
:details => get_error_message_from_fog(ex)}, :error)
options = {
:hostname => params['auto_select_host'] == 'on' ? nil : params[:destination_host],
:block_migration => params['block_migration'] == 'on',
:disk_over_commit => params['disk_over_commit'] == 'on'
}
task_id = @record.class.live_migrate_queue(session[:userid], @record, options)
unless task_id.kind_of?(Integer)
add_flash(_("Instance live migration task failed."), :error)
end

return javascript_flash(:spinner_off => true) if @flash_array
return initiate_wait_for_task(:task_id => task_id, :action => "live_migrate_finished")
else
add_flash(_("Unable to live migrate %{instance} \"%{name}\": %{details}") % {
:instance => ui_lookup(:table => 'vm_cloud'),
:name => @record.name,
:details => @record.unsupported_reason(:live_migrate)}, :error)
:details => @record.unsupported_reason(:live_migrate)
}, :error)
params[:id] = @record.id.to_s # reset id in params for show
@record = nil
@sb[:action] = nil
end
params[:id] = @record.id.to_s # reset id in params for show
@record = nil
@sb[:action] = nil
end
if @sb[:explorer]
replace_right_cell
else
session[:flash_msgs] = @flash_array.dup
javascript_redirect previous_breadcrumb_url
end
return
end

def live_migrate_finished
task_id = session[:async][:params][:task_id]
vm_id = session[:async][:params][:id]
vm = VmOrTemplate.find_by(:id => vm_id)
task = MiqTask.find(task_id)
if MiqTask.status_ok?(task.status)
add_flash(_("Live migration of Instance \"%{name}\" complete.") % {:name => vm.name})
else
add_flash(_("Unable to live migrate Instance \"%{name}\": %{details}") % {
:name => vm.name,
:details => get_error_message_from_fog(task.message)
}, :error)
end
@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
params[:id] = vm.id.to_s # reset id in params for show
@record = nil
@sb[:action] = nil
if @sb[:explorer]
replace_right_cell
else
session[:flash_msgs] = @flash_array.dup
javascript_redirect previous_breadcrumb_url
end
end

def evacuate
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,7 @@
tree_autoload
genealogy_tree_selected
ownership_update
wait_for_task
) +
ownership_post +
pre_prov_post
Expand Down Expand Up @@ -3024,6 +3025,7 @@
ownership_update
associate_floating_ip_vm
disassociate_floating_ip_vm
wait_for_task
) +
adv_search_post +
compare_post +
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/vm_cloud_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
controller.instance_variable_set(:@edit,
:new => {},
:explorer => false)
expect_any_instance_of(VmCloud).to receive(:live_migrate)
expect(VmCloud).to receive(:live_migrate_queue)
post :live_migrate_vm, :params => {
:button => 'submit',
:id => vm_openstack.id
Expand Down