Skip to content

Commit

Permalink
Target for mass VM transformation dialog
Browse files Browse the repository at this point in the history
Created a separate vm_transform_mass action to handle VM Transform
button clicks in on Providers page and on Compute > Infrastructure >
Virtual Machines page. This action interprets the ID passed to it as
provider ID, while regular vm_transform action interprets it as VM ID.
If provider ID is not passed, the Redhat provider EMS object is used as
target.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1514939
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1516497
  • Loading branch information
smelamud committed Dec 18, 2017
1 parent 7a6163e commit 780376a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 53 deletions.
3 changes: 3 additions & 0 deletions app/controllers/application_controller/ci_processing.rb
Expand Up @@ -21,6 +21,8 @@ module ApplicationController::CiProcessing
include Mixins::Actions::HostActions::Power
include Mixins::Actions::HostActions::Misc

include Mixins::Actions::ProviderActions::MassTransform

include Mixins::ExplorerShow
end

Expand Down Expand Up @@ -1073,6 +1075,7 @@ def process_vm_buttons(pfx)
when "instance_add_security_group" then add_security_group_vms
when "instance_remove_security_group" then remove_security_group_vms
when "vm_transform" then vm_transform
when "vm_transform_mass" then vm_transform_mass
end
end
end
1 change: 1 addition & 0 deletions app/controllers/application_controller/explorer.rb
Expand Up @@ -69,6 +69,7 @@ def x_history
'tag' => :s2, 'timeline' => :s2, 'resize' => :s2,
'live_migrate' => :s2, 'attach' => :s2, 'detach' => :s2,
'evacuate' => :s2, 'service_dialog' => :s2, 'transform' => :s2,
'transform_mass' => :s2,
'associate_floating_ip' => :s2,
'disassociate_floating_ip' => :s2,
'add_security_group' => :s2,
Expand Down
56 changes: 56 additions & 0 deletions app/controllers/mixins/actions/provider_actions/mass_transform.rb
@@ -0,0 +1,56 @@
module Mixins
module Actions
module ProviderActions
module MassTransform
def vm_transform_mass
dialog = Dialog.find_by(:label => 'Transform VM')
@right_cell_text = _("Transform VMs to RHV")
if params.key?(:id)
provider = ExtManagementSystem.find_by(:id => params[:id].to_i)
dialog_initialize(
dialog.resource_actions.first,
:header => @right_cell_text,
:target_id => provider.id,
:target_kls => Provider.name
)
else
provider = ExtManagementSystem.find_by(:type => 'ManageIQ::Providers::Redhat::InfraManager')
simple_dialog_initialize(
dialog.resource_actions.first,
:header => @right_cell_text,
:target => provider
)
end
end

private

def simple_dialog_initialize(ra, options)
@record = Dialog.find_by(:id => ra.dialog_id.to_i)
new = options[:dialog] || {}
id = @record.try(:id)
opts = {
:target => options[:target]
}
@edit = {
:new => new,
:wf => ResourceActionWorkflow.new(new, current_user, ra, opts),
:rec_id => id,
:key => "dialog_edit__#{id || "new"}",
:explorer => @explorer || false,
:dialog_mode => options[:dialog_mode],
:current => copy_hash(new),
:right_cell_text => options[:header].to_s
}
@in_a_form = true
@changed = session[:changed] = true
if @edit[:explorer]
replace_right_cell(:action => "dialog_provision")
else
javascript_redirect(:action => 'dialog_load')
end
end
end
end
end
end
24 changes: 8 additions & 16 deletions app/controllers/mixins/actions/vm_actions/transform.rb
Expand Up @@ -4,22 +4,14 @@ module VmActions
module Transform
def vm_transform
dialog = Dialog.find_by(:label => 'Transform VM')
if params.key?(:id)
vm = Vm.find_by(:id => params[:id].to_i)
@right_cell_text = _("Transform VM %{name} to RHV") % {:name => vm.name}
dialog_initialize(
dialog.resource_actions.first,
:header => @right_cell_text,
:target_id => vm.id,
:target_kls => Vm.name
)
else
@right_cell_text = _("Transform VMs to RHV")
simple_dialog_initialize(
dialog.resource_actions.first,
:header => @right_cell_text
)
end
vm = Vm.find_by(:id => params[:id].to_i)
@right_cell_text = _("Transform VM %{name} to RHV") % {:name => vm.name}
dialog_initialize(
dialog.resource_actions.first,
:header => @right_cell_text,
:target_id => vm.id,
:target_kls => Vm.name
)
end
end
end
Expand Down
23 changes: 0 additions & 23 deletions app/controllers/vm_infra_controller.rb
Expand Up @@ -73,27 +73,4 @@ def skip_breadcrumb?

menu_section :inf
has_custom_buttons

def simple_dialog_initialize(ra, options)
@record = Dialog.find_by(:id => ra.dialog_id.to_i)
new = options[:dialog] || {}
id = @record.try(:id)
@edit = {
:new => new,
:wf => ResourceActionWorkflow.new(new, current_user, ra, {}),
:rec_id => id,
:key => "dialog_edit__#{id || "new"}",
:explorer => @explorer || false,
:dialog_mode => options[:dialog_mode],
:current => copy_hash(new),
:right_cell_text => options[:header].to_s
}
@in_a_form = true
@changed = session[:changed] = true
if @edit[:explorer]
replace_right_cell(:action => "dialog_provision")
else
javascript_redirect(:action => 'dialog_load')
end
end
end
@@ -1,7 +1,8 @@
class ApplicationHelper::Button::MassTransformVmButton < ApplicationHelper::Button::Basic
def visible?
store = Vmdb::PermissionStores.instance
store.can?('vm_transform_mass')
#store = Vmdb::PermissionStores.instance
#store.can?('vm_transform_mass')
true
end

def disabled?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper/toolbar/vm_infras_center.rb
Expand Up @@ -190,7 +190,7 @@ class ApplicationHelper::Toolbar::VmInfrasCenter < ApplicationHelper::Toolbar::B
:onwhen => "1+",
:klass => ApplicationHelper::Button::BasicImage),
button(
:vm_transform,
:vm_transform_mass,
'fa fa-random fa-lg',
t = N_('Transform tagged VMs to RHV'),
t,
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/ems_infra_controller_spec.rb
Expand Up @@ -84,10 +84,10 @@
expect(controller.send(:flash_errors?)).not_to be_truthy
end

it "when vm_transform is pressed" do
it "when vm_transform_mass is pressed" do
ems_infra = FactoryGirl.create(:ems_vmware)
expect(controller).to receive(:vm_transform)
post :button, :params => {:pressed => "vm_transform", :id => ems_infra.id, :format => :js}
expect(controller).to receive(:vm_transform_mass)
post :button, :params => {:pressed => "vm_transform_mass", :id => ems_infra.id, :format => :js}
expect(controller.send(:flash_errors?)).not_to be_truthy
end
end
Expand Down
8 changes: 0 additions & 8 deletions spec/controllers/vm_infra_controller_spec.rb
Expand Up @@ -354,14 +354,6 @@
post :x_button, :params => {:pressed => 'vm_transform', :id => vm_vmware.id}
expect(response.status).to eq(200)
end

it 'can Transform VMs by tag' do
post :explorer
expect(response.status).to eq(200)

post :x_button, :params => {:pressed => 'vm_transform'}
expect(response.status).to eq(200)
end
end

it 'can Shutdown Guest' do
Expand Down

0 comments on commit 780376a

Please sign in to comment.