Initial commit. Implemented OAuth, Linodes, volumes, and images
This commit is contained in:
93
linodes/resize/index.shtml
Normal file
93
linodes/resize/index.shtml
Normal file
@ -0,0 +1,93 @@
|
||||
<!--
|
||||
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 - Resize</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="resize.css" />
|
||||
<script src="resize.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<!--#include virtual="/include/linode_subnav.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="top-links"><a href="/linodes">Linodes</a> » <span id="linode-tag"><a id="linode-tag-link" href=""></a> » </span><a id="linode-label" href="/linodes/dashboard?lid=0"></a> » <span class="top-links-title">Resize</span></div>
|
||||
<div id="resize">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Resize</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="lmc-tr1">
|
||||
<td colspan="3"><h2>Choose your new plan</h2></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr1">
|
||||
<td>
|
||||
<h3>Nanode</h3>
|
||||
<div id="nanode"></div>
|
||||
<br />
|
||||
<h3>Standard</h3>
|
||||
<div id="standard"></div>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<h3>Dedicated CPU</h3>
|
||||
<div id="dedicated"></div>
|
||||
<br />
|
||||
<h3>High Memory</h3>
|
||||
<div id="highmem"></div>
|
||||
<br />
|
||||
<h3>Dedicated GPU</h3>
|
||||
<div id="gpu"></div>
|
||||
</td>
|
||||
<td>
|
||||
<h2>How it works</h2>
|
||||
<ol>
|
||||
<li>
|
||||
<strong>Linode is shut down and migrated</strong><br />
|
||||
You will experience downtime while your Linode is migrated. It will take about <span id="eta"></span> to migrate your Linode, but that may vary based on host and network load.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Billing</strong><br />
|
||||
The resized Linode will be billed at the hourly rate of the new Linode plan going forward.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Enjoyment</strong><br />
|
||||
After the migration completes, you can take advantage of the new resources by resizing your disks.
|
||||
</li>
|
||||
</ol>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr1">
|
||||
<td colspan="3">
|
||||
<div id="auto-resize">
|
||||
<input disabled id="auto-resize-box" type="checkbox" />
|
||||
<label for="auto-resize-box">Automatically resize disk "<span id="disk-name"></span>"</label>
|
||||
</div>
|
||||
<button disabled id="resize-button" type="button">Resize this Linode Now!</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
64
linodes/resize/resize.css
Normal file
64
linodes/resize/resize.css
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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');
|
||||
|
||||
#auto-resize {
|
||||
display: none;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.current {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
div {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#eta {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.lmc-table td {
|
||||
vertical-align: top;
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.lmc-table td:last-child {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
ol {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#resize {
|
||||
padding: 0px 15px 15px;
|
||||
}
|
250
linodes/resize/resize.js
Normal file
250
linodes/resize/resize.js
Normal file
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* 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, migrateETA, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.autoResize = "auto-resize";
|
||||
elements.autoResizeBox = "auto-resize-box";
|
||||
elements.current = "current";
|
||||
elements.dedicated = "dedicated";
|
||||
elements.diskName = "disk-name";
|
||||
elements.eta = "eta";
|
||||
elements.gpu = "gpu";
|
||||
elements.instanceType = "instance-type";
|
||||
elements.highmem = "highmem";
|
||||
elements.linodeLabel = "linode-label";
|
||||
elements.linodeTag = "linode-tag";
|
||||
elements.linodeTagLink = "linode-tag-link";
|
||||
elements.nanode = "nanode";
|
||||
elements.resizeButton = "resize-button";
|
||||
elements.standard = "standard";
|
||||
|
||||
// Data received from API calls
|
||||
var data = {};
|
||||
data.disks = [];
|
||||
data.linode = {};
|
||||
data.types = [];
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.autoResize = {};
|
||||
ui.autoResizeBox = {};
|
||||
ui.dedicated = {};
|
||||
ui.diskName = {};
|
||||
ui.eta = {};
|
||||
ui.gpu = {};
|
||||
ui.highmem = {};
|
||||
ui.linodeLabel = {};
|
||||
ui.linodeTag = {};
|
||||
ui.linodeTagLink = {};
|
||||
ui.nanode = {};
|
||||
ui.resizeButton = {};
|
||||
ui.standard = {};
|
||||
|
||||
// Creates a Linode type radio button and label
|
||||
var createTypeButton = function(type)
|
||||
{
|
||||
// Radio button
|
||||
var radio = document.createElement("input");
|
||||
radio.id = type.id;
|
||||
radio.type = "radio";
|
||||
radio["name"] = elements.instanceType;
|
||||
radio.value = type.id;
|
||||
|
||||
// Label
|
||||
var label = document.createElement("label");
|
||||
label.htmlFor = type.id;
|
||||
label.innerHTML = type.label;
|
||||
|
||||
// Text to display next to current plan
|
||||
var current = document.createElement("span");
|
||||
current.innerHTML = " (current plan)";
|
||||
|
||||
var br = document.createElement("br");
|
||||
|
||||
// Insert elements
|
||||
ui[type["class"]].appendChild(radio);
|
||||
ui[type["class"]].appendChild(label);
|
||||
|
||||
if (type.id == data.linode.type) {
|
||||
radio.disabled = true;
|
||||
label.className = elements.current;
|
||||
ui[type["class"]].appendChild(current);
|
||||
}
|
||||
|
||||
ui[type["class"]].appendChild(br);
|
||||
};
|
||||
|
||||
// Callback for linode details API call
|
||||
var displayDetails = function(response)
|
||||
{
|
||||
data.linode = response;
|
||||
|
||||
// Set page title and header stuff
|
||||
document.title += " // " + data.linode.label;
|
||||
ui.linodeLabel.innerHTML = data.linode.label;
|
||||
if (data.linode.tags.length == 1) {
|
||||
ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0];
|
||||
ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")";
|
||||
ui.linodeTag.style.display = "inline";
|
||||
} else {
|
||||
ui.linodeTag.style.display = "none";
|
||||
}
|
||||
|
||||
// Get linode types
|
||||
apiGet("/linode/types", displayTypes, null);
|
||||
};
|
||||
|
||||
// Callback for linode disks API call
|
||||
var displayDisks = function(response)
|
||||
{
|
||||
// Add disks to array
|
||||
data.disks = data.disks.concat(response.data);
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute total size and types of disks
|
||||
var size = 0;
|
||||
var numExt = 0;
|
||||
var numSwap = 0;
|
||||
for (var i = 0; i < data.disks.length; i++) {
|
||||
size += data.disks[i].size;
|
||||
if (data.disks[i].filesystem.match(/ext3|ext4/)) {
|
||||
numExt++;
|
||||
ui.diskName.innerHTML = data.disks[i].label;
|
||||
}
|
||||
else if (data.disks[i].filesystem == "swap")
|
||||
numSwap++;
|
||||
}
|
||||
|
||||
// Compute estimated resize time
|
||||
ui.eta.innerHTML = migrateETA(size, true);
|
||||
|
||||
// Show auto-resize option if there is only a single ext disk
|
||||
if ((data.disks.length == 1 && numExt == 1) || (data.disks.length == 2 && numExt == 1 && numSwap == 1)) {
|
||||
ui.autoResizeBox.disabled = false;
|
||||
ui.autoResizeBox.checked = true;
|
||||
ui.autoResize.style.display = "block";
|
||||
}
|
||||
};
|
||||
|
||||
// Callback for linode types API call
|
||||
var displayTypes = function(response)
|
||||
{
|
||||
// Add types to array
|
||||
data.types = data.types.concat(response.data);
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert types
|
||||
for (var i = 0; i < data.types.length; i++)
|
||||
createTypeButton(data.types[i]);
|
||||
|
||||
ui.resizeButton.disabled = false;
|
||||
};
|
||||
|
||||
// Resize button handler
|
||||
var handleResize = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
// Find the selected type
|
||||
var type = null;
|
||||
var inputs = document.getElementsByTagName("input");
|
||||
for (var i = 0; i < inputs.length; i++) {
|
||||
if (inputs[i]["name"] == elements.instanceType && inputs[i].checked) {
|
||||
type = inputs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!type) {
|
||||
alert("You must choose a new plan.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm("Immediately shut down, migrate your Linode, and invoice this account for the difference?"))
|
||||
return;
|
||||
|
||||
var request = {
|
||||
"type": type.id,
|
||||
"allow_auto_disk_resize": (!ui.autoResizeBox.disabled && ui.autoResizeBox.checked)
|
||||
};
|
||||
apiPost("/linode/instances/" + data.params.lid + "/resize", request, function(response)
|
||||
{
|
||||
location.href = "/linodes/dashboard?lid=" + data.params.lid;
|
||||
});
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a Linode ID, so die if we don't have it
|
||||
if (!data.params.lid) {
|
||||
alert("No Linode 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("lid=0", "lid=" + data.params.lid);
|
||||
|
||||
// Get element references
|
||||
ui.autoResize = document.getElementById(elements.autoResize);
|
||||
ui.autoResizeBox = document.getElementById(elements.autoResizeBox);
|
||||
ui.dedicated = document.getElementById(elements.dedicated);
|
||||
ui.diskName = document.getElementById(elements.diskName);
|
||||
ui.eta = document.getElementById(elements.eta);
|
||||
ui.gpu = document.getElementById(elements.gpu);
|
||||
ui.highmem = document.getElementById(elements.highmem);
|
||||
ui.linodeLabel = document.getElementById(elements.linodeLabel);
|
||||
ui.linodeTag = document.getElementById(elements.linodeTag);
|
||||
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
|
||||
ui.nanode = document.getElementById(elements.nanode);
|
||||
ui.resizeButton = document.getElementById(elements.resizeButton);
|
||||
ui.standard = document.getElementById(elements.standard);
|
||||
|
||||
// Register resize button handler
|
||||
ui.resizeButton.addEventListener("click", handleResize);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
|
||||
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
Reference in New Issue
Block a user