-
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.
- Loading branch information
Showing
11 changed files
with
404 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
app/assets/javascripts/controllers/vm_cloud/vm_cloud_add_security_group_form_controller.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,40 @@ | ||
ManageIQ.angular.app.controller('vmCloudAddSecurityGroupFormController', ['$http', 'vmCloudAddSecurityGroupFormId', 'miqService', function($http, vmCloudAddSecurityGroupFormId, miqService) { | ||
var vm = this; | ||
|
||
var init = function() { | ||
vm.afterGet = false; | ||
vm.vmCloudModel = { | ||
security_group: null, | ||
}; | ||
vm.security_groups = []; | ||
vm.formId = vmCloudAddSecurityGroupFormId; | ||
vm.model = "vmCloudModel"; | ||
vm.saveable = miqService.saveable; | ||
miqService.sparkleOn(); | ||
$http.get('/vm_cloud/add_security_group_form_fields/' + vmCloudAddSecurityGroupFormId).then(function(response) { | ||
var data = response.data; | ||
vm.security_groups = data.security_groups; | ||
vm.afterGet = true; | ||
vm.modelCopy = angular.copy( vm.vmCloudModel ); | ||
}).catch(miqService.handleFailure); | ||
miqService.sparkleOff(); | ||
}; | ||
|
||
vm.cancelClicked = function() { | ||
var url = '/vm_cloud/add_security_group_vm/' + vmCloudAddSecurityGroupFormId + '?button=cancel'; | ||
miqService.miqAjaxButton(url); | ||
}; | ||
|
||
vm.resetClicked = function(angularForm) { | ||
vm.CloudModel = angular.copy( vm.modelCopy ); | ||
angularForm.$setPristine(true); | ||
miqService.miqFlash("warn", "All changes have been reset"); | ||
}; | ||
|
||
vm.saveClicked = function() { | ||
var url = '/vm_cloud/add_security_group_vm/' + vmCloudAddSecurityGroupFormId + '?button=submit'; | ||
miqService.miqAjaxButton(url, vm.vmCloudModel, { complete: false }); | ||
}; | ||
|
||
init(); | ||
}]); |
40 changes: 40 additions & 0 deletions
40
...assets/javascripts/controllers/vm_cloud/vm_cloud_remove_security_group_form_controller.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,40 @@ | ||
ManageIQ.angular.app.controller('vmCloudRemoveSecurityGroupFormController', ['$http', 'vmCloudRemoveSecurityGroupFormId', 'miqService', function($http, vmCloudRemoveSecurityGroupFormId, miqService) { | ||
var vm = this; | ||
|
||
var init = function() { | ||
vm.afterGet = false; | ||
vm.vmCloudModel = { | ||
security_group: null, | ||
}; | ||
vm.security_groups = []; | ||
vm.formId = vmCloudRemoveSecurityGroupFormId; | ||
vm.model = "vmCloudModel"; | ||
vm.saveable = miqService.saveable; | ||
miqService.sparkleOn(); | ||
$http.get('/vm_cloud/remove_security_group_form_fields/' + vmCloudRemoveSecurityGroupFormId).then(function(response) { | ||
var data = response.data; | ||
vm.security_groups = data.security_groups; | ||
vm.afterGet = true; | ||
vm.modelCopy = angular.copy( vm.vmCloudModel ); | ||
}).catch(miqService.handleFailure); | ||
miqService.sparkleOff(); | ||
}; | ||
|
||
vm.cancelClicked = function() { | ||
var url = '/vm_cloud/remove_security_group_vm/' + vmCloudRemoveSecurityGroupFormId + '?button=cancel'; | ||
miqService.miqAjaxButton(url); | ||
}; | ||
|
||
vm.resetClicked = function(angularForm) { | ||
vm.CloudModel = angular.copy( vm.modelCopy ); | ||
angularForm.$setPristine(true); | ||
miqService.miqFlash("warn", "All changes have been reset"); | ||
}; | ||
|
||
vm.saveClicked = function() { | ||
var url = '/vm_cloud/remove_security_group_vm/' + vmCloudRemoveSecurityGroupFormId + '?button=submit'; | ||
miqService.miqAjaxButton(url, vm.vmCloudModel, { complete: false }); | ||
}; | ||
|
||
init(); | ||
}]); |
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
106 changes: 106 additions & 0 deletions
106
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,106 @@ | ||
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 | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to :controller => 'vm', | ||
:action => 'add_security_group', | ||
:rec_id => @record.id, | ||
:escape => false | ||
end | ||
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]) | ||
drop_breadcrumb( | ||
:name => _("Add Security Group to '%{name}'") % {:name => @record.name}, | ||
:url => "/vm_cloud/add_security_group" | ||
) unless @explorer | ||
@sb[:explorer] = @explorer | ||
@in_a_form = true | ||
@add_security_group = true | ||
render :action => "show" unless @explorer | ||
end | ||
|
||
def add_security_group_form_fields | ||
assert_privileges("instance_add_security_group") | ||
@record = find_record_with_rbac(VmCloud, params[:id]) | ||
security_groups = @record.cloud_tenant.nil? ? [] : @record.cloud_tenant.security_groups - @record.security_groups | ||
render :json => { | ||
:security_groups => security_groups | ||
} | ||
end | ||
|
||
def add_security_group_vm | ||
assert_privileges("instance_add_security_group") | ||
@record = find_record_with_rbac(VmCloud, params[:id]) | ||
case params[:button] | ||
when "cancel" then add_handle_cancel_button | ||
when "submit" then add_handle_submit_button | ||
end | ||
|
||
if @sb[:explorer] | ||
replace_right_cell | ||
else | ||
session[:flash_msgs] = @flash_array.dup | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to previous_breadcrumb_url | ||
end | ||
end | ||
end | ||
|
||
def add_handle_cancel_button | ||
add_flash(_("Addition of Security Group to Instance \"%{name}\" was cancelled by the user") % {:name => @record.name}) | ||
@record = @sb[:action] = nil | ||
end | ||
|
||
def add_handle_submit_button | ||
if @record.supports_add_security_group? | ||
security_group = params[:security_group]["name"] | ||
begin | ||
@record.add_security_group_queue(session[:userid], security_group) | ||
add_flash(_("Adding Security Group %{security_group} to Instance \"%{name}\"") % { | ||
:security_group => security_group, | ||
:name => @record.name | ||
}) | ||
rescue => ex | ||
add_flash(_("Unable to add Security Group %{security_group} to Instance \"%{name}\": %{details}") % { | ||
:security_group => security_group, | ||
:name => @record.name, | ||
:details => get_error_message_from_fog(ex.to_s) | ||
}, :error) | ||
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 | ||
params[:id] = @record.id.to_s # reset id in params for show | ||
@record = nil | ||
@sb[:action] = nil | ||
end | ||
end | ||
end | ||
end | ||
end |
112 changes: 112 additions & 0 deletions
112
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,112 @@ | ||
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 | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to :controller => 'vm', | ||
:action => 'remove_security_group', | ||
:rec_id => @record.id, | ||
:escape => false | ||
end | ||
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]) | ||
drop_breadcrumb( | ||
:name => _("Remove Security Group to '%{name}'") % {:name => @record.name}, | ||
:url => "/vm_cloud/remove_security_group" | ||
) unless @explorer | ||
@sb[:explorer] = @explorer | ||
@in_a_form = true | ||
@remove_security_group = true | ||
render :action => "show" unless @explorer | ||
end | ||
|
||
def remove_security_group_form_fields | ||
assert_privileges("instance_remove_security_group") | ||
@record = find_record_with_rbac(VmCloud, params[:id]) | ||
security_groups = [] | ||
unless @record.ext_management_system.nil? | ||
@record.security_groups.each do |security_group| | ||
security_groups << security_group | ||
end | ||
end | ||
render :json => { | ||
:security_groups => security_groups | ||
} | ||
end | ||
|
||
def remove_security_group_vm | ||
assert_privileges("instance_remove_security_group") | ||
@record = find_record_with_rbac(VmCloud, params[:id]) | ||
case params[:button] | ||
when "cancel" then remove_handle_cancel_button | ||
when "submit" then remove_handle_submit_button | ||
end | ||
end | ||
|
||
private | ||
|
||
def remove_handle_cancel_button | ||
add_flash(_("Removal of Security Group from Instance \"%{name}\" was cancelled by the user") % {:name => @record.name}) | ||
@record = @sb[:action] = nil | ||
end | ||
|
||
def remove_handle_submit_button | ||
if @record.supports_remove_security_group? | ||
security_group = params[:security_group]["name"] | ||
begin | ||
@record.remove_security_group_queue(session[:userid], security_group) | ||
add_flash(_("Removing Security Group %{security_group} from Instance \"%{name}\"") % { | ||
:security_group => security_group, | ||
:name => @record.name | ||
}) | ||
rescue => ex | ||
add_flash(_("Unable to remove Security Group %{security_group} from Instance \"%{name}\": %{details}") % { | ||
:security_group => security_group, | ||
:name => @record.name, | ||
:details => get_error_message_from_fog(ex.to_s) | ||
}, :error) | ||
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 | ||
params[:id] = @record.id.to_s # reset id in params for show | ||
@record = nil | ||
@sb[:action] = nil | ||
if @sb[:explorer] | ||
replace_right_cell | ||
else | ||
session[:flash_msgs] = @flash_array.dup | ||
render :update do |page| | ||
page << javascript_prologue | ||
page.redirect_to previous_breadcrumb_url | ||
end | ||
end | ||
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
Oops, something went wrong.