Add custom hostname function. Add autofill for tenant ip
Change-Id: Id3a875b414faa050c01fa2468b8be383c3081cab
This commit is contained in:
parent
0a902980a3
commit
4c56c7aa59
@ -6,6 +6,7 @@ steal(
|
||||
'./host_config.css',
|
||||
'./views/init.ejs',
|
||||
'./views/server_row.ejs',
|
||||
'./views/pattern_tip.ejs',
|
||||
'ods/models/cluster.js',
|
||||
'lib/jquery-ui-1.10.3.custom.css',
|
||||
'lib/jquery-ui-1.10.3.custom.js',
|
||||
@ -17,17 +18,26 @@ steal(
|
||||
init: function() {
|
||||
this.element.html(this.view('init'));
|
||||
|
||||
$("#clear").click(function() {
|
||||
$(".config_hostname input").val("");
|
||||
});
|
||||
|
||||
var self = this;
|
||||
|
||||
$("#pattern").change(function() {
|
||||
var pattern = $("#pattern").val();
|
||||
if (pattern == "Switch IP") {
|
||||
$("#custom-pattern").hide();
|
||||
} else if (pattern == "Switch alias") {
|
||||
$("#custom-pattern").hide();
|
||||
} else if (pattern == "Host") {
|
||||
$("#custom-pattern").hide();
|
||||
} else if (pattern == "Custom") {
|
||||
$("#custom-pattern").show();
|
||||
}
|
||||
});
|
||||
|
||||
$("#dialog-confirm").dialog({
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
height: 200,
|
||||
width: 400,
|
||||
width: 500,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Fill values": function() {
|
||||
@ -38,6 +48,8 @@ steal(
|
||||
self.fillHostnameBySwitchAlias();
|
||||
} else if (pattern == "Host") {
|
||||
self.fillHostnameByServer();
|
||||
} else if (pattern == "Custom") {
|
||||
self.fillHostnameByCustomStr();
|
||||
}
|
||||
|
||||
$(this).dialog("close");
|
||||
@ -53,7 +65,7 @@ steal(
|
||||
content: function() {
|
||||
var element = $(this);
|
||||
if (element.is("[data-geo]")) {
|
||||
return "<div><strong>Switch IP: </strong>" + "Use the IP address and port for the switch to which the host is attached </div>" + "<div><strong>Switch alias: </strong>Use the switch alias for the switch and port to which the host is attached</div>" + "<div><strong>Server: </strong>Auto-increment integer value based on the last generated value</div>";
|
||||
return self.view('pattern_tip');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -70,6 +82,12 @@ steal(
|
||||
this.server_count = this.options.odsState.servers.length;
|
||||
},
|
||||
|
||||
'#clear-hostconfig click': function(el, ev) {
|
||||
ev.preventDefault();
|
||||
$(".server-panels input").val("");
|
||||
$(".server-panels select").multipleSelect("uncheckAll");
|
||||
},
|
||||
|
||||
onGetRoles: function(data, textStatus, xhr) {
|
||||
steal.dev.log(" *** onGetRoles data *** ", data);
|
||||
steal.dev.log(" *** onGetRoles textStatus *** ", textStatus);
|
||||
@ -107,13 +125,11 @@ steal(
|
||||
|
||||
fillHostnameBySwitchIp: function() {
|
||||
var serverData = this.options.odsState.servers_config;
|
||||
this.server_count = 0;
|
||||
for (var key in serverData) {
|
||||
var servers = serverData[key];
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
servers[i]['hostname'] = key.replace(/\./g, "-") + '-p' + servers[i].port;
|
||||
serverData[key][i]['hostname'] = servers[i]['hostname'];
|
||||
this.server_count++;
|
||||
}
|
||||
}
|
||||
this.options.odsState.servers_config = serverData;
|
||||
@ -123,14 +139,12 @@ steal(
|
||||
fillHostnameBySwitchAlias: function() {
|
||||
var serverData = this.options.odsState.servers_config;
|
||||
var key_index = 1;
|
||||
this.server_count = 0;
|
||||
for (var key in serverData) {
|
||||
var servers = serverData[key];
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
servers[i]['hostname'] = "switch" + key_index + '-p' + servers[i].port;
|
||||
}
|
||||
key_index++;
|
||||
this.server_count++;
|
||||
}
|
||||
this.options.odsState.servers_config = serverData;
|
||||
this.tabSelected($(".tab_nav_active"));
|
||||
@ -139,13 +153,112 @@ steal(
|
||||
fillHostnameByServer: function() {
|
||||
var serverData = this.options.odsState.servers_config;
|
||||
var server_index = 1;
|
||||
this.server_count = 0;
|
||||
for (var key in serverData) {
|
||||
var servers = serverData[key];
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
servers[i]['hostname'] = "server" + server_index;
|
||||
server_index++;
|
||||
this.server_count++;
|
||||
}
|
||||
}
|
||||
this.options.odsState.servers_config = serverData;
|
||||
this.tabSelected($(".tab_nav_active"));
|
||||
},
|
||||
|
||||
fillHostnameByCustomStr: function() {
|
||||
var preDefinedPatterns = ["{switchIp}", "{port}",
|
||||
"{d.1}", "{d.2}", "{d.3}", "{d.4}",
|
||||
"{mgtIpPart1}", "{mgtIpPart2}", "{mgtIpPart3}", "{mgtIpPart4}",
|
||||
"{tntIpPart1}", "{tntIpPart2}", "{tntIpPart3}", "{tntIpPart4}"
|
||||
];
|
||||
var customStr = $("#custom-pattern").val();
|
||||
var serverData = this.options.odsState.servers_config;
|
||||
var server_index = 1;
|
||||
var customHostname = "";
|
||||
|
||||
for (var key in serverData) {
|
||||
var servers = serverData[key];
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
customStr = $("#custom-pattern").val();
|
||||
for (var patternIndex = 0; patternIndex < preDefinedPatterns.length; patternIndex++) {
|
||||
if (customStr.indexOf(preDefinedPatterns[patternIndex]) != -1) {
|
||||
switch (patternIndex) {
|
||||
case 0: //{switchIp}
|
||||
customHostname = customStr.replace("{switchIp}", key.replace(/\./g, "-"));
|
||||
break;
|
||||
case 1: //{port}
|
||||
customHostname = customStr.replace("{port}", servers[i].port);
|
||||
break;
|
||||
case 2: //{d.1}
|
||||
customHostname = customStr.replace("{d.1}", server_index);
|
||||
break;
|
||||
case 3: //{d.2}
|
||||
if (server_index < 10) {
|
||||
customHostname = customStr.replace("{d.2}", "0" + server_index);
|
||||
} else {
|
||||
customHostname = customStr.replace("{d.2}", server_index);
|
||||
}
|
||||
break;
|
||||
case 4: //{d.3}
|
||||
if (server_index < 10) {
|
||||
customHostname = customStr.replace("{d.3}", "00" + server_index);
|
||||
} else if (server_index < 100) {
|
||||
customHostname = customStr.replace("{d.3}", "0" + server_index);
|
||||
} else {
|
||||
customHostname = customStr.replace("{d.3}", server_index);
|
||||
}
|
||||
break;
|
||||
case 5: //{d.4}
|
||||
if (server_index < 10) {
|
||||
customHostname = customStr.replace("{d.4}", "000" + server_index);
|
||||
} else if (server_index < 100) {
|
||||
customHostname = customStr.replace("{d.4}", "00" + server_index);
|
||||
} else if (server_index < 1000) {
|
||||
customHostname = customStr.replace("{d.4}", "0" + server_index);
|
||||
} else {
|
||||
customHostname = customStr.replace("{d.4}", server_index);
|
||||
}
|
||||
break;
|
||||
case 6: //{mgtIpPart1}
|
||||
var mgtIpPart1 = servers[i].management_ip.split(".")[0];
|
||||
customHostname = customStr.replace("{mgtIpPart1}", mgtIpPart1);
|
||||
break;
|
||||
case 7: //{mgtIpPart2}
|
||||
var mgtIpPart2 = servers[i].management_ip.split(".")[1];
|
||||
customHostname = customStr.replace("{mgtIpPart2}", mgtIpPart2);
|
||||
break;
|
||||
case 8: //{mgtIpPart3}
|
||||
var mgtIpPart3 = servers[i].management_ip.split(".")[2];
|
||||
customHostname = customStr.replace("{mgtIpPart3}", mgtIpPart3);
|
||||
break;
|
||||
case 9: //{mgtIpPart4}
|
||||
var mgtIpPart4 = servers[i].management_ip.split(".")[3];
|
||||
customHostname = customStr.replace("{mgtIpPart4}", mgtIpPart4);
|
||||
break;
|
||||
case 10: //{tntIpPart1}
|
||||
var tntIpPart1 = servers[i].tenant_ip.split(".")[0];
|
||||
customHostname = customStr.replace("{tntIpPart1}", tntIpPart1);
|
||||
break;
|
||||
case 11: //{tntIpPart2}
|
||||
var tntIpPart2 = servers[i].tenant_ip.split(".")[1];
|
||||
customHostname = customStr.replace("{tntIpPart2}", tntIpPart2);
|
||||
break;
|
||||
case 12: //{tntIpPart3}
|
||||
var tntIpPart3 = servers[i].tenant_ip.split(".")[2];
|
||||
customHostname = customStr.replace("{tntIpPart3}", tntIpPart3);
|
||||
break;
|
||||
case 13: //{tntIpPart4}
|
||||
var tntIpPart4 = servers[i].tenant_ip.split(".")[3];
|
||||
customHostname = customStr.replace("{tntIpPart4}", tntIpPart4);
|
||||
break;
|
||||
default:
|
||||
customHostname = "";
|
||||
break;
|
||||
}
|
||||
customStr = customHostname;
|
||||
} // end of if
|
||||
} //end of preDefinedPatterns for loop
|
||||
servers[i]['hostname'] = customHostname;
|
||||
server_index++;
|
||||
}
|
||||
}
|
||||
this.options.odsState.servers_config = serverData;
|
||||
@ -157,7 +270,7 @@ steal(
|
||||
var count = 0;
|
||||
for (var key in serverData) {
|
||||
$(".switch-navs").append('<div data-switchIp="' + key + '" class="tab_nav">' + key + '</div><br>');
|
||||
count ++;
|
||||
count++;
|
||||
}
|
||||
var panel_minheight = $(".tab_nav").height() * count + 50;
|
||||
$(".tab_panel_active").css("min-height", panel_minheight);
|
||||
@ -191,7 +304,8 @@ steal(
|
||||
var currentSwitch = $(".tab_nav_active").data('switchip');
|
||||
for (var i = 0; i < this.options.odsState.servers_config[currentSwitch].length; i++) {
|
||||
this.options.odsState.servers_config[currentSwitch][i].hostname = $("#hostconfig-table tbody tr").eq(i).find(".hostname").val();
|
||||
this.options.odsState.servers_config[currentSwitch][i].server_ip = $("#hostconfig-table tbody tr").eq(i).find(".serverIp").val();
|
||||
this.options.odsState.servers_config[currentSwitch][i].management_ip = $("#hostconfig-table tbody tr").eq(i).find(".managenetIp").val();
|
||||
this.options.odsState.servers_config[currentSwitch][i].tenant_ip = $("#hostconfig-table tbody tr").eq(i).find(".tenantIp").val();
|
||||
var roles = $("#hostconfig-table tbody tr").eq(i).find(".roles").val();
|
||||
if(!roles) {
|
||||
roles = [];
|
||||
@ -251,7 +365,9 @@ steal(
|
||||
//var server_id = servers[i]['server_id'];
|
||||
var clusterhost_id = servers[i]['clusterhost_id'];
|
||||
var hostname = servers[i]['hostname'];
|
||||
var server_ip = servers[i]['server_ip'];
|
||||
//var server_ip = servers[i]['server_ip'];
|
||||
var management_ip = servers[i]['management_ip'];
|
||||
var tenant_ip = servers[i]['tenant_ip'];
|
||||
var roles = servers[i]['roles'];
|
||||
|
||||
var clusterhostConfigData = {
|
||||
@ -259,7 +375,10 @@ steal(
|
||||
"networking": {
|
||||
"interfaces": {
|
||||
"management": {
|
||||
"ip": server_ip
|
||||
"ip": management_ip
|
||||
},
|
||||
"tenant": {
|
||||
"ip": tenant_ip
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -26,7 +26,8 @@
|
||||
id: 10,
|
||||
mac: "28:6e:31:47:c8:6c",
|
||||
port: "1",
|
||||
server_ip: "10.2.172.9",
|
||||
management_ip: "10.2.172.9",
|
||||
tenant_ip: "192.168.100.100",
|
||||
switch_ip: "172.29.8.40",
|
||||
vlan: "1",
|
||||
roles: []
|
||||
@ -38,7 +39,8 @@
|
||||
id: 10,
|
||||
mac: "28:6e:31:34:fd:28",
|
||||
port: "2",
|
||||
server_ip: "10.2.172.9",
|
||||
management_ip: "10.2.172.10",
|
||||
tenant_ip: "192.168.100.101",
|
||||
switch_ip: "172.29.8.40",
|
||||
vlan: "2",
|
||||
roles: []
|
||||
|
@ -5,18 +5,22 @@
|
||||
<div class="rounded" style="padding-top: 10; padding-bottom: 5px">
|
||||
<div class="float_left">Switch IP</div>
|
||||
<div class="float_right">
|
||||
<a href="#" id="auto_fill" style="padding-right:20px">Auto-fill values</a>
|
||||
<a href="#">Clear</a>
|
||||
<a href="javascript: void(0)" id="auto_fill" style="padding-right:20px">Auto-fill values</a>
|
||||
<a id="clear-hostconfig" href="javascript: void(0)">Clear</a>
|
||||
</div>
|
||||
<div class="clear"> </div>
|
||||
<div id="dialog-confirm" title="Auto fill values">
|
||||
<p>
|
||||
Host name pattern:
|
||||
<div class="float_left" id="test">Host name pattern:</div>
|
||||
<div class="float_left">
|
||||
<select id="pattern">
|
||||
<option>Switch IP</option>
|
||||
<option>Switch alias</option>
|
||||
<option>Host</option>
|
||||
</select>
|
||||
<option value="Host">Host</option>
|
||||
<option value="Switch IP">Switch IP</option>
|
||||
<option value="Switch alias">Switch alias</option>
|
||||
<option value="Custom">Custom</option>
|
||||
</select><br>
|
||||
<input id="custom-pattern" class="rounded non-empty-value" style="display:none; margin-top:10px; width:255px">
|
||||
</div>
|
||||
<span class="pattern-tip ui-icon ui-icon-info" style="float: right; margin: 6px 19px 4px 7px;" data-geo="info-ico">
|
||||
</p>
|
||||
</div>
|
||||
@ -31,7 +35,8 @@
|
||||
<tr>
|
||||
<th>Port</th>
|
||||
<th>Host name</th>
|
||||
<th>IP address</th>
|
||||
<th>Management IP</th>
|
||||
<th>Tenant IP</th>
|
||||
<th>Roles</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
17
public/ods/ui/host_config/views/pattern_tip.ejs
Normal file
17
public/ods/ui/host_config/views/pattern_tip.ejs
Normal file
@ -0,0 +1,17 @@
|
||||
<div>
|
||||
<strong>Switch IP: </strong>
|
||||
Use the IP address and port for the switch to which the host is attached
|
||||
</div>
|
||||
<div>
|
||||
<strong>Switch alias: </strong>
|
||||
Use the switch alias for the switch and port to which the host is attached
|
||||
</div>
|
||||
<div>
|
||||
<strong>Server: </strong>
|
||||
Auto-increment integer value based on the last generated value
|
||||
</div>
|
||||
<div>
|
||||
<strong>Custom: </strong>
|
||||
Pre-defined patterns include {switchIp}, {port}, {d.1}, {d.2}, {d.3}, {d.4},
|
||||
{mgtIpPart1}, {mgtIpPart2}, {mgtIpPart3}, {mgtIpPart4},
|
||||
{tntIpPart1}, {tntIpPart2}, {tntIpPart3}, {tntIpPart4}</div>
|
@ -6,7 +6,10 @@
|
||||
<input class="rounded hostname non-empty-value" name="hostname" value="<%= hostname %>">
|
||||
</td>
|
||||
<td>
|
||||
<input class="rounded serverIp non-empty-value" name="serverIp" value="<%= server_ip %>">
|
||||
<input class="rounded managenetIp non-empty-value" name="managenetIp" value="<%= management_ip %>">
|
||||
</td>
|
||||
<td>
|
||||
<input class="rounded tenantIp non-empty-value" name="tenantIp" value="<%= tenant_ip %>">
|
||||
</td>
|
||||
<td>
|
||||
<select multiple="multiple" class="roles" name="roles">
|
||||
|
@ -87,7 +87,7 @@ steal(
|
||||
|
||||
initServerTable: function() {
|
||||
this.dataTable = $('#tb_server_review').dataTable({
|
||||
"sScrollY": "200px",
|
||||
"sScrollY": "450px",
|
||||
"bPaginate": false,
|
||||
"bScrollCollapse": true,
|
||||
"aoColumns": [{
|
||||
@ -95,19 +95,32 @@ steal(
|
||||
}, {
|
||||
"mData": "mac"
|
||||
}, {
|
||||
"mData": "server_ip"
|
||||
"mData": "management_ip"
|
||||
}, {
|
||||
"mData": "tenant_ip"
|
||||
}, {
|
||||
"mData": "switch_ip"
|
||||
}, {
|
||||
"mData": "port"
|
||||
}, {
|
||||
"mData": "roles",
|
||||
"mRender": function(data, type, full) {
|
||||
if (data.length == 0) {
|
||||
return "auto";
|
||||
} else if (data.toString().length <=10) {
|
||||
return data;
|
||||
} else {
|
||||
return data.toString().substring(0, 10) + " ...";
|
||||
}
|
||||
}
|
||||
}],
|
||||
"aoColumnDefs": [{
|
||||
bSortable: false,
|
||||
aTargets: [0, 1, 2]
|
||||
aTargets: [0, 1, 2, 3, 6]
|
||||
}],
|
||||
"aaSorting": [
|
||||
[3, "asc"],
|
||||
[4, "asc"]
|
||||
[4, "asc"],
|
||||
[5, "asc"]
|
||||
]
|
||||
});
|
||||
$('.dataTables_info').remove();
|
||||
|
@ -28,9 +28,11 @@
|
||||
id: 10,
|
||||
mac: "28:6e:31:47:c8:6c",
|
||||
port: "1",
|
||||
server_ip: "10.2.172.9",
|
||||
management_ip: "10.2.172.9",
|
||||
tenant_ip: "192.168.100.101",
|
||||
switch_ip: "172.29.8.40",
|
||||
vlan: "1"
|
||||
vlan: "1",
|
||||
roles: ["role1", "role2", "role3", "role4", "role5", "role6", "role7"]
|
||||
};
|
||||
|
||||
var server2 = {
|
||||
@ -39,9 +41,11 @@
|
||||
id: 20,
|
||||
mac: "28:6e:31:34:fd:28",
|
||||
port: "2",
|
||||
server_ip: "10.2.172.9",
|
||||
management_ip: "10.2.172.10",
|
||||
tenant_ip: "192.168.100.102",
|
||||
switch_ip: "172.29.8.40",
|
||||
vlan: "2"
|
||||
vlan: "2",
|
||||
roles: ["role2"]
|
||||
};
|
||||
|
||||
if (config["172.29.8.40"] == undefined) {
|
||||
|
@ -73,9 +73,11 @@
|
||||
<tr>
|
||||
<th>Host name</th>
|
||||
<th>MAC Addr</th>
|
||||
<th>Server IP</th>
|
||||
<th>Mgt IP</th>
|
||||
<th>Tenant IP</th>
|
||||
<th>Switch IP</th>
|
||||
<th>Port</th>
|
||||
<th>Roles</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody> </tbody>
|
||||
|
@ -137,9 +137,24 @@ steal(
|
||||
|
||||
// verify IP range
|
||||
if (!$(".ipaddress").hasClass("error") && this.nicErr == 0) {
|
||||
this.verifyIpRange(mgt_ipstart, mgt_ipend, this.options.odsState.servers.length);
|
||||
if (!this.ipRangeValid) {
|
||||
var mgtIpRangeValid = this.verifyIpRange(mgt_ipstart, mgt_ipend, this.options.odsState.servers.length);
|
||||
var tenantIpRangeValid = this.verifyIpRange(tenant_ipstart, tenant_ipend, this.options.odsState.servers.length);
|
||||
|
||||
var mindex = mgt_ipstart.lastIndexOf('.') + 1;
|
||||
var mgtIpPrefix = mgt_ipstart.substring(0, mindex);
|
||||
var mgtIpStartLastDigit = mgt_ipstart.substring(mindex);
|
||||
var mgtIpEndLastDigit = mgt_ipend.substring(mindex);
|
||||
|
||||
var tindex = tenant_ipstart.lastIndexOf('.') + 1;
|
||||
var tenantIpPrefix = tenant_ipstart.substring(0, tindex);
|
||||
var tenantIpStartLastDigit = tenant_ipstart.substring(tindex);
|
||||
var tenantIpEndLastDigit = tenant_ipend.substring(tindex);
|
||||
|
||||
|
||||
if (!mgtIpRangeValid) {
|
||||
alert("The management IP range is not valid.");
|
||||
} else if (!tenantIpRangeValid) {
|
||||
alert("The tenant IP range is not valid.");
|
||||
} else {
|
||||
// config server ip
|
||||
var server_count = this.options.odsState.servers.length;
|
||||
@ -181,7 +196,8 @@ steal(
|
||||
for (var key in serverData) {
|
||||
var servers = serverData[key];
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
serverData[key][i]['server_ip'] = this.startPrefix + (parseInt(this.startLastDigit) + j);
|
||||
serverData[key][i]['management_ip'] = mgtIpPrefix + (parseInt(mgtIpStartLastDigit) + j);
|
||||
serverData[key][i]['tenant_ip'] = tenantIpPrefix + (parseInt(tenantIpStartLastDigit) + j);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
@ -355,20 +371,18 @@ steal(
|
||||
},
|
||||
|
||||
verifyIpRange: function(start, end, minCount) {
|
||||
this.ipRangeValid = false;
|
||||
|
||||
var rindex = start.lastIndexOf('.') + 1;
|
||||
this.startPrefix = start.substring(0, rindex);
|
||||
this.endPrefix = end.substring(0, rindex);
|
||||
this.startLastDigit = start.substring(rindex);
|
||||
this.endLastDigit = end.substring(rindex);
|
||||
var startPrefix = start.substring(0, rindex);
|
||||
var endPrefix = end.substring(0, rindex);
|
||||
var startLastDigit = start.substring(rindex);
|
||||
var endLastDigit = end.substring(rindex);
|
||||
|
||||
if (this.startPrefix != this.endPrefix) {
|
||||
this.ipRangeValid = false;
|
||||
} else if (parseInt(this.endLastDigit) - parseInt(this.startLastDigit) < minCount) {
|
||||
this.ipRangeValid = false;
|
||||
if (startPrefix != endPrefix) {
|
||||
return false;
|
||||
} else if (parseInt(endLastDigit) - parseInt(startLastDigit) < minCount) {
|
||||
return false;
|
||||
} else {
|
||||
this.ipRangeValid = true;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -217,7 +217,7 @@ steal(
|
||||
},
|
||||
|
||||
'getSelectedServers': function() {
|
||||
console.log("displayNodes ", this.displayNodes);
|
||||
this.dataTable.fnFilter('');
|
||||
var selectedServers = [];
|
||||
|
||||
this.options.odsState.servers = [];
|
||||
|
Loading…
Reference in New Issue
Block a user