Skip to content

Commit

Permalink
Support VM Reconfigure for VMware vCloud provider
Browse files Browse the repository at this point in the history
With this commit we add support to reconfigure VM hardware
for VMware vCloud provider. Different configuration is needed
for VMware vSphere (infra) than for VMware vCloud (cloud) so we
cannot rely on `vm.vendor = vmware` attribute anymore, which is
common to them both... Instead, we rely on VM class name.

Also, there seems to be a bug in ruby controller which tries to
render flash message AFTER redirect was invoked. This results in
ugly rails crash. Solved by removing the flash rendering part.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1572086

Signed-off-by: Miha Pleško <[email protected]>
  • Loading branch information
miha-plesko committed May 17, 2018
1 parent fda046b commit 1276141
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
vm.validateClicked = miqService.validateWithAjax;
vm.modelCopy = angular.copy( vm.reconfigureModel );
vm.model = 'reconfigureModel';
vm.vm_type = '';
vm.disk_default_type = '';

ManageIQ.angular.scope = vm;

Expand Down Expand Up @@ -179,6 +181,7 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
vm.reconfigureModel.vmAddDisks.push({disk_size_in_mb: diskSizeAdd,
persistent: dmode,
thin_provisioned: dtype,
type: disk.hdType,
new_controller_type: disk.new_controller_type,
dependent: disk.cb_dependent,
bootable: disk.cb_bootable});
Expand Down Expand Up @@ -213,7 +216,7 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
};

vm.resetAddValues = function() {
vm.reconfigureModel.hdType = 'thin';
vm.reconfigureModel.hdType = vm.disk_default_type;
vm.reconfigureModel.hdMode = 'persistent';
vm.reconfigureModel.hdSize = '';
vm.reconfigureModel.hdUnit = 'MB';
Expand Down Expand Up @@ -285,6 +288,7 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
};

vm.enableDiskAdd = function() {
vm.resetAddValues();
vm.reconfigureModel.addEnabled = true;
};

Expand Down Expand Up @@ -408,6 +412,8 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
vm.cb_cpu = data.cb_cpu;
vm.reconfigureModel.vmdisks = angular.copy(data.disks);
vm.reconfigureModel.vmNetworkAdapters = angular.copy(data.network_adapters);
vm.vm_type = data.vm_type;
vm.disk_default_type = data.disk_default_type;
vm.updateDisksAddRemove();
vm.updateNetworkAdaptersAddRemove();

Expand Down
11 changes: 4 additions & 7 deletions app/controllers/mixins/actions/vm_actions/reconfigure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def get_reconfig_info(reconfigure_ids)

# if only one vm that supports disk reconfiguration is selected, get the disks information
vmdisks = []
@reconfigureitems.first.hardware.disks.each do |disk|
@reconfigureitems.first.hardware.disks.sort_by(&:filename).each do |disk|
next if disk.device_type != 'disk'
dsize, dunit = reconfigure_calculations(disk.size / (1024 * 1024))
vmdisks << {:hdFilename => disk.filename,
Expand Down Expand Up @@ -246,7 +246,9 @@ def get_reconfig_info(reconfigure_ids)
:socket_count => socket_count.to_s,
:cores_per_socket_count => cores_per_socket.to_s,
:disks => vmdisks,
:network_adapters => network_adapters}
:network_adapters => network_adapters,
:vm_type => @reconfigureitems.first.class.name,
:disk_default_type => @reconfigureitems.first.try(:disk_default_type) || 'thin'}
end

def supports_reconfigure_disks?
Expand Down Expand Up @@ -353,11 +355,6 @@ def reconfigure_handle_submit_button
url = previous_breadcrumb_url.split('/')
javascript_redirect(:controller => url[1], :action => url[2])
end

if @flash_array
javascript_flash
return
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/application_helper/toolbar/x_vm_cloud_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class ApplicationHelper::Toolbar::XVmCloudCenter < ApplicationHelper::Toolbar::B
'pficon pficon-edit fa-lg',
t = N_('Edit Management Engine Relationship'),
t),
button(
:vm_reconfigure,
'pficon pficon-edit fa-lg',
N_('Reconfigure the Memory/CPU of this VM'),
N_('Reconfigure this VM'),
:klass => ApplicationHelper::Button::VmReconfigure
),
]
),
])
Expand Down
28 changes: 15 additions & 13 deletions app/views/vm_common/_reconfigure.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@
%thead
%th= _('Name')
%th= _('Type')
%th{"ng-if" => @reconfigitems.first.vendor == 'vmware'}= _('Mode')
%th{"ng-if" => @reconfigitems.first.vendor == 'vmware'}= _('Controller Type')
%th{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}= _('Mode')
%th{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}= _('Controller Type')
%th= _('Size')
%th= _('Unit')
%th{"ng-if" => @reconfigitems.first.vendor == 'vmware'}= _('Dependent')
%th= _('Delete Backing')
%th{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}= _('Dependent')
%th{"ng-hide" => "vm.vm_type.includes('Vmware::CloudManager')"}= _('Delete Backing')
%th{"ng-if" => @reconfigitems.first.vendor == 'redhat'}= _('Bootable')
- if supports_reconfigure_disksize?
%th{:colspan => 2}= _('Actions')
Expand All @@ -144,14 +144,16 @@
"ng-form" => "rowForm"}
%td
%td
- options = @reconfigitems.first.try(:disk_types) || %w(thick thin)
- default_option = @reconfigitems.first.try(:disk_default_type) || 'thin'
= select_tag('hdType',
options_for_select(%w(thick thin)),
options_for_select(options, :selected => default_option),
"ng-model" => "vm.reconfigureModel.hdType",
"ng-change" => "",
"data-width" => "auto",
"required" => "",
"selectpicker-for-select-tag" => "")
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
= select_tag('hdMode',
options_for_select(%w(persistent nonpersistent)),
"ng-model" => "vm.reconfigureModel.hdMode",
Expand All @@ -160,7 +162,7 @@
"required" => "",
"selectpicker-for-select-tag" => "",
"width" => "10")
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
- options = @reconfigitems.first.try(:scsi_controller_types) || {}
= select_tag('Controller',
options_for_select(options),
Expand All @@ -187,13 +189,13 @@
"data-width" => "auto",
"required" => "",
"selectpicker-for-select-tag" => "")
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
%input{"bs-switch" => "",
:data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'},
"type" => "checkbox",
"name" => "vm.cb_dependent",
"ng-model" => "vm.reconfigureModel.cb_dependent"}
%td
%td{"ng-hide" => "vm.vm_type.includes('Vmware::CloudManager')"}
%td{"ng-if" => @reconfigitems.first.vendor == 'redhat'}
%input{"bs-switch" => "",
:data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'},
Expand All @@ -213,9 +215,9 @@
{{disk.hdFilename}}
%td
{{disk.hdType}}
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
{{disk.hdMode}}
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
{{disk.new_controller_type}}
%td{"ng-if" => "disk.add_remove != 'resizing'"}
{{disk.hdSize}}
Expand Down Expand Up @@ -244,7 +246,7 @@
"data-width" => "auto",
"required" => "",
"selectpicker-for-select-tag" => "")
%td{"ng-if" => @reconfigitems.first.vendor == 'vmware'}
%td{"ng-if" => "vm.vm_type.includes('Vmware::InfraManager')"}
%input{"bs-switch" => "",
:data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'},
"type" => "checkbox",
Expand All @@ -253,7 +255,7 @@
"switch-active" => "{{disk.add_remove!='add'}}",
"ng-readonly" => "disk.add_remove=='add'",
"ng-if" => "disk.add_remove=='add'"}
%td
%td{"ng-hide" => "vm.vm_type.includes('Vmware::CloudManager')"}
%input{"bs-switch" => "",
:data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'},
"type" => "checkbox",
Expand Down

0 comments on commit 1276141

Please sign in to comment.