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

Enable new cloud volume for provider #715

Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angular.app.controller('cloudVolumeFormController', ['$http', '$scope', 'cloudVolumeFormId', 'miqService', 'API', function($http, $scope, cloudVolumeFormId, miqService, API) {
ManageIQ.angular.app.controller('cloudVolumeFormController', ['$scope', 'miqService', 'API', 'cloudVolumeFormId', 'storageManagerId', function($scope, miqService, API, cloudVolumeFormId, storageManagerId) {
var init = function() {
$scope.cloudVolumeModel = {
aws_encryption: false,
Expand All @@ -14,7 +14,7 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['$http', '$scope',
{ type: "io1", name: "Provisioned IOPS SSD (IO1)" },
{ type: "st1", name: "Throughput Optimized HDD (ST1)" },
{ type: "sc1", name: "Cold HDD (SC1)" },
{ type: "magnetic", name: "Magnetic" },
{ type: "standard", name: "Magnetic" },
];

ManageIQ.angular.scope = $scope;
Expand All @@ -23,17 +23,26 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['$http', '$scope',
$scope.cloudVolumeModel.name = "";
} else {
miqService.sparkleOn();
$http.get('/cloud_volume/cloud_volume_form_fields/' + cloudVolumeFormId)
API.get('/api/cloud_volumes/' + cloudVolumeFormId + '?attributes=ext_management_system.type')
.then(getCloudVolumeFormDataComplete)
.catch(miqService.handleFailure);
}
};

function getCloudVolumeFormDataComplete(response) {
var data = response.data;
if (storageManagerId) {
$scope.cloudVolumeModel.storage_manager_id = storageManagerId;
$scope.storageManagerChanged(storageManagerId);
}
};

function getCloudVolumeFormDataComplete(data) {
$scope.afterGet = true;
$scope.cloudVolumeModel.emstype = data.ext_management_system.type;
$scope.cloudVolumeModel.name = data.name;
// We have to display size in GB.
$scope.cloudVolumeModel.size = data.size / 1073741824;
// Currently, this is only relevant for AWS volumes so we are prefixing the
// model attribute with AWS.
$scope.cloudVolumeModel.aws_volume_type = data.volume_type;

$scope.modelCopy = angular.copy( $scope.cloudVolumeModel );
miqService.sparkleOff();
Expand Down
25 changes: 12 additions & 13 deletions app/controllers/cloud_volume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ def show
replace_gtl_main_div if pagination_request?
end

def cloud_volume_form_fields
assert_privileges("cloud_volume_edit")
volume = find_by_id_filtered(CloudVolume, params[:id])
render :json => {
:name => volume.name
}
end

def attach
params[:id] = checked_item_id unless params[:id].present?
assert_privileges("cloud_volume_attach")
Expand Down Expand Up @@ -278,7 +270,13 @@ def new
@volume = CloudVolume.new
@in_a_form = true
@storage_manager_choices = {}
ExtManagementSystem.all.each { |ems| @storage_manager_choices[ems.name] = ems.id if ems.supports_block_storage? }
if params[:storage_manager_id]
@storage_manager_id = params[:storage_manager_id]
ems = find_by_id_filtered(ExtManagementSystem, @storage_manager_id)
@storage_manager_choices[ems.name] = ems.id
else
ExtManagementSystem.all.each { |ems| @storage_manager_choices[ems.name] = ems.id if ems.supports_block_storage? }
end
drop_breadcrumb(
:name => _("Add New %{model}") % {:model => ui_lookup(:table => 'cloud_volume')},
:url => "/cloud_volume/new"
Expand All @@ -289,8 +287,7 @@ def create
assert_privileges("cloud_volume_new")
case params[:button]
when "cancel"
javascript_redirect :action => 'show_list',
:flash_msg => _("Add of new %{model} was cancelled by the user") % {:model => ui_lookup(:table => 'cloud_volume')}
cancel_action(_("Add of new %{model} was cancelled by the user") % {:model => ui_lookup(:table => 'cloud_volume')})

when "add"
@volume = CloudVolume.new
Expand Down Expand Up @@ -345,11 +342,10 @@ def create_finished
}, :error)
end

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

javascript_redirect :action => "show_list"
javascript_redirect previous_breadcrumb_url
end

def edit
Expand Down Expand Up @@ -696,6 +692,9 @@ def form_params
options[:cloud_tenant_id] = params[:cloud_tenant_id] if params[:cloud_tenant_id]
options[:vm_id] = params[:vm_id] if params[:vm_id]
options[:device_path] = params[:device_path] if params[:device_path]
options[:volume_type] = params[:aws_volume_type] if params[:aws_volume_type]
# Only set IOPS if io1 (provisioned IOPS) and IOPS available
options[:iops] = params[:aws_iops] if options[:volume_type] == 'io1' && params[:aws_iops]
options
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/ems_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ def button
javascript_redirect :controller => "host_aggregate", :action => "edit", :id => find_checked_items[0]
elsif params[:pressed] == "cloud_tenant_edit"
javascript_redirect :controller => "cloud_tenant", :action => "edit", :id => find_checked_items[0]
elsif params[:pressed] == "cloud_volume_new"
javascript_redirect :controller => "cloud_volume", :action => "new", :storage_manager_id => params[:id]
elsif params[:pressed] == "cloud_volume_edit"
javascript_redirect :controller => "cloud_volume", :action => "edit", :id => find_checked_items[0]
elsif params[:pressed].ends_with?("_edit") || ["#{pfx}_miq_request_new", "#{pfx}_clone",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ApplicationHelper::Button::Mixins::SubListViewScreenMixin
def sub_list_view_screen?
@lastaction == 'show' && [email protected]?(%w(main vms instances all_vms))
@lastaction == 'show' && [email protected]?(%w(main vms instances all_vms cloud_volumes))
end
end
60 changes: 60 additions & 0 deletions app/views/cloud_volume/_common_new_edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.form-group{"ng-class" => "{'has-error': angularForm.name.$invalid}"}
%label.col-md-2.control-label
= _('Volume Name')
.col-md-8
%input.form-control{:type => "text",
:name => "name",
'ng-model' => "cloudVolumeModel.name",
'ng-maxlength' => 128,
:required => "",
:checkchange => true}
%span.help-block{"ng-show" => "angularForm.name.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.aws_volume_type.$invalid}",
"ng-if" => "cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('Cloud Volume Type')
.col-md-8
%select{"name" => "aws_volume_type",
"ng-model" => "cloudVolumeModel.aws_volume_type",
"ng-options" => "voltype.type as voltype.name for voltype in awsVolumeTypes",
"ng-change" => "awsVolumeTypeChanged(cloudVolumeModel.aws_volume_type)",
"ng-disabled" => "formId != 'new' && cloudVolumeModel.aws_volume_type == 'standard'",
"required" => "",
:checkchange => true,
"selectpicker-for-select-tag" => ""}
%option{"value" => "", "disabled" => ""}
= "<#{_('Choose')}>"
%span.help-block{"ng-show" => "angularForm.aws_volume_type.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.size.$invalid}"}
%label.col-md-2.control-label
= _('Size (in gigabytes)')
.col-md-8
%input.form-control{:type => "text",
:name => "size",
'ng-model' => "cloudVolumeModel.size",
'ng-maxlength' => 10,
'ng-change' => "sizeChanged(cloudVolumeModel.size)",
'ng-disabled' => "formId != 'new' && (cloudVolumeModel.emstype != 'ManageIQ::Providers::Amazon::StorageManager::Ebs' || cloudVolumeModel.aws_volume_type == 'standard')",
:required => "",
:checkchange => true}
%span.help-block{"ng-show" => "angularForm.size.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.aws_iops.$invalid}",
"ng-if" => "cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('IOPS')
.col-md-8
%input.form-control{:type => "text",
:name => "aws_iops",
'ng-model' => "cloudVolumeModel.aws_iops",
'ng-maxlength' => 50,
'ng-disabled' => "cloudVolumeModel.aws_volume_type != 'io1'",
"ng-required" => "cloudVolumeModel.aws_volume_type == 'io1'",
:checkchange => true}
%span.help-block{"ng-show" => "cloudVolumeModel.aws_volume_type == 'io1' && angularForm.aws_iops.$error.required"}
= _("Required")
13 changes: 2 additions & 11 deletions app/views/cloud_volume/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
%form#form_div{:name => "angularForm", 'ng-controller' => "cloudVolumeFormController"}
%form#form_div{:name => "angularForm", 'ng-controller' => "cloudVolumeFormController", "ng-cloak" => ""}
= render :partial => "layouts/flash_msg"
%h3
= _('Edit Volume')
.form-horizontal
.form-group
%label.col-md-2.control-label
= _('Volume Name')
.col-md-8
%input.form-control{:type => "text",
:name => "name",
'ng-model' => "cloudVolumeModel.name",
'ng-maxlength' => 128,
:miqrequired => false,
:checkchange => true}
= render :partial => "common_new_edit"

%table{:width => '100%'}
%tr
Expand Down
63 changes: 4 additions & 59 deletions app/views/cloud_volume/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
= _('Storage Manager')
.col-md-8
= select_tag("storage_manager_id",
options_for_select([["<#{_('Choose')}>", nil]] + @storage_manager_choices.sort, disabled: ["<#{_('Choose')}>", nil]),
options_for_select((@storage_manager_id.nil? ? [["<#{_('Choose')}>", nil]] : []) + @storage_manager_choices.sort, disabled: ["<#{_('Choose')}>", nil]),
Copy link
Contributor

Choose a reason for hiding this comment

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

@gberginc This is something similar to what I suggested to @miha-plesko .
If we could use an API to retrieve the Storage Managers, that would be perfect...
(can be totally done in a follow-up PR)

"ng-model" => "cloudVolumeModel.storage_manager_id",
"ng-change" => "storageManagerChanged(cloudVolumeModel.storage_manager_id)",
"required" => "",
"disabled" => !@storage_manager_id.nil?,
:checkchange => true,
"selectpicker-for-select-tag" => "")
%span.help-block{"ng-show" => "angularForm.storage_manager_id.$error.required"}
Expand Down Expand Up @@ -47,64 +48,7 @@
%span.help-block{"ng-show" => "angularForm.aws_availability_zone_id.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.name.$invalid}"}
%label.col-md-2.control-label
= _('Volume Name')
.col-md-8
%input.form-control{:type => "text",
:name => "name",
'ng-model' => "cloudVolumeModel.name",
'ng-maxlength' => 128,
:required => "",
:checkchange => true}
%span.help-block{"ng-show" => "angularForm.name.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.aws_volume_type.$invalid}",
"ng-if" => "cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('Cloud Volume Type')
.col-md-8
%select{"name" => "aws_volume_type",
"ng-model" => "cloudVolumeModel.aws_volume_type",
"ng-options" => "voltype.type as voltype.name for voltype in awsVolumeTypes",
"ng-change" => "awsVolumeTypeChanged(cloudVolumeModel.aws_volume_type)",
"required" => "",
:checkchange => true,
"selectpicker-for-select-tag" => ""}
%option{"value" => "", "disabled" => ""}
= "<#{_('Choose')}>"
%span.help-block{"ng-show" => "angularForm.aws_volume_type.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.size.$invalid}"}
%label.col-md-2.control-label
= _('Size (in gigabytes)')
.col-md-8
%input.form-control{:type => "text",
:name => "size",
'ng-model' => "cloudVolumeModel.size",
'ng-maxlength' => 10,
'ng-change' => "sizeChanged(cloudVolumeModel.size)",
:required => "",
:checkchange => true}
%span.help-block{"ng-show" => "angularForm.size.$error.required"}
= _("Required")

.form-group{"ng-class" => "{'has-error': angularForm.aws_iops.$invalid}",
"ng-if" => "cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('IOPS')
.col-md-8
%input.form-control{:type => "text",
:name => "aws_iops",
'ng-model' => "cloudVolumeModel.aws_iops",
'ng-maxlength' => 50,
'ng-disabled' => "cloudVolumeModel.aws_volume_type != 'io1'",
"required" => "",
:checkchange => true}
%span.help-block{"ng-show" => "cloudVolumeModel.aws_volume_type == 'io1' && angularForm.aws_iops.$error.required"}
= _("Required")
= render :partial => "common_new_edit"

.form-group{"ng-if" => "cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
Expand Down Expand Up @@ -144,4 +88,5 @@

:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id || "new"}');
ManageIQ.angular.app.value('storageManagerId', '#{@storage_manager_id}');
miq_bootstrap('#form_div');
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@
backup_select
snapshot_new
edit
cloud_volume_form_fields
cloud_volume_tenants
index
new
Expand Down