Implement NodeBalancers

This commit is contained in:
2024-08-08 19:46:58 -04:00
parent 35e9d259f5
commit 709a220e1b
22 changed files with 2585 additions and 23 deletions

72
nodebalancers/add/add.css Normal file
View File

@ -0,0 +1,72 @@
/*
* 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');
#add {
padding: 0px 15px 15px;
}
#add-button {
display: block;
font-size: 16px;
font-weight: bold;
margin: 0 auto;
padding: 5px;
}
#datacenters {
font-size: 18px;
margin-top: 10px;
}
h2 {
font-size: 18px;
margin: 0;
}
#location {
padding: 15px;
}
optgroup {
display: none;
}
#submit {
padding: 15px;
}
tbody td {
font-size: 14px;
}
tbody td:nth-of-type(2) {
color: green;
}
td {
font-weight: bold;
}
td:first-of-type {
text-align: center;
}
thead {
background: linear-gradient(#00EE00, #00BF00);
}

147
nodebalancers/add/add.js Normal file
View File

@ -0,0 +1,147 @@
/*
* 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, countryContinents, parseParams, regionNames, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.addButton = "add-button";
elements.datacenters = "datacenters";
elements.dcOther = "dc-other";
elements.hourly = "hourly";
elements.monthly = "monthly";
// Data recieved from API calls
var data = {};
data.linodes = [];
data.regions = [];
// Static references to UI elements
var ui = {};
ui.addButton = {};
ui.datacenters = {};
ui.dcOther = {};
ui.hourly = {};
ui.monthly = {};
// Callback for regions API call
var displayRegions = function(response)
{
// Add regions that support block storage to array
for (var i = 0; i < response.data.length; i++) {
if (response.data[i].capabilities.includes("NodeBalancers"))
data.regions.push(response.data[i]);
}
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/regions?page=" + (response.page + 1), displayRegions, null);
return;
}
// Add regions to selector
for (var i = 0; i < data.regions.length; i++) {
// Regional pricing
if (data.regions[i].id == "id-cgk") {
data.regions[i].hourly = "$0.018/hr";
data.regions[i].monthly = "$12.00/mo";
} else if (data.regions[i].id == "br-gru") {
data.regions[i].hourly = "$0.021/hr";
data.regions[i].monthly = "$14.00/mo";
} else {
data.regions[i].hourly = "$0.015/hr";
data.regions[i].monthly = "$10.00/mo";
}
var loc = document.createElement("option");
loc.value = data.regions[i].id;
if (data.regions[i].label && data.regions[i].label.length)
loc.innerHTML = data.regions[i].label;
else if (regionNames[data.regions[i].id])
loc.innerHTML = regionNames[data.regions[i].id];
else
loc.innerHTML = data.regions[i].id;
var optgroup = null;
if (countryContinents[data.regions[i].country])
optgroup = document.getElementById(countryContinents[data.regions[i].country]);
if (!optgroup)
optgroup = ui.dcOther;
optgroup.style.display = "initial";
optgroup.appendChild(loc);
}
ui.addButton.disabled = false;
};
// Click handler for add button
var handleAdd = function(event)
{
if (event.currentTarget.disabled)
return;
var req = {
"region": ui.datacenters.value
};
if (data.params.tag)
req.tags = [data.params.tag];
apiPost("/nodebalancers", req, function(response)
{
location.href = "/nodebalancers/balancer?nbid=" + response.id;
});
};
// Location select handler
var handleLocation = function(event)
{
// Update prices based on location
for (var i = 0; i < data.regions.length; i++) {
if (data.regions[i].id == ui.datacenters.value) {
ui.hourly.innerHTML = data.regions[i].hourly;
ui.monthly.innerHTML = data.regions[i].monthly;
break;
}
}
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.addButton = document.getElementById(elements.addButton);
ui.datacenters = document.getElementById(elements.datacenters);
ui.dcOther = document.getElementById(elements.dcOther);
ui.hourly = document.getElementById(elements.hourly);
ui.monthly = document.getElementById(elements.monthly);
// Attach event handlers
ui.addButton.addEventListener("click", handleAdd);
ui.datacenters.addEventListener("input", handleLocation);
// Get data from API
apiGet("/regions", displayRegions, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

View File

@ -0,0 +1,66 @@
<!--
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 - Add a NodeBalancer</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="add.css" />
<script src="add.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 class="top-links-title">Add a NodeBalancer</span></div>
<div id="add">
<table class="lmc-table">
<thead>
<tr>
<td></td>
<td>Plan</td>
<td>Hourly</td>
<td>Monthly</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td><input checked type="radio" name="plan" /></td>
<td>NodeBalancer</td>
<td id="hourly">$0.015/hr</td>
<td id="monthly">$10.00/mo</td>
</tr>
</tbody>
</table>
<div id="location">
<h2>Location</h2>
<select id="datacenters">
<optgroup id="na" label="North America"></optgroup>
<optgroup id="eu" label="Europe"></optgroup>
<optgroup id="ap" label="Asia/Pacific"></optgroup>
<optgroup id="sa" label="South America"></optgroup>
<optgroup id="af" label="Africa"></optgroup>
<optgroup id="dc-other" label="Other"></optgroup>
</select>
</div>
<div id="submit">
<button disabled id="add-button" type="button">Add this NodeBalancer!</button>
</div>
</div>
</div>
</body>
</html>