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

Support base snapshot for EBS cloud volume provisioning #1324

Merged
merged 1 commit into from
Jun 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API

if (cloudVolumeFormId !== 'new') {
// Fetch cloud volume data before showing the form.
API.get('/api/cloud_volumes/' + cloudVolumeFormId + '?attributes=ext_management_system.type,availability_zone.ems_ref')
API.get('/api/cloud_volumes/' + cloudVolumeFormId + '?attributes=ext_management_system.type,availability_zone.ems_ref,base_snapshot.ems_ref')
.then(getCloudVolumeFormData)
.catch(miqService.handleFailure);
} else {
Expand Down Expand Up @@ -113,7 +113,7 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API

vm.storageManagerChanged = function(id) {
miqService.sparkleOn();
API.get('/api/providers/' + id + '?attributes=type,parent_manager.availability_zones,parent_manager.cloud_tenants')
API.get('/api/providers/' + id + '?attributes=type,parent_manager.availability_zones,parent_manager.cloud_tenants,parent_manager.cloud_volume_snapshots')
.then(getStorageManagerFormData)
.catch(miqService.handleFailure);
};
Expand Down Expand Up @@ -214,6 +214,11 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
vm.cloudVolumeModel.aws_volume_type = data.volume_type;
vm.cloudVolumeModel.aws_availability_zone_id = data.availability_zone.ems_ref;

// If volume was created from snapshot and this snapshot still exists
if (data.base_snapshot) {
vm.cloudVolumeModel.aws_base_snapshot_id = data.base_snapshot.ems_ref;
}

// Update the IOPS based on the current volume size.
vm.sizeChanged(vm.cloudVolumeModel.size);

Expand All @@ -224,6 +229,7 @@ ManageIQ.angular.app.controller('cloudVolumeFormController', ['miqService', 'API
vm.cloudVolumeModel.emstype = data.type;
vm.cloudTenantChoices = data.parent_manager.cloud_tenants;
vm.availabilityZoneChoices = data.parent_manager.availability_zones;
vm.baseSnapshotChoices = data.parent_manager.cloud_volume_snapshots;

miqService.sparkleOff();
};
Expand Down
39 changes: 26 additions & 13 deletions app/controllers/cloud_volume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,24 +684,37 @@ def form_params_create
# Depending on the storage manager type, collect required form params.
case params[:emstype]
when "ManageIQ::Providers::StorageManager::CinderManager"
cloud_tenant_id = params[:cloud_tenant_id] if params[:cloud_tenant_id]
cloud_tenant = find_record_with_rbac(CloudTenant, cloud_tenant_id)
options[:cloud_tenant] = cloud_tenant
options[:ems] = cloud_tenant.ext_management_system
options.merge!(cinder_manager_options)
when "ManageIQ::Providers::Amazon::StorageManager::Ebs"
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[:availability_zone] = params[:aws_availability_zone_id] if params[:aws_availability_zone_id]
options[:encrypted] = params[:aws_encryption]

# Get the storage manager.
storage_manager_id = params[:storage_manager_id] if params[:storage_manager_id]
options[:ems] = find_record_with_rbac(ExtManagementSystem, storage_manager_id)
options.merge!(aws_ebs_options)
end
options
end

def cinder_manager_options
options = {}
cloud_tenant_id = params[:cloud_tenant_id] if params[:cloud_tenant_id]
cloud_tenant = find_record_with_rbac(CloudTenant, cloud_tenant_id)
options[:cloud_tenant] = cloud_tenant
options[:ems] = cloud_tenant.ext_management_system
options
end

def aws_ebs_options
options = {}
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[:availability_zone] = params[:aws_availability_zone_id] if params[:aws_availability_zone_id]
options[:snapshot_id] = params[:aws_base_snapshot_id] if params[:aws_base_snapshot_id]
options[:encrypted] = params[:aws_encryption]

# Get the storage manager.
storage_manager_id = params[:storage_manager_id] if params[:storage_manager_id]
options[:ems] = find_record_with_rbac(ExtManagementSystem, storage_manager_id)
options
end

# dispatches tasks to multiple volumes
def process_cloud_volumes(volumes, task)
return if volumes.empty?
Expand Down
14 changes: 14 additions & 0 deletions app/views/cloud_volume/_common_new_edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@
%span.help-block{"ng-show" => "vm.cloudVolumeModel.aws_volume_type == 'io1' && angularForm.aws_iops.$error.required"}
= _("Required")
.form-group{"ng-if" => "vm.cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('Base Snapshot')
.col-md-8
%select{"name" => "aws_base_snapshot_id",
"ng-model" => "vm.cloudVolumeModel.aws_base_snapshot_id",
"ng-options" => "vs.ems_ref as vs.name for vs in vm.baseSnapshotChoices",
"ng-disabled" => "!vm.newRecord",
:checkchange => true,
"data-live-search" => "true",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it work with true (instead of "true")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work with true instead of "true".

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

"pf-select" => true}
%option{"value" => "", "enabled" => ""}
= _('No snapshot')
.form-group{"ng-if" => "vm.cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs'"}
%label.col-md-2.control-label
= _('Encryption')
Expand Down