1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F #4453: Sec. Groups VNets (#4747)

This commit is contained in:
Frederick Borges 2020-05-18 15:32:19 +02:00 committed by GitHub
parent 8deef3a3f8
commit 0241fe580b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 494 additions and 5 deletions

View File

@ -804,6 +804,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -804,6 +804,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: false
Network.remove_secgroup: false
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -797,6 +797,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -807,6 +807,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -805,6 +805,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: false
Network.remove_secgroup: false
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -798,6 +798,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -804,6 +804,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -805,6 +805,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: false
Network.remove_secgroup: false
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -798,6 +798,8 @@ tabs:
Network.unlock: true
Network.edit_labels: true
Network.menu_labels: true
Network.add_secgroup: true
Network.remove_secgroup: true
vnets-templates-tab:
panel_tabs:
vnet_template_info_tab: true

View File

@ -27,7 +27,8 @@ define(function(require) {
require('./vnets-tab/dialogs/add-ar'),
require('./vnets-tab/dialogs/update-ar'),
require('./vnets-tab/dialogs/reserve'),
require('./vnets-templates-tab/dialogs/instantiate-add-ar')
require('./vnets-templates-tab/dialogs/instantiate-add-ar'),
require('./vnets-tab/dialogs/add-secgroups')
];
var _panels = [

View File

@ -35,6 +35,7 @@ define(function(require) {
var RESERVE_DIALOG_ID = require("./dialogs/reserve/dialogId");
var IMPORT_DIALOG_ID = require("./form-panels/import/formPanelId");
var CLUSTERS_DIALOG_ID = require("utils/dialogs/clusters/dialogId");
var ADD_SECGROUPS_DIALOG_ID = require("./dialogs/add-secgroups/dialogId");
var _commonActions = new CommonActions(OpenNebulaResource, RESOURCE, TAB_ID,
XML_ROOT, Locale.tr("Virtual Network created"));
@ -160,6 +161,32 @@ define(function(require) {
Sunstone.getDialog(CLUSTERS_DIALOG_ID).show();
},
error: Notifier.onError
},
"Network.add_secgroup" : {
type: "single",
call: OpenNebulaResource.append,
callback: function(req) {
// Reset the wizard
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).hide();
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).reset();
Sunstone.runAction("Network.show",req.request.data[0]);
},
error: Notifier.onError
},
"Network.rm_secgroup" : {
type: "single",
call: OpenNebulaResource.update,
callback: function(req) {
// Reset the wizard
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).hide();
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).reset();
Sunstone.runAction("Network.show",req.request.data[0]);
},
error: Notifier.onError
}
};

View File

@ -0,0 +1,123 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./add-secgroups/html');
var SecGroupsTab = require('tabs/vnets-tab/utils/secgroups-tab');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
var TemplateUtils = require("utils/template-utils");
/*
CONSTANTS
*/
var DIALOG_ID = require('./add-secgroups/dialogId');
var TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
this.secgroupTab = new SecGroupsTab();
BaseDialog.call(this);
}
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
Dialog.prototype.setId = _setId;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'secGroupsTabHTML': this.secgroupTab.html("add_secgroup"),
'action': "Network.add_secgroup"
});
}
function _setup(context) {
var that = this;
Foundation.reflow(context, 'abide');
that.secgroupTab.setup(context, "add_secgroup");
$('#submit_secgroups_reset_button', context).click(function(){
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.getDialog(DIALOG_ID).show();
});
$('#add_secgroups_form', context)
.on('forminvalid.zf.abide', function(ev, frm) {
Notifier.notifyError(Locale.tr("One or more required fields are missing."));
})
.on('formvalid.zf.abide', function(ev, frm) {
var current_security_group = $("#value_td_input_SECURITY_GROUPS").text().split(",");
var new_security_groups = [];
for (var i = 0; i < current_security_group.length; i++) {
var security_group = current_security_group[i];
if (security_group != ""){
new_security_groups.push(security_group);
}
}
var selected_security_groups = that.secgroupTab.retrieve()["SECURITY_GROUPS"].split(",");
for (var i = 0; i < selected_security_groups.length; i++) {
var security_group = selected_security_groups[i];
if (current_security_group.indexOf(security_group) < 0){
new_security_groups += "," + security_group;
}
}
var network_json = {};
network_json["SECURITY_GROUPS"] = new_security_groups;
Sunstone.runAction('Network.add_secgroup', that.vnetId, TemplateUtils.templateToString(network_json));
})
.on("submit", function(ev) {
ev.preventDefault();
});
}
function _onShow(context) {
this.setNames( {tabId: TAB_ID} );
this.secgroupTab.onShow();
}
function _setId(id) {
this.vnetId = id;
}
});

View File

@ -0,0 +1,19 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require){
return 'add_secgroups_dialog';
});

View File

@ -0,0 +1,42 @@
{{! -------------------------------------------------------------------------- }}
{{! Copyright 2002-2020, OpenNebula Project, OpenNebula Systems }}
{{! }}
{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }}
{{! not use this file except in compliance with the License. You may obtain }}
{{! a copy of the License at }}
{{! }}
{{! http://www.apache.org/licenses/LICENSE-2.0 }}
{{! }}
{{! Unless required by applicable law or agreed to in writing, software }}
{{! distributed under the License is distributed on an "AS IS" BASIS, }}
{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }}
{{! See the License for the specific language governing permissions and }}
{{! limitations under the License. }}
{{! -------------------------------------------------------------------------- }}
<div id="{{dialogId}}" class="reveal large max-height" data-reveal>
<div class="reveal-body">
<form data-abide novalidate id="add_secgroups_form" action="">
<div class="row">
<h3 class="subheader">
{{tr "Add Security Group"}}
</h3>
</div>
<div class="confirm-resources-header"></div>
{{{secGroupsTabHTML}}}
<div class="reveal-footer">
<div class="form_buttons">
<button class="button radius right success" id="submit_secgroups_button" type="submit" value="{{action}}">
{{tr "Add"}}
</button>
<button id="submit_secgroups_reset_button" class="button secondary radius" type="reset" value="reset">
{{tr "Reset"}}
</button>
</div>
</div>
<button class="close-button" data-close aria-label="{{tr "Close modal"}}" type="button">
<span aria-hidden="true">&times;</span>
</button>
</form>
</div>
</div>

View File

@ -21,16 +21,22 @@ define(function(require) {
var Locale = require('utils/locale');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var SecGroupsTemplate = require('hbs!./secgroups/html');
var Sunstone = require('sunstone');
var Config = require('sunstone-config');
var TemplateUtils = require("utils/template-utils");
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./secgroups/panelId');
var SG_TABLE_ID = PANEL_ID + "SecurityGroupsTable";
var RESOURCE = "Network";
var XML_ROOT = "VNET";
var ADD_SECGROUPS_DIALOG_ID = require('../dialogs/add-secgroups/dialogId');
var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId');
/*
CONSTRUCTOR
*/
@ -74,12 +80,112 @@ define(function(require) {
this.secgroupTable = new SecurityGroupsTable(SG_TABLE_ID, opts);
return this.secgroupTable.dataTableHTML;
return SecGroupsTemplate(
{
'element': this.element,
'tab': "vnets-tab",
'action_add': "Network.add_secgroup",
'action_rm': "Network.remove_secgroup",
'dataTableHTML': this.secgroupTable.dataTableHTML
}
);
}
function _setup(context) {
this.secgroupTable.initialize();
this.secgroupTable.refreshResourceTableSelect();
var that = this;
$("#selected_ids_row_vnet_sg_list_tabSecurityGroupsTable",context).hide();
if (that.secgroupTable){
that.secgroupTable.initialize();
that.secgroupTable.refreshResourceTableSelect();
}
var secGroupDatatable = $("#vnet_sg_list_tabSecurityGroupsTable", context).dataTable({
"bSortClasses" : false,
"bDeferRender": true,
"aoColumnDefs": [
//{ "bSortable": false, "aTargets": [3,4] },
]
});
secGroupDatatable.off("click", 'tbody tr');
secGroupDatatable.on("click", 'tbody tr', function(e){
var aData = secGroupDatatable.fnGetData(this);
if (!aData) return true;
var id = aData[1];
if (!id) return true;
var name = aData[2];
if (!name) return true;
if(that.last_selected_row_secgroup) {
that.last_selected_row_secgroup.children().each(function(){
$(this).removeClass('markrowchecked');
});
}
that.last_selected_row_secgroup = $(this);
$(this).children().each(function(){
$(this).addClass('markrowchecked');
});
$("#rm_secgroup_button", context).attr("secgroups_id", id).attr("secgroups_name", name).removeAttr('disabled');
return false;
});
if (Config.isTabActionEnabled("vnets-tab", "Network.remove_secgroup")) {
context.off("click", 'button#rm_secgroup_button');
context.on("click", 'button#rm_secgroup_button', function(){
var secgroups_id = $(this).attr('secgroups_id');
var secgroups_name = $(this).attr('secgroups_name');
Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({
//header :
headerTabId: TAB_ID,
body : Locale.tr("This will remove the security group") + ' "' + secgroups_name + '"',
//question :
submit : function(){
var current_security_group = that.element.TEMPLATE.SECURITY_GROUPS.split(",");
var new_security_groups = [];
// Get current values of VNet.
var network_json = {}
obj = that.element.TEMPLATE;
for (var key in obj){
var value = obj[key];
network_json[key] = value;
}
for (var i = 0; i < current_security_group.length; i++) {
var security_group = current_security_group[i];
if (security_group != secgroups_id){
new_security_groups.push(security_group);
}
}
network_json["SECURITY_GROUPS"] = new_security_groups.join(",");
Sunstone.runAction('Network.rm_secgroup',that.element.ID,TemplateUtils.templateToString(network_json));
return false;
}
});
Sunstone.getDialog(CONFIRM_DIALOG_ID).reset();
Sunstone.getDialog(CONFIRM_DIALOG_ID).show();
return false;
});
}
if (Config.isTabActionEnabled("vnets-tab", "Network.add_secgroup")) {
context.off("click", 'button#add_secgroup_button');
context.on("click", 'button#add_secgroup_button', function(){
var id = that.element.ID;
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).setId(id);
Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).show();
return false;
});
}
return false;
}

View File

@ -0,0 +1,38 @@
{{! -------------------------------------------------------------------------- }}
{{! Copyright 2002-2020, OpenNebula Project, OpenNebula Systems }}
{{! }}
{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }}
{{! not use this file except in compliance with the License. You may obtain }}
{{! a copy of the License at }}
{{! }}
{{! http://www.apache.org/licenses/LICENSE-2.0 }}
{{! }}
{{! Unless required by applicable law or agreed to in writing, software }}
{{! distributed under the License is distributed on an "AS IS" BASIS, }}
{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }}
{{! See the License for the specific language governing permissions and }}
{{! limitations under the License. }}
{{! -------------------------------------------------------------------------- }}
<form id="secgroups_list_form">
<div class="row">
<div class="large-12 columns">
{{#isTabActionEnabled tab action_add}}
<button class="button success small radius" id="add_secgroup_button">
<span class="fas fa-plus"></span> {{tr "Security Group"}}
</button>
{{/isTabActionEnabled}}
<span class="right">
{{#isTabActionEnabled tab action_rm}}
<button class="button secondary small radius" id="rm_secgroup_button" secgroups_id="" disabled="disabled">
<span class="fas fa-trash-alt"></span> {{tr "Remove"}}
</button>
{{/isTabActionEnabled}}
</span>
</div>
</div>
<div class="row">
{{{dataTableHTML}}}
</div>
</form>

View File

@ -0,0 +1,110 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require) {
// Dependencies
var Locale = require('utils/locale');
var Tips = require('utils/tips');
var CustomTagsTable = require('utils/custom-tags-table');
var WizardFields = require('utils/wizard-fields');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var TemplateHTML = require('hbs!./secgroups-tab/html');
function SecGroupsTab() {
return this;
}
SecGroupsTab.prototype = {
'html': _generate_secgroup_tab_content,
'setup': _setup_secgroup_tab_content,
'onShow': _onShow,
'fill': _fill_secgroup_tab_data,
'retrieve': _retrieve_secgroup_tab_data
};
SecGroupsTab.prototype.constructor = SecGroupsTab;
return SecGroupsTab;
function _generate_secgroup_tab_content(str_secgroup_tab_id){
var current_security_group = $("#value_td_input_SECURITY_GROUPS").text().split(",");
var secgroups = [];
var opts = {
info: false,
select: true,
selectOptions: {
"multiple_choice": true
}
};
this.securityGroupsTable = new SecurityGroupsTable(str_secgroup_tab_id, opts);
return TemplateHTML({
'str_secgroup_tab_id': str_secgroup_tab_id,
'customTagsHTML': CustomTagsTable.html(),
'securityGroupsTableHTML': this.securityGroupsTable.dataTableHTML
});
}
function _setup_secgroup_tab_content(secgroup_section, str_secgroup_tab_id) {
this.secgroup_section = secgroup_section;
CustomTagsTable.setup($('#'+str_secgroup_tab_id+'_custom_tags',secgroup_section));
this.securityGroupsTable.initialize();
Tips.setup(secgroup_section);
}
function _onShow(){
this.securityGroupsTable.refreshResourceTableSelect();
}
function _retrieve_secgroup_tab_data(){
var data = {};
var fields = [];
$.extend(data, CustomTagsTable.retrieve(this.secgroup_section));
var str_secgroup_tab_id = $('div[name="str_secgroup_tab_id"]', this.secgroup_section).attr("str_secgroup_tab_id");
var secgroups = this.securityGroupsTable.retrieveResourceTableSelect();
if (secgroups != undefined && secgroups.length != 0){
data["SECURITY_GROUPS"] = secgroups.join(",");
}
return data;
}
function _fill_secgroup_tab_data(secgroup_json){
if (secgroup_json["SECURITY_GROUPS"] != undefined &&
secgroup_json["SECURITY_GROUPS"].length != 0){
var secgroups = secgroup_json["SECURITY_GROUPS"].split(",");
this.securityGroupsTable.selectResourceTableSelect({ids: secgroups});
}
delete secgroup_json["SECURITY_GROUPS"];
CustomTagsTable.fill(this.secgroup_section, secgroup_json);
}
});

View File

@ -0,0 +1,5 @@
<div class="row" name="str_secgroups_tab_id" str_secgroups_tab_id="{{str_secgroups_tab_id}}">
<div class="row" id="{{str_secgroups_tab_id}}_security_groups">
{{{securityGroupsTableHTML}}}
</div>
</div>