luci-app-dockerman: refactoring remote endpoint options
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
18c2fef8b3
commit
dff11ad240
4 changed files with 52 additions and 31 deletions
|
@ -14,18 +14,18 @@ function index()
|
||||||
|
|
||||||
entry({"admin", "docker", "overview"},cbi("dockerman/overview"),_("Overview"),0).leaf=true
|
entry({"admin", "docker", "overview"},cbi("dockerman/overview"),_("Overview"),0).leaf=true
|
||||||
|
|
||||||
local remote = luci.model.uci.cursor():get("dockerd", "globals", "remote_endpoint")
|
local remote = luci.model.uci.cursor():get_bool("dockerd", "globals", "remote_endpoint")
|
||||||
if remote == nil then
|
if remote then
|
||||||
local socket = luci.model.uci.cursor():get("dockerd", "globals", "socket_path")
|
|
||||||
if socket and not nixio.fs.access(socket) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
elseif remote == "true" then
|
|
||||||
local host = luci.model.uci.cursor():get("dockerd", "globals", "remote_host")
|
local host = luci.model.uci.cursor():get("dockerd", "globals", "remote_host")
|
||||||
local port = luci.model.uci.cursor():get("dockerd", "globals", "remote_port")
|
local port = luci.model.uci.cursor():get("dockerd", "globals", "remote_port")
|
||||||
if not host or not port then
|
if not host or not port then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local socket = luci.model.uci.cursor():get("dockerd", "globals", "socket_path")
|
||||||
|
if socket and not nixio.fs.access(socket) then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (require "luci.model.docker").new():_ping().code ~= 200 then
|
if (require "luci.model.docker").new():_ping().code ~= 200 then
|
||||||
|
|
|
@ -705,10 +705,18 @@ elseif action == "console" then
|
||||||
luci.util.exec(kill_ttyd)
|
luci.util.exec(kill_ttyd)
|
||||||
local hosts
|
local hosts
|
||||||
local uci = (require "luci.model.uci").cursor()
|
local uci = (require "luci.model.uci").cursor()
|
||||||
local remote = uci:get("dockerd", "globals", "remote_endpoint")
|
local remote = uci:get_bool("dockerd", "globals", "remote_endpoint")
|
||||||
local socket_path = (remote == "false" or not remote) and uci:get("dockerd", "globals", "socket_path") or nil
|
local host = nil
|
||||||
local host = (remote == "true") and uci:get("dockerd", "globals", "remote_host") or nil
|
local port = nil
|
||||||
local port = (remote == "true") and uci:get("dockerd", "globals", "remote_port") or nil
|
local socket = nil
|
||||||
|
|
||||||
|
if remote then
|
||||||
|
host = uci:get("dockerd", "globals", "remote_host") or nil
|
||||||
|
port = uci:get("dockerd", "globals", "remote_port") or nil
|
||||||
|
else
|
||||||
|
socket = uci:get("dockerd", "globals", "socket_path") or nil
|
||||||
|
end
|
||||||
|
|
||||||
if remote and host and port then
|
if remote and host and port then
|
||||||
hosts = host .. ':'.. port
|
hosts = host .. ':'.. port
|
||||||
elseif socket_path then
|
elseif socket_path then
|
||||||
|
|
|
@ -91,41 +91,42 @@ if docker.new():_ping().code == 200 then
|
||||||
end
|
end
|
||||||
|
|
||||||
s = m:section(NamedSection, "globals", "section", translate("Setting"))
|
s = m:section(NamedSection, "globals", "section", translate("Setting"))
|
||||||
s:tab("daemon", translate("Docker Daemon"))
|
|
||||||
s:tab("dockerman", translate("DockerMan"))
|
|
||||||
|
|
||||||
o = s:taboption("dockerman", Value, "socket_path",
|
o = s:option(Flag, "remote_endpoint",
|
||||||
|
translate("Remote Endpoint"),
|
||||||
|
translate("Connect to remote endpoint"))
|
||||||
|
o.rmempty = false
|
||||||
|
|
||||||
|
o = s:option(Value, "socket_path",
|
||||||
translate("Docker Socket Path"))
|
translate("Docker Socket Path"))
|
||||||
o.default = "/var/run/docker.sock"
|
o.default = "/var/run/docker.sock"
|
||||||
o.placeholder = "/var/run/docker.sock"
|
o.placeholder = "/var/run/docker.sock"
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
|
o:depends("remote_endpoint", 1)
|
||||||
|
|
||||||
o = s:taboption("dockerman", Flag, "remote_endpoint",
|
o = s:option(Value, "remote_host",
|
||||||
translate("Remote Endpoint"),
|
|
||||||
translate("Dockerman connect to remote endpoint"))
|
|
||||||
o.rmempty = false
|
|
||||||
o.enabled = "true"
|
|
||||||
o.disabled = "false"
|
|
||||||
|
|
||||||
o = s:taboption("dockerman", Value, "remote_host",
|
|
||||||
translate("Remote Host"))
|
translate("Remote Host"))
|
||||||
o.placeholder = "10.1.1.2"
|
o.placeholder = "10.1.1.2"
|
||||||
|
o:depends("remote_endpoint", 1)
|
||||||
|
|
||||||
o = s:taboption("dockerman", Value, "remote_port",
|
o = s:option(Value, "remote_port",
|
||||||
translate("Remote Port"))
|
translate("Remote Port"))
|
||||||
o.placeholder = "2375"
|
o.placeholder = "2375"
|
||||||
o.default = "2375"
|
o.default = "2375"
|
||||||
|
o:depends("remote_endpoint", 1)
|
||||||
|
|
||||||
if nixio.fs.access("/usr/bin/dockerd") then
|
if nixio.fs.access("/usr/bin/dockerd") then
|
||||||
o = s:taboption("daemon", Value, "data_root",
|
o = s:option(Value, "data_root",
|
||||||
translate("Docker Root Dir"))
|
translate("Docker Root Dir"))
|
||||||
o.placeholder = "/opt/docker/"
|
o.placeholder = "/opt/docker/"
|
||||||
|
o:depends("remote_endpoint", 0)
|
||||||
|
|
||||||
o = s:taboption("daemon", DynamicList, "registry_mirrors",
|
o = s:option(DynamicList, "registry_mirrors",
|
||||||
translate("Registry Mirrors"))
|
translate("Registry Mirrors"))
|
||||||
o:value("https://hub-mirror.c.163.com", "https://hub-mirror.c.163.com")
|
o:value("https://hub-mirror.c.163.com", "https://hub-mirror.c.163.com")
|
||||||
|
o:depends("remote_endpoint", 0)
|
||||||
|
|
||||||
o = s:taboption("daemon", ListValue, "log_level",
|
o = s:option(ListValue, "log_level",
|
||||||
translate("Log Level"),
|
translate("Log Level"),
|
||||||
translate('Set the logging level'))
|
translate('Set the logging level'))
|
||||||
o:value("debug", "debug")
|
o:value("debug", "debug")
|
||||||
|
@ -133,13 +134,15 @@ if nixio.fs.access("/usr/bin/dockerd") then
|
||||||
o:value("warn", "warn")
|
o:value("warn", "warn")
|
||||||
o:value("error", "error")
|
o:value("error", "error")
|
||||||
o:value("fatal", "fatal")
|
o:value("fatal", "fatal")
|
||||||
|
o:depends("remote_endpoint", 0)
|
||||||
|
|
||||||
o = s:taboption("daemon", DynamicList, "hosts",
|
o = s:option(DynamicList, "hosts",
|
||||||
translate("Client connection"),
|
translate("Client connection"),
|
||||||
translate('Specifies where the Docker daemon will listen for client connections'))
|
translate('Specifies where the Docker daemon will listen for client connections'))
|
||||||
o:value("unix://var/run/docker.sock", "unix://var/run/docker.sock")
|
o:value("unix://var/run/docker.sock", "unix://var/run/docker.sock")
|
||||||
o:value("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375")
|
o:value("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375")
|
||||||
o.rmempty = true
|
o.rmempty = true
|
||||||
|
o:depends("remote_endpoint", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -270,13 +270,23 @@ local duplicate_config = function (self, request)
|
||||||
end
|
end
|
||||||
|
|
||||||
_docker.new = function()
|
_docker.new = function()
|
||||||
|
local host = nil
|
||||||
|
local port = nil
|
||||||
|
local socket = nil
|
||||||
|
|
||||||
local remote = uci:get("dockerd", "globals", "remote_endpoint")
|
local remote = uci:get_bool("dockerd", "globals", "remote_endpoint")
|
||||||
|
|
||||||
|
if remote then
|
||||||
|
host = uci:get("dockerd", "globals", "remote_host") or nil
|
||||||
|
port = uci:get("dockerd", "globals", "remote_port") or nil
|
||||||
|
else
|
||||||
|
socket = uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock"
|
||||||
|
end
|
||||||
|
|
||||||
_docker.options = {
|
_docker.options = {
|
||||||
host = (remote == "true") and (uci:get("dockerd", "globals", "remote_host")) or nil,
|
host = host,
|
||||||
port = (remote == "true") and (uci:get("dockerd", "globals", "remote_port")) or nil,
|
port = port,
|
||||||
socket_path = (remote ~= "true") and (uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock") or nil,
|
socket_path = socket,
|
||||||
debug = uci:get("dockerd", "globals", "debug") == 'true' and true or false,
|
debug = uci:get("dockerd", "globals", "debug") == 'true' and true or false,
|
||||||
debug_path = uci:get("dockerd", "globals", "debug_path") or "/tmp/.docker_debug",
|
debug_path = uci:get("dockerd", "globals", "debug_path") or "/tmp/.docker_debug",
|
||||||
status_path = uci:get("dockerd", "globals", "status_path") or "/tmp/.docker_status"
|
status_path = uci:get("dockerd", "globals", "status_path") or "/tmp/.docker_status"
|
||||||
|
|
Loading…
Reference in a new issue