1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #1491: SecGroups disabled when creating an OpenvSwitch net

This commit is contained in:
Abel Coronado 2017-12-21 12:12:23 +01:00 committed by Ruben S. Montero
parent f615e197c5
commit 68c6ad8607

View File

@ -20,30 +20,30 @@ define(function(require) {
*/
// require('foundation.tab');
var BaseFormPanel = require('utils/form-panels/form-panel');
var Sunstone = require('sunstone');
var Locale = require('utils/locale');
var Tips = require('utils/tips');
var CustomTagsTable = require('utils/custom-tags-table');
var ArTab = require('tabs/vnets-tab/utils/ar-tab');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var TemplateUtils = require('utils/template-utils');
var WizardFields = require('utils/wizard-fields');
var ResourceSelect = require('utils/resource-select');
var BaseFormPanel = require("utils/form-panels/form-panel");
var Sunstone = require("sunstone");
var Locale = require("utils/locale");
var Tips = require("utils/tips");
var CustomTagsTable = require("utils/custom-tags-table");
var ArTab = require("tabs/vnets-tab/utils/ar-tab");
var SecurityGroupsTable = require("tabs/secgroups-tab/datatable");
var TemplateUtils = require("utils/template-utils");
var WizardFields = require("utils/wizard-fields");
var ResourceSelect = require("utils/resource-select");
/*
TEMPLATES
*/
var TemplateWizardHTML = require('hbs!./create/wizard');
var TemplateAdvancedHTML = require('hbs!./create/advanced');
var TemplateWizardHTML = require("hbs!./create/wizard");
var TemplateAdvancedHTML = require("hbs!./create/advanced");
/*
CONSTANTS
*/
var FORM_PANEL_ID = require('./create/formPanelId');
var TAB_ID = require('../tabId');
var FORM_PANEL_ID = require("./create/formPanelId");
var TAB_ID = require("../tabId");
/*
CONSTRUCTOR
@ -53,15 +53,15 @@ define(function(require) {
this.formPanelId = FORM_PANEL_ID;
this.tabId = TAB_ID;
this.actions = {
'create': {
'title': Locale.tr("Create Virtual Network"),
'buttonText': Locale.tr("Create"),
'resetButton': true
"create": {
"title": Locale.tr("Create Virtual Network"),
"buttonText": Locale.tr("Create"),
"resetButton": true
},
'update': {
'title': Locale.tr("Update Virtual Network"),
'buttonText': Locale.tr("Update"),
'resetButton': false
"update": {
"title": Locale.tr("Update Virtual Network"),
"buttonText": Locale.tr("Update"),
"resetButton": false
}
};
@ -96,9 +96,9 @@ define(function(require) {
this.securityGroupsTable = new SecurityGroupsTable("vnet_create", opts);
return TemplateWizardHTML({
'formPanelId': this.formPanelId,
'customTagsHTML': CustomTagsTable.html(),
'securityGroupsTableHTML': this.securityGroupsTable.dataTableHTML
"formPanelId": this.formPanelId,
"customTagsHTML": CustomTagsTable.html(),
"securityGroupsTableHTML": this.securityGroupsTable.dataTableHTML
});
}
@ -117,7 +117,7 @@ define(function(require) {
that.addARTab(number_of_ar, context);
number_of_ar++;
var mode = $("#network_mode", context).val();
if(mode == "vcenter"){
if (mode == "vcenter"){
$(".sec_groups_datatable", context).hide();
}
return false;
@ -125,108 +125,109 @@ define(function(require) {
$("#vnetCreateARTab #vnetCreateARTabUpdate", context).hide();
$('#network_mode', context).change(function() {
$("#network_mode", context).change(function() {
$("div.mode_param", context).hide();
$("div.mode_param [wizard_field]", context).prop('wizard_field_disabled', true);
$("div.mode_param [wizard_field]", context).prop("wizard_field_disabled", true);
$('input#vn_mad', context).removeAttr('required');
$('input#vn_mad', context).removeAttr('value');
$('#vcenter_switch_name', context).removeAttr('required');
$('#vcenter_cluster_id', context).removeAttr('required');
$("input#vn_mad", context).removeAttr("required");
$("input#vn_mad", context).removeAttr("value");
$("#vcenter_switch_name", context).removeAttr("required");
$("#vcenter_cluster_id", context).removeAttr("required");
$(".sec_groups_datatable", context).show();
$('#vnetCreateSecurityTab-label').show();
$("#vnetCreateSecurityTab-label").show();
switch ($(this).val()) {
case "dummy":
$("div.mode_param.dummy", context).show();
$("div.mode_param.dummy [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.dummy [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).attr('required', '');
$("input#bridge", context).attr("required", "");
break;
case "fw":
$("div.mode_param.fw", context).show();
$("div.mode_param.fw [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.fw [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).attr('required', '');
$("input#bridge", context).attr("required", "");
break;
case "802.1Q":
$("div.mode_param.8021Q", context).show();
$("div.mode_param.8021Q [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.8021Q [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).removeAttr('required');
$("input#bridge", context).removeAttr("required");
break;
case "vxlan":
$("div.mode_param.vxlan", context).show();
$("div.mode_param.vxlan [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.vxlan [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).removeAttr('required');
$("input#bridge", context).removeAttr("required");
break;
case "ebtables":
$("div.mode_param.ebtables", context).show();
$("div.mode_param.ebtables [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.ebtables [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).attr('required', '');
$("input#bridge", context).attr("required", "");
break;
case "ovswitch":
$("div.mode_param.ovswitch", context).show();
$("div.mode_param.ovswitch [wizard_field]", context).prop('wizard_field_disabled', false);
$("#vnetCreateSecurityTab-label").hide();
$("div.mode_param.ovswitch [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).attr('required', '');
$("input#bridge", context).attr("required", "");
break;
case "vcenter":
$("div.mode_param.vcenter", context).show();
$(".sec_groups_datatable", context).hide();
$("div.mode_param.vcenter [wizard_field]", context).prop('wizard_field_disabled', false);
$('input#bridge', context).attr('value', $('#name', context).val());
$('#vcenter_switch_name', context).attr('required', '');
$('#vnetCreateSecurityTab-label').hide();
$("div.mode_param.vcenter [wizard_field]", context).prop("wizard_field_disabled", false);
$("input#bridge", context).attr("value", $("#name", context).val());
$("#vcenter_switch_name", context).attr("required", "");
$("#vnetCreateSecurityTab-label").hide();
ResourceSelect.insert({
context: $('#vcenter_cluster_id', context),
resourceName: 'Host',
context: $("#vcenter_cluster_id", context),
resourceName: "Host",
emptyValue: true,
nameValues: false,
filterKey: 'VM_MAD',
filterValue: 'vcenter',
filterKey: "VM_MAD",
filterValue: "vcenter",
required: true,
callback: function(element){
element.attr('wizard_field', 'VCENTER_ONE_HOST_ID');
element.attr("wizard_field", "VCENTER_ONE_HOST_ID");
}
});
$('input#vn_mad', context).attr('required', '');
$('input#vn_mad', context).attr('value', 'vcenter');
$("input#vn_mad", context).attr("required", "");
$("input#vn_mad", context).attr("value", "vcenter");
$('#div_vn_mad', context).hide();
$("#div_vn_mad", context).hide();
break;
case "custom":
$("div.mode_param.custom", context).show();
$("div.mode_param.custom [wizard_field]", context).prop('wizard_field_disabled', false);
$("div.mode_param.custom [wizard_field]", context).prop("wizard_field_disabled", false);
$('input#bridge', context).removeAttr('required');
$('input#vn_mad', context).attr('required', '');
$("input#bridge", context).removeAttr("required");
$("input#vn_mad", context).attr("required", "");
break;
}
$("div.network_mode_description").hide();
$('div.network_mode_description[value="' + $(this).val() + '"]').show();
$("div.network_mode_description[value=\"" + $(this).val() + "\"]").show();
});
$('select[wizard_field=AUTOMATIC_VLAN_ID]', context).change(function(){
$("select[wizard_field=AUTOMATIC_VLAN_ID]", context).change(function(){
if($(this).val() != "") {
$('input[wizard_field="VLAN_ID"]', context).hide().prop('wizard_field_disabled', true);
$("input[wizard_field=\"VLAN_ID\"]", context).hide().prop("wizard_field_disabled", true);
} else {
$('input[wizard_field="VLAN_ID"]', context).show().prop('wizard_field_disabled', false);
$("input[wizard_field=\"VLAN_ID\"]", context).show().prop("wizard_field_disabled", false);
}
});
//Initialize shown options
$('#network_mode', context).trigger("change");
$('select[wizard_field=AUTOMATIC_VLAN_ID]', context).trigger("change");
$("#network_mode", context).trigger("change");
$("select[wizard_field=AUTOMATIC_VLAN_ID]", context).trigger("change");
this.securityGroupsTable.initialize();
CustomTagsTable.setup($("#vnetCreateContextTab", context));
Foundation.reflow(context, 'tabs');
Foundation.reflow(context, "tabs");
// Add first AR
$("#vnet_wizard_ar_btn", context).trigger("click");
@ -237,15 +238,15 @@ define(function(require) {
function _add_ar_tab(ar_id, context) {
var that = this;
var str_ar_tab_id = 'ar' + ar_id;
var str_ar_tab_id = "ar" + ar_id;
var ar_tab = new ArTab();
this.arTabObjects[ar_id] = ar_tab;
var html_tab_content =
'<div id="' + str_ar_tab_id + 'Tab" class="ar_tab tabs-panel" ar_id="' + ar_id + '">' +
"<div id=\"" + str_ar_tab_id + "Tab\" class=\"ar_tab tabs-panel\" ar_id=\"" + ar_id + "\">" +
ar_tab.html(str_ar_tab_id) +
'</div>';
"</div>";
// Append the new div containing the tab and add the tab to the list
var a = $("<li class='tabs-title'>" +
@ -258,7 +259,7 @@ define(function(require) {
Foundation.reInit($("ul#vnet_wizard_ar_tabs", context));
$("a", a).trigger("click");
var ar_section = $('#' + str_ar_tab_id + 'Tab', context);
var ar_section = $("#" + str_ar_tab_id + "Tab", context);
ar_tab.setup(ar_section, str_ar_tab_id);
ar_tab.onShow();
@ -266,8 +267,8 @@ define(function(require) {
// close icon: removing the tab on click
a.on("click", "i.remove-tab", function() {
var target = $(this).parent().attr("href");
var li = $(this).closest('li');
var ul = $(this).closest('ul');
var li = $(this).closest("li");
var ul = $(this).closest("ul");
var content = $(target);
var ar_id = content.attr("ar_id");
@ -275,8 +276,8 @@ define(function(require) {
li.remove();
content.remove();
if (li.hasClass('is-active')) {
$('a', ul.children('li').last()).click();
if (li.hasClass("is-active")) {
$("a", ul.children("li").last()).click();
}
delete that.arTabObjects[ar_id];
@ -303,7 +304,7 @@ define(function(require) {
$.extend(network_json, CustomTagsTable.retrieve($("#vnetCreateContextTab", context)));
$('.ar_tab', context).each(function() {
$(".ar_tab", context).each(function() {
var ar_id = $(this).attr("ar_id");
var hash = that.arTabObjects[ar_id].retrieve();
@ -330,13 +331,13 @@ define(function(require) {
function _submitAdvanced(context) {
if (this.action == "create") {
var template = $('textarea#template', context).val();
var template = $("textarea#template", context).val();
var vnet_json = {vnet: {vnet_raw: template}};
Sunstone.runAction("Network.create", vnet_json);
return false;
} else if (this.action == "update") {
var template_raw = $('textarea#template', context).val();
var template_raw = $("textarea#template", context).val();
Sunstone.runAction("Network.update", this.resourceId, template_raw);
return false;
}
@ -347,7 +348,7 @@ define(function(require) {
this.securityGroupsTable.refreshResourceTableSelect();
$('.ar_tab', context).each(function() {
$(".ar_tab", context).each(function() {
var ar_id = $(this).attr("ar_id");
that.arTabObjects[ar_id].onShow();
});
@ -360,25 +361,25 @@ define(function(require) {
$("#default_sg_warning", context).hide();
// Populates the Avanced mode Tab
$('#template', context).val(TemplateUtils.templateToString(element.TEMPLATE));
$("#template", context).val(TemplateUtils.templateToString(element.TEMPLATE));
WizardFields.fillInput($('[wizard_field="NAME"]', context), element.NAME);
$('[wizard_field="NAME"]', context).prop("disabled", true).prop('wizard_field_disabled', true);
WizardFields.fillInput($("[wizard_field=\"NAME\"]", context), element.NAME);
$("[wizard_field=\"NAME\"]", context).prop("disabled", true).prop("wizard_field_disabled", true);
// Show all network mode inputs, and make them not required. This will change
// if a different network model is selected
$('input#bridge', context).attr('required', '');
$("input#bridge", context).attr("required", "");
$("div.mode_param", context).show();
$("div.mode_param [wizard_field]", context).prop('wizard_field_disabled', true).removeAttr('required');
$("div.mode_param [wizard_field]", context).prop("wizard_field_disabled", true).removeAttr("required");
WizardFields.fillInput($('input#vn_mad', context), element.TEMPLATE["VN_MAD"]);
WizardFields.fillInput($("input#vn_mad", context), element.TEMPLATE["VN_MAD"]);
if (element.VLAN_ID_AUTOMATIC == 1){
$('select[wizard_field=AUTOMATIC_VLAN_ID]', context).val("YES").
attr('disabled', 'disabled').trigger("change");
$("select[wizard_field=AUTOMATIC_VLAN_ID]", context).val("YES").
attr("disabled", "disabled").trigger("change");
} else {
$('select[wizard_field=AUTOMATIC_VLAN_ID]', context).val("").
attr('disabled', 'disabled').trigger("change");
$("select[wizard_field=AUTOMATIC_VLAN_ID]", context).val("").
attr("disabled", "disabled").trigger("change");
}
WizardFields.fill($("#vnetCreateGeneralTab", context), element.TEMPLATE);
@ -386,8 +387,8 @@ define(function(require) {
WizardFields.fill($("#vnetCreateQoSTab", context), element.TEMPLATE);
WizardFields.fill($("#vnetCreateContextTab", context), element.TEMPLATE);
if ($('#network_mode', context).val() == undefined){
$('#network_mode', context).val("custom").change();
if ($("#network_mode", context).val() == undefined){
$("#network_mode", context).val("custom").change();
}
if (element.TEMPLATE["SECURITY_GROUPS"] != undefined &&
@ -403,11 +404,11 @@ define(function(require) {
// Delete so these attributes don't end in the custom tags table also
delete element.TEMPLATE["SECURITY_GROUPS"];
var fields = $('[wizard_field]', context);
var fields = $("[wizard_field]", context);
fields.each(function() {
var field = $(this);
var field_name = field.attr('wizard_field');
var field_name = field.attr("wizard_field");
delete element.TEMPLATE[field_name];
});