luci-app-lxc: fix "plain-vanilla" integration
I've tried to get the lxc app in a more usable state. Tested with mips and amd64 targets. * fix missing tar/xz dependency, only if LXC_BUSYBOX_OPTIONS is not selected * mute needless gpg validation warning * tidy up controller a little bit * fix multiple possible dispatcher errors * fix compatibility with XHTML standard theme (looks still horrible ;-) * inform the user about custom kernel prerequisites * inform the user about the template download * inform the user if no template was found Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
37a4a1c070
commit
fa4dc6be91
4 changed files with 105 additions and 51 deletions
|
@ -7,7 +7,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
LUCI_TITLE:=LXC management Web UI
|
LUCI_TITLE:=LXC management Web UI
|
||||||
LUCI_DEPENDS:=+luci-mod-admin-full +lxc +lxc-attach +lxc-console +lxc-create +liblxc +rpcd-mod-lxc +getopt
|
LUCI_DEPENDS:=+luci-mod-admin-full +lxc +lxc-attach +lxc-console +lxc-create +liblxc +rpcd-mod-lxc +getopt +!LXC_BUSYBOX_OPTIONS:tar
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
|
|
||||||
PKG_MAINTAINER:=Petar Koretic <petar.koretic@sartura.hr>
|
PKG_MAINTAINER:=Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
|
@ -14,33 +14,33 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local uci = require "luci.model.uci"
|
local uci = require "luci.model.uci".cursor()
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local nixio = require "nixio"
|
local fs = require "nixio"
|
||||||
|
|
||||||
module("luci.controller.lxc", package.seeall)
|
module("luci.controller.lxc", package.seeall)
|
||||||
|
|
||||||
function fork_exec(command)
|
function fork_exec(command)
|
||||||
local pid = nixio.fork()
|
local pid = fs.fork()
|
||||||
if pid > 0 then
|
if pid > 0 then
|
||||||
return
|
return
|
||||||
elseif pid == 0 then
|
elseif pid == 0 then
|
||||||
-- change to root dir
|
-- change to root dir
|
||||||
nixio.chdir("/")
|
fs.chdir("/")
|
||||||
|
|
||||||
-- patch stdin, out, err to /dev/null
|
-- patch stdin, out, err to /dev/null
|
||||||
local null = nixio.open("/dev/null", "w+")
|
local null = fs.open("/dev/null", "w+")
|
||||||
if null then
|
if null then
|
||||||
nixio.dup(null, nixio.stderr)
|
fs.dup(null, fs.stderr)
|
||||||
nixio.dup(null, nixio.stdout)
|
fs.dup(null, fs.stdout)
|
||||||
nixio.dup(null, nixio.stdin)
|
fs.dup(null, fs.stdin)
|
||||||
if null:fileno() > 2 then
|
if null:fileno() > 2 then
|
||||||
null:close()
|
null:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- replace with target command
|
-- replace with target command
|
||||||
nixio.exec("/bin/sh", "-c", command)
|
fs.exec("/bin/sh", "-c", command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,9 +71,8 @@ function lxc_get_downloadable()
|
||||||
local target = lxc_get_arch_target()
|
local target = lxc_get_arch_target()
|
||||||
local templates = {}
|
local templates = {}
|
||||||
|
|
||||||
local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list --no-validate --server %s'
|
local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list --no-validate --server %s 2>/dev/null'
|
||||||
% util.shellquote(uci.cursor():get("lxc", "lxc", "url")), 'r')
|
% util.shellquote(uci:get("lxc", "lxc", "url")), 'r')
|
||||||
|
|
||||||
local line
|
local line
|
||||||
for line in f:lines() do
|
for line in f:lines() do
|
||||||
local dist, version, dist_target = line:match("^(%S+)%s+(%S+)%s+(%S+)%s+default%s+%S+$")
|
local dist, version, dist_target = line:match("^(%S+)%s+(%S+)%s+(%S+)%s+default%s+%S+$")
|
||||||
|
@ -101,7 +100,7 @@ function lxc_create(lxc_name, lxc_template)
|
||||||
name = lxc_name,
|
name = lxc_name,
|
||||||
template = "download",
|
template = "download",
|
||||||
args = {
|
args = {
|
||||||
"--server", uci.cursor():get("lxc", "lxc", "url"),
|
"--server", uci:get("lxc", "lxc", "url"),
|
||||||
"--no-validate",
|
"--no-validate",
|
||||||
"--dist", lxc_dist,
|
"--dist", lxc_dist,
|
||||||
"--release", lxc_release,
|
"--release", lxc_release,
|
||||||
|
@ -121,6 +120,7 @@ function lxc_get_config_path()
|
||||||
local f = io.open("/etc/lxc/lxc.conf", "r")
|
local f = io.open("/etc/lxc/lxc.conf", "r")
|
||||||
local content = f:read("*all")
|
local content = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
local ret = content:match('^%s*lxc.lxcpath%s*=%s*([^%s]*)')
|
local ret = content:match('^%s*lxc.lxcpath%s*=%s*([^%s]*)')
|
||||||
if ret then
|
if ret then
|
||||||
return ret .. "/"
|
return ret .. "/"
|
||||||
|
@ -160,7 +160,7 @@ function lxc_configuration_set(lxc_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lxc_get_arch_target()
|
function lxc_get_arch_target()
|
||||||
local target = nixio.uname().machine
|
local target = fs.uname().machine
|
||||||
local target_map = {
|
local target_map = {
|
||||||
armv5 = "armel",
|
armv5 = "armel",
|
||||||
armv6 = "armel",
|
armv6 = "armel",
|
||||||
|
|
|
@ -16,7 +16,9 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
m = Map("lxc", translate("LXC Containers"))
|
m = Map("lxc", translate("LXC Containers"),
|
||||||
|
translate("<b>Please note:</b> For LXC Containers you need a custom OpenWrt image.<br />")
|
||||||
|
.. translate("The image should include at least support for 'kernel cgroups', 'kernel namespaces' and 'miscellaneous LXC related options'."))
|
||||||
|
|
||||||
if fs.access("/etc/config/lxc") then
|
if fs.access("/etc/config/lxc") then
|
||||||
m:section(SimpleSection).template = "lxc"
|
m:section(SimpleSection).template = "lxc"
|
||||||
|
|
|
@ -14,6 +14,32 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
local fs = require "nixio"
|
||||||
|
local target = fs.uname().machine
|
||||||
|
%>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
table.cbi-section-table th,
|
||||||
|
table.cbi-section-table td,
|
||||||
|
.cbi-section-table-cell,
|
||||||
|
.cbi-input-select,
|
||||||
|
.cbi-input-text
|
||||||
|
{
|
||||||
|
text-align:left;
|
||||||
|
vertical-align:top;
|
||||||
|
padding-left:2px;
|
||||||
|
margin-right:auto;
|
||||||
|
margin-left:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cbi-input-select,
|
||||||
|
.cbi-input-text
|
||||||
|
{
|
||||||
|
width:15em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<fieldset class="cbi-section">
|
||||||
<legend><%:Available Containers%></legend>
|
<legend><%:Available Containers%></legend>
|
||||||
<div class="cbi-section-node">
|
<div class="cbi-section-node">
|
||||||
|
@ -43,7 +69,7 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="tr_holder">
|
<tr id="tr_holder">
|
||||||
<td>
|
<td>
|
||||||
<input type="text" id="tx_name" placeholder="<%:Enter new name%>" value='' />
|
<input class="cbi-input-text" type="text" id="tx_name" placeholder="<%:Enter new name%>" value='' />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select id="s_template" class="cbi-input-select cbi-button">
|
<select id="s_template" class="cbi-input-select cbi-button">
|
||||||
|
@ -65,21 +91,23 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
|
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
|
||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">
|
||||||
|
//<![CDATA[
|
||||||
|
window.img = { "red" : "<%=resource%>/cbi/red.gif", "green" : "<%=resource%>/cbi/green.gif", "purple" : "<%=resource%>/cbi/purple.gif" }
|
||||||
|
window.states = { "STOPPED" : "red", "RUNNING" : "green", "FROZEN" : "purple" }
|
||||||
|
|
||||||
window.img = { "red" : "<%=resource%>/cbi/red.gif", "green" : "<%=resource%>/cbi/green.gif", "purple" : "<%=resource%>/cbi/purple.gif" }
|
var t_lxc_list = document.getElementById('t_lxc_list');
|
||||||
window.states = { "STOPPED" : "red", "RUNNING" : "green", "FROZEN" : "purple"}
|
var loader_html = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />';
|
||||||
|
|
||||||
var t_lxc_list = document.getElementById('t_lxc_list');
|
|
||||||
var loader_html = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" /> ';
|
|
||||||
var timeout_msg = 0
|
var timeout_msg = 0
|
||||||
var output_list = document.getElementById("lxc-list-output")
|
var output_list = document.getElementById("lxc-list-output")
|
||||||
var output_add = document.getElementById("lxc-add-output")
|
var output_add = document.getElementById("lxc-add-output")
|
||||||
var loader_add = document.getElementById("lxc-add-loader")
|
var loader_add = document.getElementById("lxc-add-loader")
|
||||||
|
|
||||||
|
info_message(output_add, "Template download in progress, please be patient!", 10000)
|
||||||
|
|
||||||
function lxc_create(tr)
|
function lxc_create(tr)
|
||||||
{
|
{
|
||||||
var lxc_name = tr.querySelector("#tx_name").value.trim()
|
var lxc_name = tr.querySelector("#tx_name").value.replace(/\s/g,'')
|
||||||
var lxc_template = tr.querySelector("#s_template").value
|
var lxc_template = tr.querySelector("#s_template").value
|
||||||
var bt_create = tr.querySelector("#bt_create")
|
var bt_create = tr.querySelector("#bt_create")
|
||||||
|
|
||||||
|
@ -92,7 +120,13 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
if (!lxc_name || !lxc_name.length)
|
if (!lxc_name || !lxc_name.length)
|
||||||
{
|
{
|
||||||
bt_create.disabled = false
|
bt_create.disabled = false
|
||||||
return info_message(output_add, "Name cannot be empty!", 4000)
|
return info_message(output_add, "The 'Name' field must not be empty!", 4000)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lxc_template)
|
||||||
|
{
|
||||||
|
bt_create.disabled = false
|
||||||
|
return info_message(output_add, "The 'Template' field must not be empty!", 4000)
|
||||||
}
|
}
|
||||||
|
|
||||||
loading(loader_add)
|
loading(loader_add)
|
||||||
|
@ -101,6 +135,7 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
function(x)
|
function(x)
|
||||||
{
|
{
|
||||||
bt_create.disabled = false
|
bt_create.disabled = false
|
||||||
|
|
||||||
loading(loader_add, 0)
|
loading(loader_add, 0)
|
||||||
|
|
||||||
if (!x)
|
if (!x)
|
||||||
|
@ -116,16 +151,16 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
var actions = ''
|
var actions = ''
|
||||||
actions += '<input type="button" onclick="action_handler(this)" data-action="start" value="<%:Start%>" class="cbi-button cbi-button-apply" />'
|
actions += '<input type="button" onclick="action_handler(this)" data-action="start" value="<%:Start%>" class="cbi-button cbi-button-apply" />'
|
||||||
actions+= '<input type="button" onclick="action_handler(this)" data-action="stop" value="<%:Stop%>" class="cbi-button cbi-button-reset" />'
|
actions += ' <input type="button" onclick="action_handler(this)" data-action="stop" value="<%:Stop%>" class="cbi-button cbi-button-reset" />'
|
||||||
actions+= '<input type="button" onclick="action_handler(this)" data-action="destroy" value="<%:Delete%>" class="cbi-button cbi-button-remove" />'
|
actions += ' <input type="button" onclick="action_handler(this)" data-action="destroy" value="<%:Delete%>" class="cbi-button cbi-button-remove" />'
|
||||||
actions+= ' <select class="cbi-input-select cbi-button" onchange="action_more_handler(this)">\
|
actions += ' <select class="cbi-input-select cbi-button" onchange="action_more_handler(this)">\
|
||||||
<option selected disabled>more</option>\
|
<option selected="selected" disabled="disabled">more</option>\
|
||||||
<option>configure</option>\
|
<option>configure</option>\
|
||||||
<option>freeze</option>\
|
<option>freeze</option>\
|
||||||
<option>unfreeze</option>\
|
<option>unfreeze</option>\
|
||||||
<option>reboot</option>\
|
<option>reboot</option>\
|
||||||
</select>'
|
</select>'
|
||||||
actions+= '<span data-loader style="display:inline-block; width:16px; height:16px; margin:0 5px"></span>'
|
actions += '<span data-loader="" style="display:inline-block; width:16px; height:16px; margin:0 5px"></span>'
|
||||||
|
|
||||||
var row = t_lxc_list.insertRow(-1)
|
var row = t_lxc_list.insertRow(-1)
|
||||||
var cell = row.insertCell(-1)
|
var cell = row.insertCell(-1)
|
||||||
|
@ -144,12 +179,11 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
function action_handler(self)
|
function action_handler(self)
|
||||||
{
|
{
|
||||||
var action = self.getAttribute("data-action");
|
var action = self.getAttribute("data-action");
|
||||||
|
var bt_action = self
|
||||||
var bt_action = self
|
var lxc_name = self.parentNode.parentNode.children[0].getAttribute('data-id')
|
||||||
var lxc_name = self.parentNode.parentNode.children[0].getAttribute('data-id')
|
|
||||||
var status_img = self.parentNode.parentNode.querySelector('img')
|
var status_img = self.parentNode.parentNode.querySelector('img')
|
||||||
var loader = self.parentNode.querySelector('[data-loader]')
|
var loader = self.parentNode.querySelector('[data-loader]')
|
||||||
|
|
||||||
bt_action.disabled = true
|
bt_action.disabled = true
|
||||||
|
|
||||||
|
@ -181,18 +215,16 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
loading(loader, 0)
|
loading(loader, 0)
|
||||||
bt_action.disabled = false
|
bt_action.disabled = false
|
||||||
|
|
||||||
//FIXME: uncomment after fixing 'lxc-start'
|
|
||||||
if (!x /*|| ec */)
|
if (!x /*|| ec */)
|
||||||
return info_message(output_list,"Action failed!")
|
return info_message(output_list,"Action failed!")
|
||||||
|
|
||||||
//FIXME: uncomment after fixing 'lxc-start'
|
set_status(status_img, "green")
|
||||||
//set_status(status_img, "green")
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (action == "destroy")
|
else if (action == "destroy")
|
||||||
{
|
{
|
||||||
if (!confirm("This will completely remove LXC container from the disk. Are you sure? (container will be stopped if running)"))
|
if (!confirm("This will completely remove a stopped LXC container from disk. Are you sure?"))
|
||||||
return
|
return
|
||||||
|
|
||||||
loading(loader)
|
loading(loader)
|
||||||
|
@ -253,13 +285,12 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
function action_more_handler(self)
|
function action_more_handler(self)
|
||||||
{
|
{
|
||||||
var lxc_name = self.parentNode.parentNode.querySelector('[data-id]').getAttribute('data-id')
|
var lxc_name = self.parentNode.parentNode.querySelector('[data-id]').getAttribute('data-id')
|
||||||
var loader = self.parentNode.parentNode.querySelector('[data-loader]')
|
var loader = self.parentNode.parentNode.querySelector('[data-loader]')
|
||||||
|
var option = self.options[self.selectedIndex].text
|
||||||
var option = self.options[self.selectedIndex].text
|
|
||||||
|
|
||||||
self.value = "more"
|
self.value = "more"
|
||||||
|
|
||||||
switch (option)
|
switch(option)
|
||||||
{
|
{
|
||||||
case "configure":
|
case "configure":
|
||||||
var tr = document.createElement('tr')
|
var tr = document.createElement('tr')
|
||||||
|
@ -352,10 +383,25 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
var row = t_lxc_list.insertRow(-1);
|
var row = t_lxc_list.insertRow(-1);
|
||||||
row.id = 'empty'
|
row.id = 'empty'
|
||||||
var cell = row.insertCell(0);
|
var cell = row.insertCell(0);
|
||||||
cell.colSpan = 4;
|
cell.colSpan = 3;
|
||||||
cell.innerHTML = '<em><br />There are no containers available yet.</em>';
|
cell.innerHTML = '<em><br />There are no containers available yet.</em>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_empty_template()
|
||||||
|
{
|
||||||
|
if (document.getElementById('tr_holder') !== null)
|
||||||
|
return
|
||||||
|
|
||||||
|
var row_count = t_lxc_create.rows.length;
|
||||||
|
while(--row_count) t_lxc_create.deleteRow(row_count);
|
||||||
|
|
||||||
|
var row = t_lxc_create.insertRow(-1);
|
||||||
|
row.id = 'tr_holder'
|
||||||
|
var cell = row.insertCell(0);
|
||||||
|
cell.colSpan = 3;
|
||||||
|
cell.innerHTML = '<em><br />There are no templates for your architecture (<%=target%>) available, please select another Containers URL.</em>';
|
||||||
|
}
|
||||||
|
|
||||||
function lxc_list_update()
|
function lxc_list_update()
|
||||||
{
|
{
|
||||||
XHR.poll(4, '<%=luci.dispatcher.build_url("admin", "services")%>/lxc_action/list', null,
|
XHR.poll(4, '<%=luci.dispatcher.build_url("admin", "services")%>/lxc_action/list', null,
|
||||||
|
@ -363,8 +409,11 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
{
|
{
|
||||||
if (!x) return;
|
if (!x) return;
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return set_empty(t_lxc_list)
|
||||||
|
|
||||||
var lxc_count = Object.keys(data).length
|
var lxc_count = Object.keys(data).length
|
||||||
if (!data || !lxc_count)
|
if (!lxc_count)
|
||||||
return set_empty(t_lxc_list)
|
return set_empty(t_lxc_list)
|
||||||
|
|
||||||
if (document.getElementById('empty') !== null)
|
if (document.getElementById('empty') !== null)
|
||||||
|
@ -443,8 +492,11 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
{
|
{
|
||||||
if (!x) return;
|
if (!x) return;
|
||||||
|
|
||||||
var lxc_count = Object.keys(data).length
|
if (!data) return set_empty_template();
|
||||||
if (!data || !lxc_count) return;
|
|
||||||
|
var lxc_count = Object.keys(data).length;
|
||||||
|
if (!lxc_count) return set_empty_template();
|
||||||
|
|
||||||
var select = document.getElementById("s_template");
|
var select = document.getElementById("s_template");
|
||||||
for(var key in data)
|
for(var key in data)
|
||||||
{
|
{
|
||||||
|
@ -454,5 +506,5 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
select.add(option, -1);
|
select.add(option, -1);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
//]]>
|
||||||
//]]></script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue