Feature #3748: Security Groups tab, with info panel

This commit is contained in:
Carlos Martín committed 2015-05-19 15:39:26 +02:00
1 parent a3d4de282f
commit 15bb5481c6
8 files changed
+576 -2

No files matched your search

+3 -2
View File
@@ -8,9 +8,10 @@ define(function(require) {
require('tabs/zones-tab'),
require('tabs/datastores-tab'),
require('tabs/hosts-tab'),
require('tabs/vnets-tab'),
require('tabs/secgroups-tab'),
require('tabs/vresources-tab'),
require('tabs/images-tab'),
require('tabs/vnets-tab')
require('tabs/images-tab')
];
var _commonDialogs = [
@@ -0,0 +1,34 @@
define(function(require) {
var Locale = require('utils/locale');
var Buttons = require('./secgroups-tab/buttons');
var Actions = require('./secgroups-tab/actions');
var Table = require('./secgroups-tab/datatable');
var TAB_ID = require('./secgroups-tab/tabId');
var DATATABLE_ID = "dataTableSecurityGroups";
var _dialogs = [
];
var _panels = [
require('./secgroups-tab/panels/info')
];
var Tab = {
tabId: TAB_ID,
title: Locale.tr("Security Groups"),
tabClass: "subTab",
parentTab: "infra-tab",
listHeader: '<i class="fa fa-fw fa-shield"></i>&emsp;'+Locale.tr("Security Groups"),
infoHeader: '<i class="fa fa-fw fa-shield"></i>&emsp;'+Locale.tr("Security Group"),
subheader: '<span/> <small></small>&emsp;',
resource: 'SecurityGroup',
buttons: Buttons,
actions: Actions,
dataTable: new Table(DATATABLE_ID, {actions: true, info: true}),
panels: _panels,
dialogs: _dialogs
};
return Tab;
});
@@ -0,0 +1,210 @@
define(function(require) {
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
var DataTable = require('./datatable');
var OpenNebulaSecurityGroup = require('opennebula/securitygroup');
var TAB_ID = require('./tabId');
// TODO
//var CREATE_DIALOG_ID = require('./dialogs/create/dialogId');
var _actions = {
/*
TODO
"SecurityGroup.create" : {
type: "create",
call: OpenNebulaSecurityGroup.create,
callback: function(request, response){
$("a[href=back]", $("#secgroups-tab")).trigger("click");
popFormDialog("create_security_group_form", $("#secgroups-tab"));
addSecurityGroupElement(request, response);
notifyCustom(tr("Security Group created"), " ID: " + response.SECURITY_GROUP.ID, false);
},
error: function(request, response){
popFormDialog("create_security_group_form", $("#secgroups-tab"));
onError(request, response);
}
},
"SecurityGroup.create_dialog" : {
type: "custom",
call: function(){
Sunstone.popUpFormPanel("create_security_group_form", "secgroups-tab", "create", true);
}
},
*/
"SecurityGroup.list" : {
type: "list",
call: OpenNebulaSecurityGroup.list,
callback: function(request, response) {
Sunstone.getDataTable(TAB_ID).updateView(request, response);
},
error: Notifier.onError
},
"SecurityGroup.show" : {
type: "single",
call: OpenNebulaSecurityGroup.show,
callback: function(request, response) {
Sunstone.getDataTable(TAB_ID).updateElement(request, response);
if (Sunstone.rightInfoVisible($('#'+TAB_ID))) {
Sunstone.insertPanels(TAB_ID, response);
}
},
error: Notifier.onError
},
"SecurityGroup.refresh" : {
type: "custom",
call: function() {
var tab = $('#' + TAB_ID);
if (Sunstone.rightInfoVisible(tab)) {
Sunstone.runAction("SecurityGroup.show", Sunstone.rightInfoResourceId(tab));
} else {
Sunstone.getDataTable(TAB_ID).waitingNodes();
Sunstone.runAction("SecurityGroup.list", {force: true});
}
},
error: Notifier.onError
},
"SecurityGroup.delete" : {
type: "multiple",
call : OpenNebulaSecurityGroup.del,
callback : function(request, response) {
Sunstone.getDataTable(TAB_ID).deleteElement(request, response);
},
elements: function() {
return Sunstone.getDataTable(TAB_ID).elements();
},
error: Notifier.onError,
notify: true
},
/*
TODO
"SecurityGroup.update_dialog" : {
type: "custom",
call: function(){
var selected_nodes = securityGroupElements();
if ( selected_nodes.length != 1 ) {
notifyMessage("Please select one (and just one) Security Group to update.");
return false;
}
var resource_id = ""+selected_nodes[0];
Sunstone.runAction("SecurityGroup.show_to_update", resource_id);
}
},
"SecurityGroup.show_to_update" : {
type: "single",
call: OpenNebulaSecurityGroup.show,
callback: function(request, response) {
// TODO: global var, better use jquery .data
sg_to_update_id = response.SECURITY_GROUP.ID;
Sunstone.popUpFormPanel("create_security_group_form", "secgroups-tab", "create", true);
Sunstone.popUpFormPanel("create_security_group_form", "secgroups-tab", "update", true, function(context){
fillSecurityGroupUpdateFormPanel(response.SECURITY_GROUP, context);
});
},
error: Notifier.onError
},
"SecurityGroup.update" : {
type: "single",
call: OpenNebulaSecurityGroup.update,
callback: function(request, response){
$("a[href=back]", $("#secgroups-tab")).trigger("click");
popFormDialog("create_security_group_form", $("#secgroups-tab"));
notifyMessage(tr("Security Group updated correctly"));
},
error: function(request, response){
popFormDialog("create_security_group_form", $("#secgroups-tab"));
onError(request, response);
}
},
*/
"SecurityGroup.update_template" : {
type: "single",
call: OpenNebulaSecurityGroup.update,
callback: function(request,response){
Sunstone.runAction('SecurityGroup.show',request.request.data[0][0]);
},
error: Notifier.onError
},
"SecurityGroup.chown" : {
type: "multiple",
call: OpenNebulaSecurityGroup.chown,
callback: function (req) {
Sunstone.runAction("SecurityGroup.show", req.request.data[0]);
},
elements: function() {
return Sunstone.getDataTable(TAB_ID).elements();
},
error: Notifier.onError,
notify: true
},
"SecurityGroup.chgrp" : {
type: "multiple",
call: OpenNebulaSecurityGroup.chgrp,
callback: function (req) {
Sunstone.runAction("SecurityGroup.show", req.request.data[0]);
},
elements: function() {
return Sunstone.getDataTable(TAB_ID).elements();
},
error: Notifier.onError,
notify: true
},
"SecurityGroup.chmod" : {
type: "single",
call: OpenNebulaSecurityGroup.chmod,
callback: function (req) {
Sunstone.runAction("SecurityGroup.show", req.request.data[0]);
},
elements: function() {
return Sunstone.getDataTable(TAB_ID).elements();
},
error: Notifier.onError,
notify: true
},
/*
TODO
"SecurityGroup.clone_dialog" : {
type: "custom",
call: popUpSecurityGroupCloneDialog
},
*/
"SecurityGroup.clone" : {
type: "single",
call: OpenNebulaSecurityGroup.clone,
error: Notifier.onError,
notify: true
},
"SecurityGroup.rename" : {
type: "single",
call: OpenNebulaSecurityGroup.rename,
callback: function(request) {
Sunstone.runAction('SecurityGroup.show',request.request.data[0][0]);
},
error: Notifier.onError,
notify: true
}
};
return _actions;
})
@@ -0,0 +1,46 @@
define(function(require) {
var Locale = require('utils/locale');
var Buttons = {
"SecurityGroup.refresh" : {
type: "action",
layout: "refresh",
alwaysActive: true
},
"SecurityGroup.create_dialog" : {
type: "create_dialog",
layout: "create"
},
"SecurityGroup.update_dialog" : {
type: "action",
layout: "main",
text: Locale.tr("Update")
},
"SecurityGroup.chown" : {
type: "confirm_with_select",
text: Locale.tr("Change owner"),
layout: "user_select",
select: "User",
tip: Locale.tr("Select the new owner")+":"
},
"SecurityGroup.chgrp" : {
type: "confirm_with_select",
text: Locale.tr("Change group"),
layout: "user_select",
select: "Group",
tip: Locale.tr("Select the new group")+":"
},
"SecurityGroup.clone_dialog" : {
type: "action",
layout: "main",
text: Locale.tr("Clone")
},
"SecurityGroup.delete" : {
type: "confirm",
layout: "del",
text: Locale.tr("Delete")
}
};
return Buttons;
})
@@ -0,0 +1,98 @@
define(function(require) {
/*
DEPENDENCIES
*/
var TemplateInfo = require('hbs!./info/html');
var Locale = require('utils/locale');
var PermissionsTable = require('utils/panel/permissions-table');
var RenameTr = require('utils/panel/rename-tr');
var OpenNebulaSecurityGroup = require('opennebula/securitygroup');
var Utils = require('../utils/common');
/*
TEMPLATES
*/
var TemplateTable = require('utils/panel/template-table');
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./info/panelId');
var RESOURCE = "SecurityGroup";
var XML_ROOT = "SECURITY_GROUP";
/*
CONSTRUCTOR
*/
function Panel(info) {
this.title = Locale.tr("Info");
this.icon = "fa-info-circle";
this.element = info[XML_ROOT];
return this;
}
Panel.PANEL_ID = PANEL_ID;
Panel.prototype.html = _html;
Panel.prototype.setup = _setup;
return Panel;
/*
FUNCTION DEFINITIONS
*/
function _html() {
var renameTrHTML = RenameTr.html(RESOURCE, this.element.NAME);
var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element);
var rules = Utils.getRules(this.element);
var ruleTextList = [];
$.each(rules, function(){
ruleTextList.push(Utils.sgRuleToSt(this));
});
// TODO
//$(".resource-info-header", $("#secgroups-tab")).html(this.element.NAME);
// TODO: simplify interface?
var strippedTemplate = $.extend({}, this.element.TEMPLATE);
delete strippedTemplate["RULE"];
var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE,
Locale.tr("Attributes"));
//====
return TemplateInfo({
'element': this.element,
'renameTrHTML': renameTrHTML,
'permissionsTableHTML': permissionsTableHTML,
'ruleList': ruleTextList,
'templateTableHTML': templateTableHTML
});
}
function _setup(context) {
RenameTr.setup(RESOURCE, this.element.ID, context);
PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context);
// TODO: simplify interface?
var strippedTemplate = $.extend({}, this.element.TEMPLATE);
delete strippedTemplate["RULE"];
var hiddenValues = {RULE: this.element.TEMPLATE.RULE};
TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context, hiddenValues);
//===
return false;
}
});
@@ -0,0 +1,59 @@
<div class="row">
<div class="large-6 columns">
<table id="info_security_group_table" class="dataTable extended_table">
<thead>
<tr>
<th colspan="3">{{tr "Information"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="key_td">{{tr "ID"}}</td>
<td class="value_td" colspan="2">{{element.ID}}</td>
</tr>
{{{renameTrHTML}}}
</tbody>
</table>
</div>
<div class="large-6 columns">
{{{permissionsTableHTML}}}
</div>
</div>
<div class="row">
<div class="large-9 columns">
<table class="dataTable extended_table">
<thead>
<tr>
<th>{{tr "Rules"}}</th>
</tr>
</thead>
</table>
<table class="policies_table dataTable">
<thead>
<tr>
<th>{{tr "Protocol"}}</th>
<th>{{tr "Type"}}</th>
<th>{{tr "Port Range"}}</th>
<th>{{tr "Network"}}</th>
<th>{{tr "ICMP Type"}}</th>
</tr>
</thead>
<tbody>
{{#each ruleList}}
<tr>
<td>{{PROTOCOL}}</td>
<td>{{RULE_TYPE}}</td>
<td>{{RANGE}}</td>
<td>{{NETWORK}}</td>
<td>{{ICMP_TYPE}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="large-9 columns">
{{{templateTableHTML}}}
</div>
</div>
@@ -0,0 +1,3 @@
define(function(require){
return 'security_group_info_tab';
})
@@ -0,0 +1,123 @@
define(function(require) {
/*
Common functions for Security Groups
*/
/*
DEPENDENCIES
*/
var Locale = require('utils/locale');
/*
@param {Object} rule Object representing the rule as returned by OpenNebula
Returns an object with the human readable attributes of the rule. List of attributes:
PROTOCOL
RULE_TYPE
ICMP_TYPE
RANGE
NETWORK
*/
function _sgRuleToSt(rule){
var text = {};
if(rule.PROTOCOL != undefined){
switch(rule.PROTOCOL.toUpperCase()){
case "TCP":
text["PROTOCOL"] = Locale.tr("TCP");
break;
case "UDP":
text["PROTOCOL"] = Locale.tr("UDP");
break;
case "ICMP":
text["PROTOCOL"] = Locale.tr("ICMP");
break;
case "IPSEC":
text["PROTOCOL"] = Locale.tr("IPsec");
break;
case "ALL":
text["PROTOCOL"] = Locale.tr("All");
break;
default:
text["PROTOCOL"] = "";
}
} else {
text["PROTOCOL"] = "";
}
if(rule.RULE_TYPE != undefined){
switch(rule.RULE_TYPE.toUpperCase()){
case "OUTBOUND":
text["RULE_TYPE"] = Locale.tr("Outbound");
break;
case "INBOUND":
text["RULE_TYPE"] = Locale.tr("Inbound");
break;
default:
text["RULE_TYPE"] = "";
}
} else {
text["RULE_TYPE"] = "";
}
if(rule.ICMP_TYPE != undefined){
text["ICMP_TYPE"] = icmp_to_st(rule.ICMP_TYPE);
} else {
text["ICMP_TYPE"] = "";
}
if(rule.RANGE != undefined && rule.RANGE != ""){
text["RANGE"] = rule.RANGE;
} else {
text["RANGE"] = Locale.tr("All");
}
var network = "";
if(rule.NETWORK_ID != undefined && rule.NETWORK_ID != ""){
network += (Locale.tr("Virtual Network") + " " + rule.NETWORK_ID);
}
if(rule.SIZE != undefined && rule.SIZE != ""){
if(network != ""){
network += ":<br>";
}
if(rule.IP != undefined && rule.IP != ""){
network += Locale.tr("Start") + ": " + rule.IP + ", ";
} else if(rule.MAC != undefined && rule.MAC != ""){
network += Locale.tr("Start") + ": " + rule.MAC + ", ";
}
network += Locale.tr("Size") + ": " + rule.SIZE;
}
if(network == ""){
network = Locale.tr("Any");
}
text["NETWORK"] = network;
return text;
}
/*
@param {Object} info Object representing the Security Group as returned by OpenNebula
*/
function _getRules(info){
var rules = info.TEMPLATE.RULE;
if (!rules){ //empty
rules = [];
} else if (rules.constructor != Array) { //>1 rule
rules = [rules];
}
return rules;
}
return {
'sgRuleToSt': _sgRuleToSt,
'getRules': _getRules
};
});