Skip to content

Commit

Permalink
F #5612: Attach/detach secgroup in VM NICs (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Borges authored Feb 11, 2022
1 parent 869d2a8 commit 6ab6f3f
Show file tree
Hide file tree
Showing 26 changed files with 470 additions and 64 deletions.
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/kvm/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/kvm/cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ tabs:
VM.save_rdp: true
VM.save_virt_viewer: true
VM.updateconf: true
VM.attachsg: true
VM.detachsg: true
dashboard:
# Connected user's quotas
quotas: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/kvm/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/mixed/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/mixed/cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ tabs:
VM.save_rdp: true
VM.save_virt_viewer: true
VM.updateconf: true
VM.attachsg: true
VM.detachsg: true
dashboard:
# Connected user's quotas
quotas: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/mixed/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/vcenter/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/vcenter/cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ tabs:
VM.save_rdp: true
VM.save_virt_viewer: true
VM.updateconf: true
VM.attachsg: true
VM.detachsg: true
dashboard:
# Connected user's quotas
quotas: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/etc/sunstone-views/vcenter/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ tabs:
VM.rdp: true
VM.save_rdp: true
VM.save_virt_viewer: true
VM.attachsg: true
VM.detachsg: true
oneflow-services-tab:
panel_tabs:
service_info_tab: true
Expand Down
12 changes: 12 additions & 0 deletions src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def perform_action(template_json)
sched_action_update(action_hash['params'])
when 'sched_action_delete'
sched_action_delete(action_hash['params'])
when 'sg_attach'
sg_attach(action_hash['params'])
when 'sg_detach'
sg_detach(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " \
' available for this resource'
Expand Down Expand Up @@ -289,6 +293,14 @@ def sched_action_delete(params = {})
super(params['sched_id'])
end

def sg_attach(params = {})
super(params['nic_id'], params['sg_id'])
end

def sg_detach(params = {})
super(params['nic_id'], params['sg_id'])
end

end

end
8 changes: 8 additions & 0 deletions src/sunstone/public/app/opennebula/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,14 @@ define(function(require) {
"sched_action_delete" : function(params) {
var action_obj = { "sched_id" : params.data.extra_param };
OpenNebulaAction.simple_action(params, RESOURCE, "sched_action_delete", action_obj);
},
"attachsg" : function(params) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "sg_attach", action_obj);
},
"detachsg" : function(params) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "sg_detach", action_obj);
}
};

Expand Down
1 change: 1 addition & 0 deletions src/sunstone/public/app/tabs/provision-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ define(function(require) {
require("./vms-tab/dialogs/disk-saveas"),
require("./vms-tab/dialogs/disk-snapshot-rename"),
require("./vms-tab/dialogs/attach-nic"),
require("./vms-tab/dialogs/attach-sg"),
require("./vms-tab/dialogs/revert"),
require("./vms-tab/dialogs/snapshot"),
require("./users-tab/dialogs/login-token")
Expand Down
1 change: 1 addition & 0 deletions src/sunstone/public/app/tabs/vms-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define(function(require) {
require("./vms-tab/dialogs/disk-snapshot-rename"),
require("./vms-tab/dialogs/disk-resize"),
require("./vms-tab/dialogs/attach-nic"),
require("./vms-tab/dialogs/attach-sg"),
require("./vms-tab/dialogs/snapshot"),
require("./vms-tab/dialogs/revert"),
require("./vms-tab/dialogs/saveas-template")
Expand Down
2 changes: 2 additions & 0 deletions src/sunstone/public/app/tabs/vms-tab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ define(function(require) {
"VM.sched_action_add" : _commonActions.singleAction('sched_action_add'),
"VM.sched_action_delete" : _commonActions.singleAction('sched_action_delete'),
"VM.sched_action_update" : _commonActions.singleAction('sched_action_update'),
"VM.attachsg" : _commonActions.singleAction('attachsg'),
"VM.detachsg" : _commonActions.singleAction('detachsg'),

"VM.create_dialog" : {
type: "custom",
Expand Down
2 changes: 1 addition & 1 deletion src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define(function(require) {
function Dialog() {
this.dialogId = DIALOG_ID;

this.nicTab = new NicTab(DIALOG_ID + "NickTab");
this.nicTab = new NicTab(DIALOG_ID + "NicTab");

BaseDialog.call(this);
};
Expand Down
128 changes: 128 additions & 0 deletions src/sunstone/public/app/tabs/vms-tab/dialogs/attach-sg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2021, 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 Notifier = require("utils/notifier");
var SecgroupsTable = require('tabs/secgroups-tab/datatable');
var Sunstone = require("sunstone");
var TemplateHTML = require("hbs!./attach-sg/html");


/*
CONSTANTS
*/

var DIALOG_ID = require("./attach-sg/dialogId");
var TAB_ID = require("../tabId");

/*
CONSTRUCTOR
*/

function Dialog() {
var that = this;
this.dialogId = DIALOG_ID;

var secgroupSelectOptions = {
'select': true,
'selectOptions': {
"multiple_choice": false,
'unselect_callback': function(aData, options){
if (that.secGroups && that.secGroups.includes(aData[options.id_index])){
$("div[name='str_nic_tab_id'] table tbody tr td:contains('" + aData[options.name_index] + "')").click();
}
},
'filter_fn': function(sg) {
if (that.nic && that.nic.SECURITY_GROUPS) {
var security_groups = that.nic.SECURITY_GROUPS ? that.nic.SECURITY_GROUPS.split(",") : [];
return !security_groups.includes(sg.ID);
}
return true;
}
}
};

this.secgroupsTable = new SecgroupsTable(this.dialogId + 'SGTable', secgroupSelectOptions);

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.setElement = _setElement;

return Dialog;

/*
FUNCTION DEFINITIONS
*/

function _html() {
return TemplateHTML({
"dialogId": this.dialogId,
"secGroupsDataTableHTML": this.secgroupsTable.dataTableHTML
});
}

function _setup(context) {
var that = this;
that.secgroupsTable.initialize();
that.secgroupsTable.refreshResourceTableSelect();

$("#" + DIALOG_ID + "Form", context).submit(function() {
var sg_id = that.secgroupsTable.retrieveResourceTableSelect();

if(sg_id !== ''){
var obj = {
'nic_id': parseInt(that.nic.NIC_ID),
'sg_id': parseInt(sg_id)
};
Sunstone.runAction("VM.attachsg", that.element.ID, obj);
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
}else{
Notifier.notifyError("Select a security group");
}

return false;
});
return false;
}

function _onShow(context) {
return false;
}

function _setElement(element, nic_id) {
this.element = element;
var nic_array = [];

nic_array = Array.isArray(element.TEMPLATE.NIC) ? element.TEMPLATE.NIC : [element.TEMPLATE.NIC];
this.nic = nic_array.filter(function(nic) {
return nic.NIC_ID == nic_id;
})[0];

this.secgroupsTable.refreshResourceTableSelect();
}
});
19 changes: 19 additions & 0 deletions src/sunstone/public/app/tabs/vms-tab/dialogs/attach-sg/dialogId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2021, 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 'attachSGVMDialog';
});
37 changes: 37 additions & 0 deletions src/sunstone/public/app/tabs/vms-tab/dialogs/attach-sg/html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{! -------------------------------------------------------------------------- }}
{{! Copyright 2002-2021, 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" data-reveal>
<div class="row">
<div class="large-12 columns">
<h3 class="subheader" id="">{{tr "Attach new security group to NIC"}}</h3>
</div>
</div>
<div class="confirm-resources-header"></div>
<div class="reveal-body">
<form id="{{dialogId}}Form" action="">
{{{secGroupsDataTableHTML}}}
<div class="reveal-footer">
<div class="form_buttons">
<button class="button radius right success" id="attach_sg_button" type="submit" value="VM.attachsg">{{tr "Attach"}}</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>
Loading

0 comments on commit 6ab6f3f

Please sign in to comment.