Merge pull request #1924 from dibdot/lxc_fix

luci-app-lxc: add backingstore support
This commit is contained in:
Dirk Brenken 2018-07-01 21:27:36 +02:00 committed by GitHub
commit 2e2dab3e56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +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") local url = util.shellquote(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
@ -44,7 +44,7 @@ function lxc_get_downloadable()
local templates = {} 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(url) }, 'r') %{ ssl_status, 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+$")
@ -60,30 +60,21 @@ end
function lxc_create(lxc_name, lxc_template) function lxc_create(lxc_name, lxc_template)
luci.http.prepare_content("text/plain") luci.http.prepare_content("text/plain")
local path = lxc_get_config_path() local path = lxc_get_config_path()
if not path then if not path then
return return
end end
local src_err
local ssl_status = lxc_get_ssl_status() 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.sys.call('/usr/bin/lxc-create --quiet --name %s --bdev best --template download -- --dist %s --release %s --arch %s --server %s %s'
name = lxc_name, %{ lxc_name, lxc_dist, lxc_release, lxc_get_arch_target(url), url, ssl_status })
template = "download",
args = {
"--server", url,
"--dist", lxc_dist,
"--release", lxc_release,
"--arch", lxc_get_arch_target(url),
ssl_status
}
}), src_err)
while (nx.fs.access(path .. lxc_name .. "/partial")) do while (nx.fs.access(path .. lxc_name .. "/partial")) do
nx.nanosleep(1) nx.nanosleep(1)
end end
luci.http.write("0")
end end
function lxc_action(lxc_action, lxc_name) function lxc_action(lxc_action, lxc_name)