Merge pull request #1920 from dibdot/lxc_fix
luci-app-lxc: small fixes & cosmetics
This commit is contained in:
commit
1fd3a16635
3 changed files with 32 additions and 30 deletions
|
@ -19,6 +19,7 @@ module("luci.controller.lxc", package.seeall)
|
||||||
local uci = require "luci.model.uci".cursor()
|
local uci = require "luci.model.uci".cursor()
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local nx = require "nixio"
|
local nx = require "nixio"
|
||||||
|
local url = uci:get("lxc", "lxc", "url")
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
if not nixio.fs.access("/etc/config/lxc") then
|
if not nixio.fs.access("/etc/config/lxc") then
|
||||||
|
@ -38,12 +39,12 @@ function index()
|
||||||
end
|
end
|
||||||
|
|
||||||
function lxc_get_downloadable()
|
function lxc_get_downloadable()
|
||||||
local target = lxc_get_arch_target()
|
local target = lxc_get_arch_target(url)
|
||||||
local templates = {}
|
|
||||||
local ssl_status = lxc_get_ssl_status()
|
local ssl_status = lxc_get_ssl_status()
|
||||||
|
local templates = {}
|
||||||
|
|
||||||
local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list %s --server %s 2>/dev/null'
|
local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list %s --server %s 2>/dev/null'
|
||||||
%{ ssl_status, util.shellquote(uci:get("lxc", "lxc", "url")) }, 'r')
|
%{ ssl_status, util.shellquote(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+$")
|
||||||
|
@ -65,18 +66,17 @@ function lxc_create(lxc_name, lxc_template)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ssl_status = lxc_get_ssl_status()
|
|
||||||
|
|
||||||
local src_err
|
local src_err
|
||||||
|
local ssl_status = lxc_get_ssl_status()
|
||||||
local lxc_dist, lxc_release = lxc_template:match("^(.+):(.+)$")
|
local lxc_dist, lxc_release = lxc_template:match("^(.+):(.+)$")
|
||||||
luci.http.write(util.ubus("lxc", "create", {
|
luci.http.write(util.ubus("lxc", "create", {
|
||||||
name = lxc_name,
|
name = lxc_name,
|
||||||
template = "download",
|
template = "download",
|
||||||
args = {
|
args = {
|
||||||
"--server", uci:get("lxc", "lxc", "url"),
|
"--server", url,
|
||||||
"--dist", lxc_dist,
|
"--dist", lxc_dist,
|
||||||
"--release", lxc_release,
|
"--release", lxc_release,
|
||||||
"--arch", lxc_get_arch_target(),
|
"--arch", lxc_get_arch_target(url),
|
||||||
ssl_status
|
ssl_status
|
||||||
}
|
}
|
||||||
}), src_err)
|
}), src_err)
|
||||||
|
@ -153,19 +153,21 @@ function lxc_configuration_set(lxc_name)
|
||||||
luci.http.write("0")
|
luci.http.write("0")
|
||||||
end
|
end
|
||||||
|
|
||||||
function lxc_get_arch_target()
|
function lxc_get_arch_target(url)
|
||||||
local target = nx.uname().machine
|
local target = nx.uname().machine
|
||||||
local target_map = {
|
if url and url:match("images.linuxcontainers.org") then
|
||||||
armv5 = "armel",
|
local target_map = {
|
||||||
armv6 = "armel",
|
armv5 = "armel",
|
||||||
armv7 = "armhf",
|
armv6 = "armel",
|
||||||
armv8 = "arm64",
|
armv7 = "armhf",
|
||||||
x86_64 = "amd64"
|
armv8 = "arm64",
|
||||||
}
|
x86_64 = "amd64"
|
||||||
local k, v
|
}
|
||||||
for k, v in pairs(target_map) do
|
local k, v
|
||||||
if target:find("^" ..k.. "$") then
|
for k, v in pairs(target_map) do
|
||||||
return v
|
if target:find(k) then
|
||||||
|
return v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return target
|
return target
|
||||||
|
|
|
@ -16,7 +16,7 @@ Author: Petar Koretic <petar.koretic@sartura.hr>
|
||||||
|
|
||||||
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("<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'."))
|
.. translate("The image should include at least support for 'kernel cgroups', 'kernel namespaces' and 'miscellaneous LXC related options' plus 'kmod-veth' for optional network support."))
|
||||||
m:section(SimpleSection).template = "lxc"
|
m:section(SimpleSection).template = "lxc"
|
||||||
|
|
||||||
s = m:section(TypedSection, "lxc", translate("Options"))
|
s = m:section(TypedSection, "lxc", translate("Options"))
|
||||||
|
|
|
@ -19,8 +19,8 @@ local nx = require "nixio"
|
||||||
local target = nx.uname().machine
|
local target = nx.uname().machine
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<div class="cbi-section">
|
||||||
<legend><%:Available Containers%></legend>
|
<h3><%:Available Containers%></h3>
|
||||||
<div class="cbi-section-node">
|
<div class="cbi-section-node">
|
||||||
<div class="table cbi-section-table" id="t_lxc_list">
|
<div class="table cbi-section-table" id="t_lxc_list">
|
||||||
<div class="tr cbi-section-table-titles">
|
<div class="tr cbi-section-table-titles">
|
||||||
|
@ -30,15 +30,15 @@ local target = nx.uname().machine
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<div class="cbi-section">
|
||||||
<span id="lxc-list-output"></span>
|
<span id="lxc-list-output"></span>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
<fieldset class="cbi-section">
|
<div class="cbi-section">
|
||||||
<legend><%:Create New Container%></legend>
|
<h3><%:Create New Container%></h3>
|
||||||
<div class="cbi-section-node">
|
<div class="cbi-section-node">
|
||||||
<div class="table cbi-section-table" id="t_lxc_create">
|
<div class="table cbi-section-table" id="t_lxc_create">
|
||||||
<div class="tr cbi-section-table-titles">
|
<div class="tr cbi-section-table-titles">
|
||||||
|
@ -56,11 +56,11 @@ local target = nx.uname().machine
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<div class="cbi-section">
|
||||||
<span id="lxc-add-output"></span>
|
<span id="lxc-add-output"></span>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue