Implement NodeBalancers
This commit is contained in:
87
nodebalancers/node/index.shtml
Normal file
87
nodebalancers/node/index.shtml
Normal file
@ -0,0 +1,87 @@
|
||||
<!--
|
||||
This file is part of Linode Manager Classic.
|
||||
|
||||
Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>LMC - NodeBalancers</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="node.css" />
|
||||
<script src="node.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="top-links"><a href="/nodebalancers">NodeBalancers</a> » <span id="nodebalancer-tag"><a id="nodebalancer-tag-link" href=""></a> » </span><a id="nodebalancer-label" href="/nodebalancers/balancer?nbid=0"></a> » <a id="config-label" href="/nodebalancers/config?nbid=0&nbcid=0">Port</a> » <span class="top-links-title">Edit Node</span></div>
|
||||
<div id="node">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Edit Node</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">Node Settings</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Label</td>
|
||||
<td><input id="label" type="text" size="30" /></td>
|
||||
<td class="info">This backend node's label</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Address</td>
|
||||
<td>
|
||||
<select id="address">
|
||||
<option selected disabled value="0">Select A Linode</option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="info">The private IP address of the backend Linode instance</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Port</td>
|
||||
<td><input id="port" type="number" min="1" max="65535" size="4" /></td>
|
||||
<td class="info">The backend port for this node</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Weight</td>
|
||||
<td><input id="weight" type="number" min="1" max="255" value="100" size="4" /></td>
|
||||
<td class="info">Load balancing weight, 1-255. Higher means more connections.</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Mode</td>
|
||||
<td>
|
||||
<select id="mode">
|
||||
<option value="accept">Accept</option>
|
||||
<option value="reject">Reject</option>
|
||||
<option value="backup">Backup</option>
|
||||
<option value="drain">Drain</option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="info">The connections mode for this node</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td></td>
|
||||
<td><button disabled id="save-button" type="button">Save Changes</button></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
nodebalancers/node/node.css
Normal file
27
nodebalancers/node/node.css
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@import url('/global.css');
|
||||
|
||||
#node {
|
||||
padding: 0px 15px 15px;
|
||||
}
|
||||
|
||||
tbody tr td:first-of-type {
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
255
nodebalancers/node/node.js
Normal file
255
nodebalancers/node/node.js
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { settings, elements, apiGet, apiPost, apiPut, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.address = "address";
|
||||
elements.configLabel = "config-label";
|
||||
elements.label = "label";
|
||||
elements.mode = "mode";
|
||||
elements.nodebalancerLabel = "nodebalancer-label";
|
||||
elements.nodebalancerTag = "nodebalancer-tag";
|
||||
elements.nodebalancerTagLink = "nodebalancer-tag-link";
|
||||
elements.port = "port";
|
||||
elements.saveButton = "save-button";
|
||||
elements.weight = "weight";
|
||||
|
||||
// Data recieved from API calls
|
||||
var data = {};
|
||||
data.config = {};
|
||||
data.linodeFilters = {
|
||||
"ipv4": {
|
||||
"+contains": "192.168"
|
||||
}
|
||||
};
|
||||
data.linodes = [];
|
||||
data.nodebalancer = {};
|
||||
data.node = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.address = {};
|
||||
ui.configLabel = {};
|
||||
ui.label = {};
|
||||
ui.mode = {};
|
||||
ui.nodebalancerLabel = {};
|
||||
ui.nodebalancerTag = {};
|
||||
ui.nodebalancerTagLink = {};
|
||||
ui.port = {};
|
||||
ui.saveButton = {};
|
||||
ui.weight = {};
|
||||
|
||||
// Callback for config API call
|
||||
var displayConfig = function(response)
|
||||
{
|
||||
data.config = response;
|
||||
|
||||
ui.configLabel.innerHTML = "Port " + data.config.port;
|
||||
if (!parseInt(data.params.nbnid))
|
||||
ui.port.value = data.config.port;
|
||||
};
|
||||
|
||||
// Callback for linodes API call
|
||||
var displayLinodes = function(response)
|
||||
{
|
||||
data.linodes = data.linodes.concat(response.data);
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, data.linodeFilters);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add linodes to address selector
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
var ipIndex = -1;
|
||||
for (var j = 0; j < data.linodes[i].ipv4.length; j++) {
|
||||
if (data.linodes[i].ipv4[j].indexOf("192.168.") == 0) {
|
||||
ipIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ipIndex == -1)
|
||||
continue;
|
||||
|
||||
var option = document.createElement("option");
|
||||
option.value = data.linodes[i].ipv4[j];
|
||||
option.innerHTML = data.linodes[i].ipv4[j] + " (" + data.linodes[i].label + ")";
|
||||
ui.address.appendChild(option);
|
||||
}
|
||||
|
||||
if (parseInt(data.params.nbnid))
|
||||
apiGet("/nodebalancers/" + data.params.nbid + "/configs/" + data.params.nbcid + "/nodes/" + data.params.nbnid, displayNode, null);
|
||||
else
|
||||
ui.saveButton.disabled = false;
|
||||
};
|
||||
|
||||
// Callback for nodebalancer API call
|
||||
var displayNodebalancer = function(response)
|
||||
{
|
||||
data.nodebalancer = response;
|
||||
|
||||
// Set page title and header stuff
|
||||
if (document.title.indexOf("//") == -1)
|
||||
document.title += " // Edit " + data.nodebalancer.label;
|
||||
ui.nodebalancerLabel.innerHTML = data.nodebalancer.label;
|
||||
if (data.nodebalancer.tags.length == 1) {
|
||||
ui.nodebalancerTagLink.href = "/nodebalancers?tag=" + data.nodebalancer.tags[0];
|
||||
ui.nodebalancerTagLink.innerHTML = "(" + data.nodebalancer.tags[0] + ")";
|
||||
ui.nodebalancerTag.style.display = "inline";
|
||||
} else {
|
||||
ui.nodebalancerTag.style.display = "none";
|
||||
}
|
||||
|
||||
// Get linodes
|
||||
data.linodeFilters.region = data.nodebalancer.region;
|
||||
apiGet("/linode/instances", displayLinodes, data.linodeFilters);
|
||||
};
|
||||
|
||||
// Callback for node API call
|
||||
var displayNode = function(response)
|
||||
{
|
||||
data.node = response;
|
||||
|
||||
ui.label.value = data.node.label;
|
||||
var lastColon = data.node.address.lastIndexOf(":");
|
||||
ui.address.value = data.node.address.slice(0, lastColon);
|
||||
ui.port.value = data.node.address.slice(lastColon + 1);
|
||||
ui.weight.value = data.node.weight;
|
||||
ui.mode.value = data.node.mode;
|
||||
|
||||
ui.saveButton.disabled = false;
|
||||
};
|
||||
|
||||
// Save button handler
|
||||
var handleSave = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
if (ui.address.value == "0")
|
||||
return;
|
||||
|
||||
var req = {
|
||||
"label": ui.label.value,
|
||||
"address": ui.address.value + ":" + ui.port.value,
|
||||
"weight": parseInt(ui.weight.value),
|
||||
"mode": ui.mode.value
|
||||
};
|
||||
|
||||
if (data.params.nbnid == 0) {
|
||||
apiPost("/nodebalancers/" + data.params.nbid + "/configs/" + data.params.nbcid + "/nodes", req, function(response)
|
||||
{
|
||||
location.href = "/nodebalancers/config?nbid=" + data.params.nbid + "&nbcid=" + data.params.nbcid;
|
||||
});
|
||||
} else {
|
||||
apiPut("/nodebalancers/" + data.params.nbid + "/configs/" + data.params.nbcid + "/nodes/" + data.params.nbnid, req, function(response)
|
||||
{
|
||||
location.href = "/nodebalancers/config?nbid=" + data.params.nbid + "&nbcid=" + data.params.nbcid;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a NodeBalancer ID, so die if we don't have it
|
||||
if (!data.params.nbid) {
|
||||
alert("No NodeBalancer ID supplied!");
|
||||
return;
|
||||
}
|
||||
|
||||
// We also need a config ID
|
||||
if (!data.params.nbcid) {
|
||||
alert("No config ID supplied!");
|
||||
return;
|
||||
}
|
||||
|
||||
// We also need a node ID
|
||||
if (!data.params.nbnid) {
|
||||
alert("No node ID supplied!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Update links on page to include proper Linode ID
|
||||
var anchors = document.getElementsByTagName("a");
|
||||
for (var i = 0; i < anchors.length; i++) {
|
||||
anchors[i].href = anchors[i].href.replace("nbid=0", "nbid=" + data.params.nbid);
|
||||
anchors[i].href = anchors[i].href.replace("nbcid=0", "nbcid=" + data.params.nbcid);
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.address = document.getElementById(elements.address);
|
||||
ui.configLabel = document.getElementById(elements.configLabel);
|
||||
ui.label = document.getElementById(elements.label);
|
||||
ui.mode = document.getElementById(elements.mode);
|
||||
ui.nodebalancerLabel = document.getElementById(elements.nodebalancerLabel);
|
||||
ui.nodebalancerTag = document.getElementById(elements.nodebalancerTag);
|
||||
ui.nodebalancerTagLink = document.getElementById(elements.nodebalancerTagLink);
|
||||
ui.port = document.getElementById(elements.port);
|
||||
ui.saveButton = document.getElementById(elements.saveButton);
|
||||
ui.weight = document.getElementById(elements.weight);
|
||||
|
||||
// Register event handlers
|
||||
ui.saveButton.addEventListener("click", handleSave);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/nodebalancers/" + data.params.nbid, displayNodebalancer, null);
|
||||
apiGet("/nodebalancers/" + data.params.nbid + "/configs/" + data.params.nbcid, displayConfig, null);
|
||||
};
|
||||
|
||||
// Show/hide check rows
|
||||
var showHideChecks = function(event)
|
||||
{
|
||||
for (var i = 0; i < ui.checkShow.length; i++) {
|
||||
if (ui.checkShow[i].classList.contains(elements.checkShow + "-" + ui.checkType.value))
|
||||
ui.checkShow[i].style.display = "table-row";
|
||||
else
|
||||
ui.checkShow[i].style.display = "none";
|
||||
}
|
||||
};
|
||||
|
||||
// Show/hide protocol stuff
|
||||
var showHideProtocol = function(event)
|
||||
{
|
||||
for (var i = 0; i < ui.protocolShow.length; i++) {
|
||||
if (ui.protocolShow[i].classList.contains(elements.protocolShow + "-" + ui.protocol.value)) {
|
||||
if (ui.protocolShow[i].classList.contains(elements.replaceCert)) {
|
||||
if (ui.protocolShow[i].classList.contains(elements.replaceCertOnly) == state.replaceCert)
|
||||
ui.protocolShow[i].style.display = "table-row";
|
||||
else
|
||||
ui.protocolShow[i].style.display = "none";
|
||||
} else {
|
||||
ui.protocolShow[i].style.display = "table-row";
|
||||
}
|
||||
} else {
|
||||
ui.protocolShow[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
Reference in New Issue
Block a user