diff --git a/src/sunstone/etc/sunstone-views/kvm/admin.yaml b/src/sunstone/etc/sunstone-views/kvm/admin.yaml index 1d5aecdb52..f98f477daa 100644 --- a/src/sunstone/etc/sunstone-views/kvm/admin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/admin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml index f19217a8dc..dae9ab2c7d 100644 --- a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/kvm/user.yaml b/src/sunstone/etc/sunstone-views/kvm/user.yaml index 52f4ddc3f3..dea34db593 100644 --- a/src/sunstone/etc/sunstone-views/kvm/user.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/user.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/mixed/admin.yaml b/src/sunstone/etc/sunstone-views/mixed/admin.yaml index 7735b2b4d9..d610da0d7a 100644 --- a/src/sunstone/etc/sunstone-views/mixed/admin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/admin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml index b0e31a961d..2856a0b10c 100644 --- a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/mixed/user.yaml b/src/sunstone/etc/sunstone-views/mixed/user.yaml index e4394c8463..078f92731d 100644 --- a/src/sunstone/etc/sunstone-views/mixed/user.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/user.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml index f6472f9f8c..cafd69e7f5 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml index 091e4e97e2..e8e0cc9ee4 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml @@ -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 diff --git a/src/sunstone/etc/sunstone-views/vcenter/user.yaml b/src/sunstone/etc/sunstone-views/vcenter/user.yaml index e4394c8463..078f92731d 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/user.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/user.yaml @@ -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 diff --git a/src/sunstone/public/app/tabs/vnets-tab.js b/src/sunstone/public/app/tabs/vnets-tab.js index f4fc88ebf6..50903543a7 100644 --- a/src/sunstone/public/app/tabs/vnets-tab.js +++ b/src/sunstone/public/app/tabs/vnets-tab.js @@ -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 = [ diff --git a/src/sunstone/public/app/tabs/vnets-tab/actions.js b/src/sunstone/public/app/tabs/vnets-tab/actions.js index 6461b0c8b2..5bf91bdf61 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/actions.js +++ b/src/sunstone/public/app/tabs/vnets-tab/actions.js @@ -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 } }; diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js new file mode 100644 index 0000000000..a6239ded8d --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js @@ -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; + } +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js new file mode 100644 index 0000000000..7ca9e6c98a --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js @@ -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'; +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs new file mode 100644 index 0000000000..6b8964aac8 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs @@ -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. }} +{{! -------------------------------------------------------------------------- }} + +