|
|
@ -59,6 +59,9 @@ function index() |
|
|
|
page = entry({"admin", "services", "lxc_action"}, call("lxc_action"), nil) |
|
|
|
page.leaf = true |
|
|
|
|
|
|
|
page = entry({"admin", "services", "lxc_get_downloadable"}, call("lxc_get_downloadable"), nil) |
|
|
|
page.leaf = true |
|
|
|
|
|
|
|
page = entry({"admin", "services", "lxc_configuration_get"}, call("lxc_configuration_get"), nil) |
|
|
|
page.leaf = true |
|
|
|
|
|
|
@ -67,6 +70,27 @@ function index() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
function lxc_get_downloadable() |
|
|
|
luci.http.prepare_content("application/json") |
|
|
|
|
|
|
|
local f = io.popen('uname -m', 'r') |
|
|
|
local target = f:read('*a') |
|
|
|
f:close() |
|
|
|
target = target:gsub("^%s*(.-)%s*$", "%1") |
|
|
|
|
|
|
|
local templates = {} |
|
|
|
|
|
|
|
local f = io.popen('lxc-create -n just_want_to_list_available_lxc_templates -t download -- --list', 'r') |
|
|
|
|
|
|
|
for line in f:lines() do |
|
|
|
local dist,version = line:match("^(%S+)%s+(%S+)%s+" .. target .. "%s+default%s+%S+$") |
|
|
|
if dist~=nil and version~=nil then templates[#templates + 1] = dist .. ":" .. version end |
|
|
|
end |
|
|
|
|
|
|
|
f:close() |
|
|
|
luci.http.write_json(templates) |
|
|
|
end |
|
|
|
|
|
|
|
function lxc_create(lxc_name, lxc_template) |
|
|
|
luci.http.prepare_content("text/plain") |
|
|
|
|
|
|
@ -78,9 +102,15 @@ function lxc_create(lxc_name, lxc_template) |
|
|
|
return luci.http.write("1") |
|
|
|
end |
|
|
|
|
|
|
|
local target = _G.DISTRIB_TARGET:match('([^/]+)') |
|
|
|
local f = io.popen('uname -m', 'r') |
|
|
|
local target = f:read('*a') |
|
|
|
f:close() |
|
|
|
target = target:gsub("^%s*(.-)%s*$", "%1") |
|
|
|
|
|
|
|
local lxc_dist = lxc_template:gsub("(.*):(.*)", '%1') |
|
|
|
local lxc_release = lxc_template:gsub("(.*):(.*)", '%2') |
|
|
|
|
|
|
|
local data = conn:call("lxc", "create", { name = lxc_name, template = "download", args = { "--server", url, "--no-validate", "--dist", lxc_template, "--release", "bb", "--arch", target } } ) |
|
|
|
local data = conn:call("lxc", "create", { name = lxc_name, template = "download", args = { "--server", url, "--no-validate", "--dist", lxc_dist, "--release", lxc_release, "--arch", target } } ) |
|
|
|
|
|
|
|
luci.http.write(data) |
|
|
|
end |
|
|
|