mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09:00
Feature #3175: Security group definition for vnet, ar & nic
This commit is contained in:
1 parent
49b94d12ea
commit
da3b9aecc7
4 files changed
+291
-35
No files matched your search
@@ -465,7 +465,7 @@ function securityGroupElements(){
|
||||
return getSelectedNodes(dataTable_security_groups);
|
||||
}
|
||||
|
||||
function security_groupElementArray(element_json){
|
||||
function securityGroupElementArray(element_json){
|
||||
|
||||
var element = element_json.SECURITY_GROUP;
|
||||
|
||||
@@ -481,7 +481,7 @@ function security_groupElementArray(element_json){
|
||||
//callback for an action affecting a security_group element
|
||||
function updateSecurityGroupElement(request, element_json){
|
||||
var id = element_json.SECURITY_GROUP.ID;
|
||||
var element = security_groupElementArray(element_json);
|
||||
var element = securityGroupElementArray(element_json);
|
||||
updateSingleElement(element,dataTable_security_groups,'#security_group_'+id);
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ function deleteSecurityGroupElement(req){
|
||||
//call back for actions creating a security_group element
|
||||
function addSecurityGroupElement(request,element_json){
|
||||
var id = element_json.SECURITY_GROUP.ID;
|
||||
var element = security_groupElementArray(element_json);
|
||||
var element = securityGroupElementArray(element_json);
|
||||
addElement(element,dataTable_security_groups);
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ function updateSecurityGroupsView (request,list){
|
||||
|
||||
$.each(list,function(){
|
||||
//Grab table data from the list
|
||||
list_array.push(security_groupElementArray(this));
|
||||
list_array.push(securityGroupElementArray(this));
|
||||
});
|
||||
|
||||
updateView(list_array,dataTable_security_groups);
|
||||
|
||||
@@ -1786,6 +1786,12 @@ function generate_nic_tab_content(str_nic_tab_id, str_datatable_id){
|
||||
'</label>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</fieldset>'+
|
||||
'<fieldset>'+
|
||||
'<legend>'+tr("Security Groups")+'</legend>'+
|
||||
'<div name="str_nic_tab_id" str_nic_tab_id="'+str_nic_tab_id+'">'+
|
||||
generateSecurityGroupTableSelect("vm_create_nic_"+str_nic_tab_id)+
|
||||
'</div>'+
|
||||
'</fieldset>'});
|
||||
|
||||
$("#refresh_template_nic_table_button_class"+str_nic_tab_id).die();
|
||||
@@ -1815,6 +1821,13 @@ function retrieve_nic_tab_data(context){
|
||||
data["ICMP"] = "drop"
|
||||
}
|
||||
|
||||
var str_nic_tab_id = $('div[name="str_nic_tab_id"]', context).attr("str_nic_tab_id");
|
||||
|
||||
var secgroups = retrieveSecurityGroupTableSelect(context,
|
||||
"vm_create_nic_"+str_nic_tab_id);
|
||||
|
||||
data["SECURITY_GROUPS"] = secgroups.join(",");
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -1907,6 +1920,11 @@ function setup_nic_tab_content(nic_section, str_nic_tab_id, str_datatable_id) {
|
||||
return true;
|
||||
});
|
||||
|
||||
setupSecurityGroupTableSelect(nic_section, "vm_create_nic_"+str_nic_tab_id,
|
||||
{"multiple_choice": true});
|
||||
|
||||
refreshSecurityGroupTableSelect(nic_section, "vm_create_nic_"+str_nic_tab_id);
|
||||
|
||||
setupTips(nic_section);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ var create_vn_tmpl =
|
||||
<dd class="active"><a href="#vnetCreateGeneralTab"><i class="fa fa-globe"></i><br>'+tr("General")+'</a></dd>\
|
||||
<dd><a href="#vnetCreateBridgeTab"><i class="fa fa-cog"></i><br>'+tr("Configuration")+'</a></dd>\
|
||||
<dd><a href="#vnetCreateARTab"><i class="fa fa-align-justify"></i><br>'+tr("Addresses")+'</a></dd>\
|
||||
<dd><a href="#vnetCreateSecurityTab"><i class="fa fa-shield"></i><br>'+tr("Security")+'</a></dd>\
|
||||
<dd><a href="#vnetCreateContextTab"><i class="fa fa-folder"></i><br>'+tr("Context")+'</a></dd>\
|
||||
</dl>\
|
||||
<div id="vnet_create_tabs_content" class="tabs-content">\
|
||||
@@ -138,6 +139,9 @@ var create_vn_tmpl =
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="content" id="vnetCreateSecurityTab">\
|
||||
'+generateSecurityGroupTableSelect("vnet_create")+'\
|
||||
</div>\
|
||||
<div class="content" id="vnetCreateContextTab">\
|
||||
<div class="row">\
|
||||
<div class="large-6 columns">\
|
||||
@@ -1253,6 +1257,8 @@ function setupCreateVNetDialog() {
|
||||
//Initialize shown options
|
||||
$('#network_mode',dialog).trigger("change");
|
||||
|
||||
setupSecurityGroupTableSelect(dialog, "vnet_create", {"multiple_choice": true});
|
||||
|
||||
setupCustomTags($("#vnetCreateContextTab", dialog));
|
||||
|
||||
//Handle submission of the easy mode
|
||||
@@ -1266,6 +1272,9 @@ function setupCreateVNetDialog() {
|
||||
retrieveWizardFields($("#vnetCreateBridgeTab", dialog), network_json);
|
||||
retrieveWizardFields($("#vnetCreateContextTab", dialog), network_json);
|
||||
|
||||
var secgroups = retrieveSecurityGroupTableSelect(dialog, "vnet_create");
|
||||
network_json["SECURITY_GROUPS"] = secgroups.join(",");
|
||||
|
||||
retrieveCustomTags($("#vnetCreateContextTab", dialog), network_json);
|
||||
|
||||
$('.ar_tab',dialog).each(function(){
|
||||
@@ -1322,6 +1331,8 @@ function setupCreateVNetDialog() {
|
||||
function popUpCreateVnetDialog() {
|
||||
$create_vn_dialog.foundation().foundation('reveal', 'open');
|
||||
|
||||
refreshSecurityGroupTableSelect($create_vn_dialog, "vnet_create");
|
||||
|
||||
$("input#name",$create_vn_dialog).focus();
|
||||
}
|
||||
|
||||
@@ -1347,7 +1358,7 @@ function add_ar_tab(ar_id, dialog) {
|
||||
|
||||
function generate_ar_tab_content(str_ar_tab_id){
|
||||
var html =
|
||||
'<div class="row">\
|
||||
'<div class="row" name="str_ar_tab_id" str_ar_tab_id="'+str_ar_tab_id+'">\
|
||||
<div class="large-12 columns">\
|
||||
<input wizard_field="TYPE" type="radio" name="'+str_ar_tab_id+'_ar_type" id="'+str_ar_tab_id+'_ar_type_ip4" value="IP4"/><label for="'+str_ar_tab_id+'_ar_type_ip4">'+tr("IPv4")+'</label>\
|
||||
<input wizard_field="TYPE" type="radio" name="'+str_ar_tab_id+'_ar_type" id="'+str_ar_tab_id+'_ar_type_ip4_6" value="IP4_6"/><label for="'+str_ar_tab_id+'_ar_type_ip4_6">'+tr("IPv4/6")+'</label>\
|
||||
@@ -1390,20 +1401,35 @@ function generate_ar_tab_content(str_ar_tab_id){
|
||||
</label>\
|
||||
<input wizard_field="ULA_PREFIX" type="text" name="ULA_PREFIX" id="'+str_ar_tab_id+'_ula_prefix"/>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
<hr>\
|
||||
<div class="large-12 columns">\
|
||||
<span>' + tr("Custom attributes") + '</span>\
|
||||
<br>\
|
||||
<br>\
|
||||
</div>'+
|
||||
generateAdvancedSection({
|
||||
title: tr("Advanced Options"),
|
||||
html_id: 'advanced_vnet_create_ar',
|
||||
content:'<div class="row">\
|
||||
<div class="large-12 columns">\
|
||||
<span>' + tr("Custom attributes") + '</span>\
|
||||
<br>\
|
||||
<br>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row" id="'+str_ar_tab_id+'_custom_tags">\
|
||||
<div class="12 columns">'+
|
||||
customTagsHtml()+
|
||||
'</div>\
|
||||
</div>';
|
||||
<div class="row" id="'+str_ar_tab_id+'_custom_tags">\
|
||||
<div class="12 columns">'+
|
||||
customTagsHtml()+
|
||||
'</div>\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
<br>\
|
||||
<br>\
|
||||
<hr>\
|
||||
<div class="large-12 columns">\
|
||||
<span>' + tr("Security Groups") + '</span>\
|
||||
<br>\
|
||||
<br>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row" id="'+str_ar_tab_id+'_security_groups">\
|
||||
'+generateSecurityGroupTableSelect("vnet_create_ar_"+str_ar_tab_id)+'\
|
||||
</div>'});
|
||||
|
||||
return html;
|
||||
}
|
||||
@@ -1440,6 +1466,11 @@ function setup_ar_tab_content(ar_section, str_ar_tab_id) {
|
||||
|
||||
setupCustomTags($('#'+str_ar_tab_id+'_custom_tags',ar_section));
|
||||
|
||||
setupSecurityGroupTableSelect(ar_section, "vnet_create_ar_"+str_ar_tab_id,
|
||||
{"multiple_choice": true});
|
||||
|
||||
refreshSecurityGroupTableSelect(ar_section, "vnet_create_ar_"+str_ar_tab_id);
|
||||
|
||||
setupTips(ar_section);
|
||||
}
|
||||
|
||||
@@ -1480,6 +1511,12 @@ function retrieve_ar_tab_data(ar_section){
|
||||
|
||||
retrieveCustomTags(ar_section, data);
|
||||
|
||||
var str_ar_tab_id = $('div[name="str_ar_tab_id"]', ar_section).attr("str_ar_tab_id");
|
||||
|
||||
var secgroups = retrieveSecurityGroupTableSelect(ar_section,
|
||||
"vnet_create_ar_"+str_ar_tab_id);
|
||||
data["SECURITY_GROUPS"] = secgroups.join(",");
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -5916,6 +5916,111 @@ function setupDatastoreTableSelect(section, context_id, opts){
|
||||
return setupResourceTableSelect(section, context_id, options);
|
||||
}
|
||||
|
||||
function generateSecurityGroupTableSelect(context_id){
|
||||
|
||||
var columns = [
|
||||
"",
|
||||
tr("ID"),
|
||||
tr("Owner"),
|
||||
tr("Group"),
|
||||
tr("Name")
|
||||
];
|
||||
|
||||
var options = {
|
||||
"id_index": 1,
|
||||
"name_index": 4,
|
||||
"select_resource": tr("Please select a security group from the list"),
|
||||
"you_selected": tr("You selected the following security group:"),
|
||||
"select_resource_multiple": tr("Please select one or more security groups from the list"),
|
||||
"you_selected_multiple": tr("You selected the following security groups:")
|
||||
};
|
||||
|
||||
return generateResourceTableSelect(context_id, columns, options);
|
||||
}
|
||||
|
||||
// opts.bVisible: dataTable bVisible option. If not set, the .yaml visibility will be used
|
||||
// opts.filter_fn: boolean function to filter which vnets to show
|
||||
// opts.multiple_choice: boolean true to enable multiple element selection
|
||||
function setupSecurityGroupTableSelect(section, context_id, opts){
|
||||
|
||||
if(opts == undefined){
|
||||
opts = {};
|
||||
}
|
||||
|
||||
if(opts.bVisible == undefined){
|
||||
// Use the settings in the conf, but removing the checkbox
|
||||
var config = Config.tabTableColumns('secgroups-tab').slice(0);
|
||||
var i = config.indexOf(0);
|
||||
|
||||
if(i != -1){
|
||||
config.splice(i,1);
|
||||
}
|
||||
|
||||
opts.bVisible = config;
|
||||
}
|
||||
|
||||
if(opts.multiple_choice == undefined){
|
||||
opts.multiple_choice = false;
|
||||
}
|
||||
|
||||
var options = {
|
||||
"dataTable_options": {
|
||||
"bAutoWidth":false,
|
||||
"iDisplayLength": 4,
|
||||
"sDom" : '<"H">t<"F"p>',
|
||||
"bRetrieve": true,
|
||||
"bSortClasses" : false,
|
||||
"bDeferRender": true,
|
||||
"aoColumnDefs": [
|
||||
{ "sWidth": "35px", "aTargets": [0,1] },
|
||||
{ "bVisible": true, "aTargets": opts.bVisible},
|
||||
{ "bVisible": false, "aTargets": ['_all']}
|
||||
]
|
||||
},
|
||||
|
||||
"multiple_choice": opts.multiple_choice,
|
||||
|
||||
"id_index": 1,
|
||||
"name_index": 4,
|
||||
|
||||
"update_fn": function(datatable){
|
||||
OpenNebula.SecurityGroup.list({
|
||||
timeout: true,
|
||||
success: function (request, secgroups_list){
|
||||
var secgroup_list_array = [];
|
||||
|
||||
$.each(secgroups_list,function(){
|
||||
var add = true;
|
||||
|
||||
if(opts.filter_fn){
|
||||
add = opts.filter_fn(this.SECURITY_GROUP);
|
||||
}
|
||||
|
||||
if(add){
|
||||
secgroup_list_array.push(securityGroupElementArray(this));
|
||||
}
|
||||
});
|
||||
|
||||
updateView(secgroup_list_array, datatable);
|
||||
},
|
||||
error: onError
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return setupResourceTableSelect(section, context_id, options);
|
||||
}
|
||||
|
||||
// Clicks the refresh button
|
||||
function refreshSecurityGroupTableSelect(section, context_id){
|
||||
return refreshResourceTableSelect(section, context_id);
|
||||
}
|
||||
|
||||
// Returns an ID, or an array of IDs for opts.multiple_choice
|
||||
function retrieveSecurityGroupTableSelect(section, context_id){
|
||||
return retrieveResourceTableSelect(section, context_id);
|
||||
}
|
||||
|
||||
function generateResourceTableSelect(context_id, columns, options){
|
||||
if (!options.select_resource){
|
||||
options.select_resource = tr("Please select a resource from the list");
|
||||
@@ -5956,9 +6061,11 @@ function generateResourceTableSelect(context_id, columns, options){
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="row">\
|
||||
<div class="large-12 columns">\
|
||||
<div class="large-12 columns" id="selected_ids_row_'+context_id+'">\
|
||||
<span id="select_resource_'+context_id+'" class="radius secondary label">'+options.select_resource+'</span>\
|
||||
<span id="selected_resource_'+context_id+'" class="radius secondary label" style="display: none;">'+options.you_selected+'</span>\
|
||||
<span id="select_resource_multiple_'+context_id+'" class="radius secondary label" style="display: none;">'+options.select_resource_multiple+'</span>\
|
||||
<span id="selected_resource_multiple_'+context_id+'" class="radius secondary label" style="display: none;">'+options.you_selected_multiple+'</span>\
|
||||
<input id="selected_resource_id_'+context_id+'" type="text"/>\
|
||||
<span id="selected_resource_name_'+context_id+'" class="radius label" type="text"></span>\
|
||||
</div>\
|
||||
@@ -5991,31 +6098,101 @@ function setupResourceTableSelect(section, context_id, options) {
|
||||
|
||||
dataTable_select.fnSort( [ [options.id_index, config['user_config']['table_order']] ] );
|
||||
|
||||
if(options.multiple_choice){
|
||||
$('#selected_resource_'+context_id, section).hide();
|
||||
$('#select_resource_'+context_id, section).hide();
|
||||
|
||||
$('#selected_resource_multiple_'+context_id, section).hide();
|
||||
$('#select_resource_multiple_'+context_id, section).show();
|
||||
}
|
||||
|
||||
$('#selected_resource_id_'+context_id, section).hide();
|
||||
$('#selected_resource_name_'+context_id, section).hide();
|
||||
|
||||
$('#datatable_'+context_id+' tbody', section).delegate("tr", "click", function(e){
|
||||
dataTable_select.unbind("draw");
|
||||
var aData = dataTable_select.fnGetData(this);
|
||||
$('#selected_ids_row_'+context_id, section).data("options", options);
|
||||
|
||||
$("td.markrow", dataTable_select).removeClass('markrow');
|
||||
$('tbody input.check_item', dataTable_select).removeAttr('checked');
|
||||
if(options.multiple_choice){
|
||||
$('#selected_ids_row_'+context_id, section).data("ids", {});
|
||||
|
||||
$('#selected_resource_'+context_id, section).show();
|
||||
$('#select_resource_'+context_id, section).hide();
|
||||
$('.alert-box', section).hide();
|
||||
function row_click(row){
|
||||
dataTable_select.unbind("draw");
|
||||
var aData = dataTable_select.fnGetData(row);
|
||||
|
||||
$("td", this).addClass('markrow');
|
||||
$('input.check_item', this).attr('checked','checked');
|
||||
var row_id = aData[options.id_index];
|
||||
var row_name = aData[options.name_index];
|
||||
|
||||
$('#selected_resource_id_'+context_id, section).val(aData[options.id_index]).change();
|
||||
$('#selected_resource_id_'+context_id, section).hide();
|
||||
var ids = $('#selected_ids_row_'+context_id, section).data("ids");
|
||||
|
||||
$('#selected_resource_name_'+context_id, section).text(aData[options.name_index]).change();
|
||||
$('#selected_resource_name_'+context_id, section).show();
|
||||
if( ids[row_id] ){
|
||||
delete ids[row_id];
|
||||
|
||||
return true;
|
||||
});
|
||||
$("td", row).removeClass('markrow');
|
||||
$('input.check_item', row).removeAttr('checked');
|
||||
|
||||
$('#selected_ids_row_'+context_id+' span[row_id="'+row_id+'"]', section).remove();
|
||||
} else {
|
||||
ids[row_id] = true;
|
||||
|
||||
$("td", row).addClass('markrow');
|
||||
$('input.check_item', row).attr('checked','checked');
|
||||
|
||||
$('#selected_ids_row_'+context_id, section).append('<span row_id="'+row_id+'" class="radius label">'+row_name+' <span class="fa fa-times blue"></span></span> ');
|
||||
}
|
||||
|
||||
if ($.isEmptyObject(ids)){
|
||||
$('#selected_resource_multiple_'+context_id, section).hide();
|
||||
$('#select_resource_multiple_'+context_id, section).show();
|
||||
} else {
|
||||
$('#selected_resource_multiple_'+context_id, section).show();
|
||||
$('#select_resource_multiple_'+context_id, section).hide();
|
||||
}
|
||||
|
||||
$('.alert-box', section).hide();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$('#datatable_'+context_id+' tbody', section).delegate("tr", "click", function(e){
|
||||
row_click(this);
|
||||
});
|
||||
|
||||
$(section).on("click", '#selected_ids_row_'+context_id+' span.fa.fa-times', function() {
|
||||
var row_id = $(this).parent("span").attr('row_id');
|
||||
|
||||
// TODO: improve preformance, linear search
|
||||
$.each(dataTable_select.fnGetData(), function(index, row){
|
||||
if(row[options.id_index] == row_id){
|
||||
row_click(dataTable_select.fnGetNodes(index));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
$('#datatable_'+context_id+' tbody', section).delegate("tr", "click", function(e){
|
||||
dataTable_select.unbind("draw");
|
||||
var aData = dataTable_select.fnGetData(this);
|
||||
|
||||
$("td.markrow", dataTable_select).removeClass('markrow');
|
||||
$('tbody input.check_item', dataTable_select).removeAttr('checked');
|
||||
|
||||
$('#selected_resource_'+context_id, section).show();
|
||||
$('#select_resource_'+context_id, section).hide();
|
||||
$('.alert-box', section).hide();
|
||||
|
||||
$("td", this).addClass('markrow');
|
||||
$('input.check_item', this).attr('checked','checked');
|
||||
|
||||
$('#selected_resource_id_'+context_id, section).val(aData[options.id_index]).change();
|
||||
$('#selected_resource_id_'+context_id, section).hide();
|
||||
|
||||
$('#selected_resource_name_'+context_id, section).text(aData[options.name_index]).change();
|
||||
$('#selected_resource_name_'+context_id, section).show();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
setupTips(section);
|
||||
}
|
||||
@@ -6036,6 +6213,30 @@ function resetResourceTableSelect(section, context_id, options) {
|
||||
$('#select_resource_'+context_id, section).show();
|
||||
}
|
||||
|
||||
// Returns an ID, or an array of IDs for opts.multiple_choice
|
||||
function retrieveResourceTableSelect(section, context_id){
|
||||
var options = $('#selected_ids_row_'+context_id, section).data("options");
|
||||
|
||||
if(options.multiple_choice){
|
||||
var ids = $('#selected_ids_row_'+context_id, section).data("ids");
|
||||
|
||||
var arr = [];
|
||||
|
||||
$.each(ids, function(key, val){
|
||||
arr.push(key);
|
||||
});
|
||||
|
||||
return arr;
|
||||
} else {
|
||||
return $('#selected_resource_id_'+context_id, section).val();
|
||||
}
|
||||
}
|
||||
|
||||
// Clicks the refresh button
|
||||
function refreshResourceTableSelect(section, context_id){
|
||||
$('#refresh_button_'+context_id, section).click();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// VM & Service user inputs
|
||||
//==============================================================================
|
||||
|
||||
Reference in new issue
Block a user