Initial commit. Implemented OAuth, Linodes, volumes, and images
This commit is contained in:
35
linodes/deploy/deploy.css
Normal file
35
linodes/deploy/deploy.css
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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');
|
||||
|
||||
#deploy {
|
||||
padding: 0px 15px 15px;
|
||||
}
|
||||
|
||||
#size {
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
tbody tr:last-of-type {
|
||||
border: none;
|
||||
}
|
||||
|
||||
tbody tr td:first-of-type {
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
243
linodes/deploy/deploy.js
Normal file
243
linodes/deploy/deploy.js
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.currentDistros = "current";
|
||||
elements.customImages = "custom";
|
||||
elements.deletedDisks = "deleted";
|
||||
elements.deployButton = "deploy-button";
|
||||
elements.deprecatedDistros = "deprecated";
|
||||
elements.image = "image";
|
||||
elements.linodeLabel = "linode-label";
|
||||
elements.linodeTag = "linode-tag";
|
||||
elements.linodeTagLink = "linode-tag-link";
|
||||
elements.maxSize = "max";
|
||||
elements.minSize = "min";
|
||||
elements.rootPass = "root-pass";
|
||||
elements.size = "size";
|
||||
elements.subnav = "subnav-link";
|
||||
elements.subnavActive = "subnav-link-active";
|
||||
|
||||
// Data recieved from API calls
|
||||
var data = {};
|
||||
data.disks = [];
|
||||
data.images = [];
|
||||
data.linode = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.currentDistros = {};
|
||||
ui.customImages = {};
|
||||
ui.deletedDisks = {};
|
||||
ui.deployButton = {};
|
||||
ui.deprecatedDistros = {};
|
||||
ui.image = {};
|
||||
ui.linodeLabel = {};
|
||||
ui.linodeTag = {};
|
||||
ui.linodeTagLink = {};
|
||||
ui.rootPass = {};
|
||||
ui.maxSize = {};
|
||||
ui.minSize = {};
|
||||
ui.size = {};
|
||||
|
||||
// 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";
|
||||
}
|
||||
|
||||
// Get linode's disks
|
||||
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
|
||||
};
|
||||
|
||||
// Callback for 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;
|
||||
}
|
||||
|
||||
// Display max size
|
||||
var free = data.linode.specs.disk;
|
||||
for (var i = 0; i < data.disks.length; i++)
|
||||
free -= data.disks[i].size;
|
||||
|
||||
ui.maxSize.innerHTML = free;
|
||||
ui.size.max = free;
|
||||
ui.size.value = free;
|
||||
};
|
||||
|
||||
// Callback for images API call
|
||||
var displayImages = function(response)
|
||||
{
|
||||
// Add images to array
|
||||
data.images = data.images.concat(response.data);
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/images?page=" + (response.page + 1), displayImages, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add images to selector
|
||||
for (var i = 0; i < data.images.length; i++) {
|
||||
var image = document.createElement("option");
|
||||
image.value = data.images[i].id;
|
||||
image.innerHTML = data.images[i].label;
|
||||
if (data.images[i].deprecated)
|
||||
ui.deprecatedDistros.appendChild(image);
|
||||
else if (data.images[i].type == "automatic")
|
||||
ui.deletedDisks.appendChild(image);
|
||||
else if (!data.images[i].vendor)
|
||||
ui.customImages.appendChild(image);
|
||||
else
|
||||
ui.currentDistros.appendChild(image);
|
||||
|
||||
if (data.images[i].id == settings.preferredDistro) {
|
||||
ui.image.value = data.images[i].id;
|
||||
ui.minSize.innerHTML = data.images[i].size;
|
||||
ui.size.min = data.images[i].size;
|
||||
}
|
||||
}
|
||||
|
||||
if (ui.customImages.childNodes.length == 0)
|
||||
ui.customImages.style.display = "none";
|
||||
if (ui.deletedDisks.childNodes.length == 0)
|
||||
ui.deletedDisks.style.display = "none";
|
||||
ui.deployButton.disabled = false;
|
||||
};
|
||||
|
||||
// Handler for deploy button
|
||||
var handleDeploy = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
var image = null;
|
||||
for (var i = 0; i < data.images.length; i++) {
|
||||
if (data.images[i].id == ui.image.value) {
|
||||
image = data.images[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
var req = {
|
||||
"label": image.label,
|
||||
"size": parseInt(ui.size.value),
|
||||
"image": ui.image.value,
|
||||
"root_pass": ui.rootPass.value
|
||||
};
|
||||
if (image.id.startsWith("linode/"))
|
||||
req.label += " Disk";
|
||||
|
||||
apiPost("/linode/instances/" + data.params.lid + "/disks", req, 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);
|
||||
|
||||
// Highlight the dashboard subnav link
|
||||
var subnavLinks = document.getElementsByClassName(elements.subnav);
|
||||
for (var i = 0; i < subnavLinks.length; i++) {
|
||||
if (subnavLinks[i].pathname == "/linodes/dashboard")
|
||||
subnavLinks[i].className += " " + elements.subnavActive;
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.currentDistros = document.getElementById(elements.currentDistros);
|
||||
ui.customImages = document.getElementById(elements.customImages);
|
||||
ui.deletedDisks = document.getElementById(elements.deletedDisks);
|
||||
ui.deployButton = document.getElementById(elements.deployButton);
|
||||
ui.deprecatedDistros = document.getElementById(elements.deprecatedDistros);
|
||||
ui.image = document.getElementById(elements.image);
|
||||
ui.linodeLabel = document.getElementById(elements.linodeLabel);
|
||||
ui.linodeTag = document.getElementById(elements.linodeTag);
|
||||
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
|
||||
ui.maxSize = document.getElementById(elements.maxSize);
|
||||
ui.minSize = document.getElementById(elements.minSize);
|
||||
ui.rootPass = document.getElementById(elements.rootPass);
|
||||
ui.size = document.getElementById(elements.size);
|
||||
|
||||
// Register event handlers
|
||||
ui.deployButton.addEventListener("click", handleDeploy);
|
||||
ui.image.addEventListener("input", updateMinSize);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
|
||||
apiGet("/images", displayImages, null);
|
||||
};
|
||||
|
||||
// Update the mininum image size display
|
||||
var updateMinSize = function()
|
||||
{
|
||||
var image = null;
|
||||
for (var i = 0; i < data.images.length; i++) {
|
||||
if (data.images[i].id == ui.image.value) {
|
||||
image = data.images[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
ui.minSize.innerHTML = image.size;
|
||||
ui.size.min = image.size;
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
77
linodes/deploy/index.shtml
Normal file
77
linodes/deploy/index.shtml
Normal file
@ -0,0 +1,77 @@
|
||||
<!--
|
||||
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 - Deploy</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="deploy.css" />
|
||||
<script src="deploy.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">Deploy</span></div>
|
||||
<div id="deploy">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Deploy an Image</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Image</td>
|
||||
<td>
|
||||
<select id="image">
|
||||
<optgroup id="current" label="64 bit Distributions - Recommended"></optgroup>
|
||||
<optgroup id="deprecated" label="Older Distributions"></optgroup>
|
||||
<optgroup id="custom" label="Images"></optgroup>
|
||||
<optgroup id="deleted" label="Recently Deleted Disks"></optgroup>
|
||||
</select>
|
||||
</td>
|
||||
<td><span class="info">See also: <a href="/linodes/deploy_stackscript?lid=0">Deploying using StackScripts</a></span></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Deployment Disk Size</td>
|
||||
<td>
|
||||
<input id="size" type="number" /> MB<br />
|
||||
<span class="info"><span id="min"></span> MB min <span id="max"></span> MB max</span>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Swap Disk</td>
|
||||
<td>A swap disk must be created separately.</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Root Password</td>
|
||||
<td colspan="2"><input id="root-pass" type="password" /></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td></td>
|
||||
<td colspan="2"><button disabled id="deploy-button" type="button">Deploy</button>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user