-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1997 from tzumainn/vm-security-group-operations
Add vm security group operations
- Loading branch information
Showing
15 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/assets/javascripts/components/vm_cloud/vm-cloud-add-security-group-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
ManageIQ.angular.app.component('vmCloudAddSecurityGroupComponent', { | ||
bindings: { | ||
recordId: '@', | ||
redirectUrl: '@', | ||
}, | ||
controllerAs: 'vm', | ||
controller: vmCloudAddSecurityGroupFormController, | ||
templateUrl: '/static/vm_cloud/add_security_group.html.haml', | ||
}); | ||
|
||
vmCloudAddSecurityGroupFormController.$inject = ['API', 'miqService', '$q']; | ||
|
||
function vmCloudAddSecurityGroupFormController(API, miqService, $q) { | ||
var vm = this; | ||
|
||
vm.$onInit = function() { | ||
vm.afterGet = false; | ||
vm.vmCloudModel = { | ||
security_group: '', | ||
}; | ||
vm.security_groups = []; | ||
vm.formId = vm.recordId; | ||
vm.saveable = miqService.saveable; | ||
vm.newRecord = true; | ||
miqService.sparkleOn(); | ||
|
||
var currentSecurityGroups; | ||
|
||
$q.all([ | ||
API.get("/api/instances/" + vm.recordId), | ||
API.get("/api/instances/" + vm.recordId + "/security_groups?expand=resources&attributes=id,name"), | ||
]) | ||
.then(function(data) { | ||
var tenantId = data[0].cloud_tenant_id; | ||
currentSecurityGroups = data[1].resources; | ||
|
||
return API.get("/api/cloud_tenants/" + tenantId + "/security_groups?expand=resources&attributes=id,name"); | ||
}) | ||
.then(function(data) { | ||
vm.security_groups = data.resources.filter(function(securityGroup) { | ||
return ! _.find(currentSecurityGroups, { id: securityGroup.id }); | ||
}); | ||
|
||
vm.afterGet = true; | ||
miqService.sparkleOff(); | ||
}).catch(miqService.handleFailure); | ||
}; | ||
|
||
vm.cancelClicked = function() { | ||
miqService.sparkleOn(); | ||
miqService.redirectBack(sprintf(__('Addition of security group was canceled by the user.')), 'warning', vm.redirectUrl); | ||
}; | ||
|
||
vm.addClicked = function() { | ||
var saveObject = { | ||
name: vm.vmCloudModel.security_group, | ||
action: 'add', | ||
}; | ||
var saveMsg = sprintf(__('%s has been successfully added.'), vm.vmCloudModel.security_group); | ||
miqService.sparkleOn(); | ||
API.post('/api/instances/' + vm.recordId + '/security_groups/', saveObject) | ||
.then(miqService.redirectBack.bind(vm, saveMsg, 'success', vm.redirectUrl)) | ||
.catch(miqService.handleFailure); | ||
}; | ||
} |
50 changes: 50 additions & 0 deletions
50
app/assets/javascripts/components/vm_cloud/vm-cloud-remove-security-group-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
ManageIQ.angular.app.component('vmCloudRemoveSecurityGroupComponent', { | ||
bindings: { | ||
recordId: '@', | ||
redirectUrl: '@', | ||
}, | ||
controllerAs: 'vm', | ||
controller: vmCloudRemoveSecurityGroupFormController, | ||
templateUrl: '/static/vm_cloud/remove_security_group.html.haml', | ||
}); | ||
|
||
vmCloudRemoveSecurityGroupFormController.$inject = ['API', 'miqService']; | ||
|
||
function vmCloudRemoveSecurityGroupFormController(API, miqService) { | ||
var vm = this; | ||
|
||
vm.$onInit = function() { | ||
vm.afterGet = false; | ||
vm.vmCloudModel = { | ||
security_group: '', | ||
}; | ||
vm.security_groups = []; | ||
vm.formId = vm.recordId; | ||
vm.model = "vmCloudModel"; | ||
vm.saveable = miqService.saveable; | ||
vm.newRecord = false; | ||
miqService.sparkleOn(); | ||
API.get("/api/instances/" + vm.recordId + "/security_groups?expand=resources&attributes=id,name").then(function(data) { | ||
vm.security_groups = data.resources; | ||
vm.afterGet = true; | ||
miqService.sparkleOff(); | ||
}).catch(miqService.handleFailure); | ||
}; | ||
|
||
vm.cancelClicked = function() { | ||
miqService.sparkleOn(); | ||
miqService.redirectBack(sprintf(__('Removal of security group was canceled by the user.')), 'warning', vm.redirectUrl); | ||
}; | ||
|
||
vm.saveClicked = function() { | ||
var saveObject = { | ||
name: vm.vmCloudModel.security_group, | ||
action: 'remove', | ||
}; | ||
var saveMsg = sprintf(__('%s has been successfully removed.'), vm.vmCloudModel.security_group); | ||
miqService.sparkleOn(); | ||
API.post('/api/instances/' + vm.recordId + '/security_groups/', saveObject) | ||
.then(miqService.redirectBack.bind(vm, saveMsg, 'success', vm.redirectUrl)) | ||
.catch(miqService.handleFailure); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/controllers/mixins/actions/vm_actions/add_security_group.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Mixins | ||
module Actions | ||
module VmActions | ||
module AddSecurityGroup | ||
def add_security_group_vms | ||
assert_privileges("instance_add_security_group") | ||
recs = checked_or_params | ||
@record = find_record_with_rbac(VmCloud, recs.first) | ||
if @record.supports_add_security_group? && @record.ext_management_system.present? | ||
if @explorer | ||
add_security_group | ||
@refresh_partial = "vm_common/add_security_group" | ||
else | ||
javascript_redirect :controller => 'vm', :action => 'add_security_group', :rec_id => @record.id, :escape => false | ||
end | ||
else | ||
add_flash(_("Unable to add Security Group to Instance \"%{name}\": %{details}") % { | ||
:name => @record.name, | ||
:details => @record.unsupported_reason(:add_security_group) | ||
}, :error) | ||
end | ||
end | ||
|
||
alias instance_add_security_group add_security_group_vms | ||
|
||
def add_security_group | ||
assert_privileges("instance_add_security_group") | ||
@record ||= find_record_with_rbac(VmCloud, params[:rec_id]) | ||
unless @explorer | ||
drop_breadcrumb( | ||
:name => _("Add Security Group to '%{name}'") % {:name => @record.name}, | ||
:url => "/vm_cloud/add_security_group" | ||
) | ||
end | ||
@sb[:explorer] = @explorer | ||
@in_a_form = true | ||
@add_security_group = true | ||
render :action => "show" unless @explorer | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
app/controllers/mixins/actions/vm_actions/remove_security_group.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Mixins | ||
module Actions | ||
module VmActions | ||
module RemoveSecurityGroup | ||
def remove_security_group_vms | ||
assert_privileges("instance_remove_security_group") | ||
recs = checked_or_params | ||
@record = find_record_with_rbac(VmCloud, recs.first) | ||
if @record.supports_remove_security_group? && @record.ext_management_system.present? | ||
if @explorer | ||
remove_security_group | ||
@refresh_partial = "vm_common/remove_security_group" | ||
else | ||
javascript_redirect :controller => 'vm', :action => 'remove_security_group', :rec_id => @record.id, :escape => false | ||
end | ||
else | ||
add_flash(_("Unable to remove Security Group from Instance \"%{name}\": %{details}") % { | ||
:name => @record.name, | ||
:details => @record.unsupported_reason(:remove_security_group) | ||
}, :error) | ||
end | ||
end | ||
|
||
alias instance_remove_security_group remove_security_group_vms | ||
|
||
def remove_security_group | ||
assert_privileges("instance_remove_security_group") | ||
@record ||= find_record_with_rbac(VmCloud, params[:rec_id]) | ||
unless @explorer | ||
drop_breadcrumb( | ||
:name => _("Remove Security Group to '%{name}'") % {:name => @record.name}, | ||
:url => "/vm_cloud/remove_security_group" | ||
) | ||
end | ||
@sb[:explorer] = @explorer | ||
@in_a_form = true | ||
@remove_security_group = true | ||
render :action => "show" unless @explorer | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%form#form_div{"name" => "angularForm", | ||
"form-changed" => true, | ||
"miq-form" => true, | ||
"model" => "vm.vmCloudModel", | ||
"ng-cloak" => "", | ||
"ng-show" => "vm.afterGet"} | ||
= render :partial => "layouts/flash_msg" | ||
%h3 | ||
= _('Add Security Group') | ||
.form-horizontal | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Security Group') | ||
.col-md-8 | ||
%select{"name" => "security_group", | ||
"ng-model" => "vm.vmCloudModel.security_group", | ||
"ng-options" => "security_group.name as security_group.name for security_group in vm.security_groups", | ||
"pf-select" => true, | ||
"required" => "", | ||
"selectpicker-for-select-tag" => ""} | ||
= render :partial => "layouts/angular/generic_form_buttons" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%form#form_div{"name" => "angularForm", | ||
"form-changed" => true, | ||
"miq-form" => true, | ||
"model" => "vm.vmCloudModel", | ||
"ng-cloak" => "", | ||
"ng-show" => "vm.afterGet"} | ||
= render :partial => "layouts/flash_msg" | ||
%h3 | ||
= _('Remove Security Group') | ||
.form-horizontal | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Security Group') | ||
.col-md-8 | ||
%select{"name" => "security_group", | ||
"ng-model" => "vm.vmCloudModel.security_group", | ||
"ng-options" => "security_group.name as security_group.name for security_group in vm.security_groups", | ||
"pf-select" => true, | ||
"required" => "", | ||
"selectpicker-for-select-tag" => ""} | ||
= render :partial => "layouts/angular/generic_form_buttons" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- @angular_form = true | ||
|
||
= render :partial => "layouts/flash_msg" | ||
|
||
%vm-cloud-add-security-group-component{"record-id" => @record.id, | ||
"redirect-url" => "/#{controller_name}/explorer",} | ||
|
||
:javascript | ||
miq_bootstrap('vm-cloud-add-security-group-component'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- @angular_form = true | ||
|
||
= render :partial => "layouts/flash_msg" | ||
|
||
%vm-cloud-remove-security-group-component{"record-id" => @record.id, | ||
"redirect-url" => "/#{controller_name}/explorer",} | ||
|
||
:javascript | ||
miq_bootstrap('vm-cloud-remove-security-group-component'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.