From da074c97666a24f213cf5987ecc400bc6a5e9dbf Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Thu, 16 Jun 2016 10:44:23 +0200 Subject: [PATCH 1/4] luci-app-lxc: Allow versioned images I makes quite some sense to provide user the choice between various versions of the distribution to install into LXC. Signed-off-by: Michal Hrusecky --- utils/luci-app-lxc/files/controller/lxc.lua | 5 ++++- utils/luci-app-lxc/files/view/lxc.htm | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/luci-app-lxc/files/controller/lxc.lua b/utils/luci-app-lxc/files/controller/lxc.lua index f3f5d07ba7..6c28d4159f 100644 --- a/utils/luci-app-lxc/files/controller/lxc.lua +++ b/utils/luci-app-lxc/files/controller/lxc.lua @@ -80,7 +80,10 @@ function lxc_create(lxc_name, lxc_template) local target = _G.DISTRIB_TARGET:match('([^/]+)') - local data = conn:call("lxc", "create", { name = lxc_name, template = "download", args = { "--server", url, "--no-validate", "--dist", lxc_template, "--release", "bb", "--arch", target } } ) + 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_dist, "--release", lxc_release, "--arch", target } } ) luci.http.write(data) end diff --git a/utils/luci-app-lxc/files/view/lxc.htm b/utils/luci-app-lxc/files/view/lxc.htm index 1376968e3b..db216fc28e 100644 --- a/utils/luci-app-lxc/files/view/lxc.htm +++ b/utils/luci-app-lxc/files/view/lxc.htm @@ -47,7 +47,7 @@ Author: Petar Koretic From 0084c9377e16fec94031f1c2ae6d05427c604e4a Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Thu, 16 Jun 2016 10:49:23 +0200 Subject: [PATCH 2/4] luci-app-lxc: Use uname -m as architecture As containers are basically virtual machines, it should not depend on the build target but on the real hardware architecture. For example there is plenty of ARM families (mvebu, sunxi, ...) but all armv7l arms should be able to run armv7l containers. Signed-off-by: Michal Hrusecky --- utils/luci-app-lxc/files/controller/lxc.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/luci-app-lxc/files/controller/lxc.lua b/utils/luci-app-lxc/files/controller/lxc.lua index 6c28d4159f..3d1b23df85 100644 --- a/utils/luci-app-lxc/files/controller/lxc.lua +++ b/utils/luci-app-lxc/files/controller/lxc.lua @@ -78,7 +78,10 @@ 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') From 449a19ff5deed75de43201866e2c206196f467e7 Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Thu, 16 Jun 2016 16:18:59 +0200 Subject: [PATCH 3/4] luci-app-lxc: Download list of available distributions There was harcoded list of available images. Instead of it, LuCI LXC app will now try to download list of available container images. Signed-off-by: Michal Hrusecky --- utils/luci-app-lxc/files/controller/lxc.lua | 24 +++++++++++++++++++++ utils/luci-app-lxc/files/view/lxc.htm | 19 +++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/utils/luci-app-lxc/files/controller/lxc.lua b/utils/luci-app-lxc/files/controller/lxc.lua index 3d1b23df85..3b7635d965 100644 --- a/utils/luci-app-lxc/files/controller/lxc.lua +++ b/utils/luci-app-lxc/files/controller/lxc.lua @@ -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") diff --git a/utils/luci-app-lxc/files/view/lxc.htm b/utils/luci-app-lxc/files/view/lxc.htm index db216fc28e..bc767f3664 100644 --- a/utils/luci-app-lxc/files/view/lxc.htm +++ b/utils/luci-app-lxc/files/view/lxc.htm @@ -47,7 +47,6 @@ Author: Petar Koretic @@ -438,4 +437,22 @@ Author: Petar Koretic } lxc_list_update() + + new XHR().get('<%=luci.dispatcher.build_url("admin", "services")%>/lxc_get_downloadable', null, + function(x, data) + { + if (!x) return; + + var lxc_count = Object.keys(data).length + if (!data || !lxc_count) return; + var select = document.getElementById("s_template"); + for(var key in data) + { + var option = document.createElement('option'); + option.value = data[key]; + option.text = data[key].replace(/[_:]/, ' '); + select.add(option, -1); + } + }) + //]]> From b6d1ef53c3eabfb36c37298a9ff7a5730fe37045 Mon Sep 17 00:00:00 2001 From: Michal Hrusecky Date: Fri, 17 Jun 2016 09:22:41 +0200 Subject: [PATCH 4/4] luci-app-lxc: Bump version Did quite some changes, so bumping version so users would get the change. Signed-off-by: Michal Hrusecky --- utils/luci-app-lxc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/luci-app-lxc/Makefile b/utils/luci-app-lxc/Makefile index f08d81e13c..210f030a11 100644 --- a/utils/luci-app-lxc/Makefile +++ b/utils/luci-app-lxc/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-lxc -PKG_RELEASE:=20141012 +PKG_RELEASE:=20160616 PKG_LICENSE:=Apache-2.0