diff options
Diffstat (limited to 'applications/luci-app-dockerman/luasrc/model/cbi')
9 files changed, 149 insertions, 123 deletions
diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/configuration.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/configuration.lua new file mode 100644 index 0000000000..6fd831d370 --- /dev/null +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/configuration.lua @@ -0,0 +1,72 @@ +-- Copyright 2021 Florian Eckert <fe@dev.tdt.de> +-- Licensed to the public under the Apache License 2.0. + +local m, s, o + +m = Map("dockerd", + translate("Docker - Configuration"), + translate("DockerMan is a simple docker manager client for LuCI")) + +s = m:section(NamedSection, "globals", "section", translate("Global settings")) + +o = s:option(Flag, "remote_endpoint", + translate("Remote Endpoint"), + translate("Connect to remote endpoint")) +o.rmempty = false + +o = s:option(Value, "remote_host", + translate("Remote Host"), + translate("Host or IP Address for the connection to a remote docker instance")) +o.datatype = "host" +o.rmempty = false +o.optional = false +o.placeholder = "10.1.1.2" +o:depends("remote_endpoint", 1) + +o = s:option(Value, "remote_port", + translate("Remote Port")) +o.placeholder = "2375" +o.datatype = "port" +o.rmempty = false +o.optional = false +o:depends("remote_endpoint", 1) + +if nixio.fs.access("/usr/bin/dockerd") then + o = s:option(Value, "data_root", + translate("Docker Root Dir")) + o.placeholder = "/opt/docker/" + o:depends("remote_endpoint", 0) + + o = s:option(Value, "bip", + translate("Default bridge"), + translate("Configure the default bridge network")) + o.placeholder = "172.17.0.1/16" + o.datatype = "ipaddr" + o:depends("remote_endpoint", 0) + + o = s:option(DynamicList, "registry_mirrors", + translate("Registry Mirrors"), + translate("It replaces the daemon registry mirrors with a new set of registry mirrors")) + o.placeholder = translate("Example: https://hub-mirror.c.163.com") + o:depends("remote_endpoint", 0) + + o = s:option(ListValue, "log_level", + translate("Log Level"), + translate('Set the logging level')) + o:value("debug", translate("Debug")) + o:value("", translate("Info")) -- This is the default debug level from the deamon is optin is not set + o:value("warn", translate("Warning")) + o:value("error", translate("Error")) + o:value("fatal", translate("Fatal")) + o.rmempty = true + o:depends("remote_endpoint", 0) + + o = s:option(DynamicList, "hosts", + translate("Client connection"), + translate('Specifies where the Docker daemon will listen for client connections (default: unix:///var/run/docker.sock)')) + o.placeholder = translate("Example: tcp://0.0.0.0:2375") + o.rmempty = true + o:depends("remote_endpoint", 0) +end + +return m diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua index ec3f9201af..5caad4f93f 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua @@ -37,7 +37,7 @@ local get_ports = function(d) if d.HostConfig and d.HostConfig.PortBindings then for inter, out in pairs(d.HostConfig.PortBindings) do - data = (data and (data .. "<br>") or "") .. out[1]["HostPort"] .. ":" .. inter + data = (data and (data .. "<br />") or "") .. out[1]["HostPort"] .. ":" .. inter end end @@ -49,7 +49,7 @@ local get_env = function(d) if d.Config and d.Config.Env then for _,v in ipairs(d.Config.Env) do - data = (data and (data .. "<br>") or "") .. v + data = (data and (data .. "<br />") or "") .. v end end @@ -90,7 +90,7 @@ local get_mounts = function(d) v_dest = v_dest .."/".. v_dest_d end end - data = (data and (data .. "<br>") or "") .. v_sorce .. ":" .. v["Destination"] .. (v["Mode"] ~= "" and (":" .. v["Mode"]) or "") + data = (data and (data .. "<br />") or "") .. v_sorce .. ":" .. v["Destination"] .. (v["Mode"] ~= "" and (":" .. v["Mode"]) or "") end end @@ -102,7 +102,7 @@ local get_device = function(d) if d.HostConfig and d.HostConfig.Devices then for _,v in ipairs(d.HostConfig.Devices) do - data = (data and (data .. "<br>") or "") .. v["PathOnHost"] .. ":" .. v["PathInContainer"] .. (v["CgroupPermissions"] ~= "" and (":" .. v["CgroupPermissions"]) or "") + data = (data and (data .. "<br />") or "") .. v["PathOnHost"] .. ":" .. v["PathInContainer"] .. (v["CgroupPermissions"] ~= "" and (":" .. v["CgroupPermissions"]) or "") end end @@ -114,7 +114,7 @@ local get_links = function(d) if d.HostConfig and d.HostConfig.Links then for _,v in ipairs(d.HostConfig.Links) do - data = (data and (data .. "<br>") or "") .. v + data = (data and (data .. "<br />") or "") .. v end end @@ -126,7 +126,7 @@ local get_tmpfs = function(d) if d.HostConfig and d.HostConfig.Tmpfs then for k, v in pairs(d.HostConfig.Tmpfs) do - data = (data and (data .. "<br>") or "") .. k .. (v~="" and ":" or "")..v + data = (data and (data .. "<br />") or "") .. k .. (v~="" and ":" or "")..v end end @@ -138,7 +138,7 @@ local get_dns = function(d) if d.HostConfig and d.HostConfig.Dns then for _, v in ipairs(d.HostConfig.Dns) do - data = (data and (data .. "<br>") or "") .. v + data = (data and (data .. "<br />") or "") .. v end end @@ -150,7 +150,7 @@ local get_sysctl = function(d) if d.HostConfig and d.HostConfig.Sysctls then for k, v in pairs(d.HostConfig.Sysctls) do - data = (data and (data .. "<br>") or "") .. k..":"..v + data = (data and (data .. "<br />") or "") .. k..":"..v end end @@ -195,13 +195,15 @@ local start_stop_remove = function(m, cmd) end end -m=SimpleForm("docker", container_info.Name:sub(2), translate("Docker Container") ) +m=SimpleForm("docker", + translatef("Docker - Container (%s)", container_info.Name:sub(2)), + translate("On this page, the selected container can be managed.")) m.redirect = luci.dispatcher.build_url("admin/docker/containers") s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err=docker:read_status() -s.err=s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err=s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end @@ -292,7 +294,7 @@ if action == "info" then }, ["03image"] = { _key = translate("Image"), - _value = container_info.Config.Image .. "<br>" .. container_info.Image + _value = container_info.Config.Image .. "<br />" .. container_info.Image }, ["04status"] = { _key = translate("Status"), @@ -750,35 +752,40 @@ elseif action == "stats" then local response = dk.containers:top({id = container_id, query = {ps_args="-aux"}}) local container_top - if response.code == 200 then - container_top=response.body - else - response = dk.containers:top({id = container_id}) + if response.code ~= 409 then + if response.code ~= 200 then + response = dk.containers:top({id = container_id}) + end + + if response.code ~= 200 then + response = dk.containers:top({id = container_id, query = {ps_args="-ww"}}) + end + if response.code == 200 then - container_top=response.body + container_top = response.body end - end - if type(container_top) == "table" then - s = m:section(SimpleSection) - s.container_id = container_id - s.template = "dockerman/container_stats" - table_stats = { - cpu={ - key=translate("CPU Useage"), + local table_stats = { + cpu = { + key=translate("CPU Usage"), value='-' }, - memory={ - key=translate("Memory Useage"), + memory = { + key=translate("Memory Usage"), value='-' } } - - container_top = response.body s = m:section(Table, table_stats, translate("Stats")) s:option(DummyValue, "key", translate("Stats")).width="33%" s:option(DummyValue, "value") - top_section = m:section(Table, container_top.Processes, translate("TOP")) + + s = m:section(SimpleSection) + s.container_id = container_id + s.template = "dockerman/container_stats" + end + + if type(container_top) == "table" then + local top_section = m:section(Table, container_top.Processes, translate("TOP")) for i, v in ipairs(container_top.Titles) do top_section:option(DummyValue, i, translate(v)) end diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua index 5bcb5fae9c..a48118ec0c 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua @@ -90,19 +90,21 @@ end local container_list = get_containers() -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", + translate("Docker - Containers"), + translate("This page displays all containers that have been created on the connected docker host.")) m.submit=false m.reset=false s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err=docker:read_status() -s.err=s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err=s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end -s = m:section(Table, container_list, translate("Containers")) +s = m:section(Table, container_list, translate("Containers overview")) s.addremove = false s.sectionhead = translate("Containers") s.sortable = false diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/images.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/images.lua index 01a7e3f237..2b84de3b8f 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/images.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/images.lua @@ -40,7 +40,7 @@ function get_images() if v.RepoTags and next(v.RepoTags)~=nil then for i, v1 in ipairs(v.RepoTags) do - data[index]["_tags"] =(data[index]["_tags"] and ( data[index]["_tags"] .. "<br>" )or "") .. ((v1:match("<none>") or (#v.RepoTags == 1)) and v1 or ('<a href="javascript:un_tag(\''..v1..'\')" class="dockerman_link" title="'..translate("Remove tag")..'" >' .. v1 .. '</a>')) + data[index]["_tags"] =(data[index]["_tags"] and ( data[index]["_tags"] .. "<br />" )or "") .. ((v1:match("<none>") or (#v.RepoTags == 1)) and v1 or ('<a href="javascript:un_tag(\''..v1..'\')" class="dockerman_link" title="'..translate("Remove tag")..'" >' .. v1 .. '</a>')) if not data[index]["tag"] then data[index]["tag"] = v1 @@ -68,7 +68,9 @@ end local image_list = get_images() -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", + translate("Docker - Images"), + translate("On this page all images are displayed that are available on the system and with which a container can be created.")) m.submit=false m.reset=false @@ -77,7 +79,9 @@ local pull_value={ _registry="index.docker.io" } -s = m:section(SimpleSection, translate("Pull Image")) +s = m:section(SimpleSection, + translate("Pull Image"), + translate("By entering a valid image name with the corresponding version, the docker image can be downloaded from the configured registry.")) s.template="cbi/nullsection" o = s:option(Value, "_image_tag_name") @@ -116,12 +120,14 @@ o.write = function(self, section) luci.http.redirect(luci.dispatcher.build_url("admin/docker/images")) end -s = m:section(SimpleSection, translate("Import Images")) +s = m:section(SimpleSection, + translate("Import Image"), + translate("When pressing the Import button, both a local image can be loaded onto the system and a valid image tar can be downloaded from remote.")) o = s:option(DummyValue, "_image_import") o.template = "dockerman/images_import" -s = m:section(Table, image_list, translate("Images")) +s = m:section(Table, image_list, translate("Images overview")) o = s:option(Flag, "_selected","") o.disabled = 0 @@ -149,7 +155,7 @@ local remove_action = function(force) for k in pairs(image_list) do if image_list[k]._selected == 1 then - image_selected[#image_selected+1] = (image_list[k]["_tags"]:match("<br>") or image_list[k]["_tags"]:match("<none>")) and image_list[k].id or image_list[k].tag + image_selected[#image_selected+1] = (image_list[k]["_tags"]:match("<br />") or image_list[k]["_tags"]:match("<none>")) and image_list[k].id or image_list[k].tag end end @@ -188,7 +194,7 @@ end s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err = docker:read_status() -s.err = s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err = s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/networks.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/networks.lua index 4cea32915d..f54acbd16d 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/networks.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/networks.lua @@ -38,8 +38,8 @@ local get_networks = function () data[index]["_interface"] = v.Options.parent end - data[index]["_subnet"] = v.IPAM and v.IPAM.Config[1] and v.IPAM.Config[1].Subnet or nil - data[index]["_gateway"] = v.IPAM and v.IPAM.Config[1] and v.IPAM.Config[1].Gateway or nil + data[index]["_subnet"] = v.IPAM and v.IPAM.Config and v.IPAM.Config[1] and v.IPAM.Config[1].Subnet or nil + data[index]["_gateway"] = v.IPAM and v.IPAM.Config and v.IPAM.Config[1] and v.IPAM.Config[1].Gateway or nil end return data @@ -47,11 +47,13 @@ end local network_list = get_networks() -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", + translate("Docker - Networks"), + translate("This page displays all docker networks that have been created on the connected docker host.")) m.submit=false m.reset=false -s = m:section(Table, network_list, translate("Networks")) +s = m:section(Table, network_list, translate("Networks overview")) s.nodescr=true o = s:option(Flag, "_selected","") @@ -85,7 +87,7 @@ o = s:option(DummyValue, "_gateway", translate("Gateway")) s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err = docker:read_status() -s.err = s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err = s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua index 0ee344370e..5d38a352e0 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newcontainer.lua @@ -436,18 +436,18 @@ elseif cmd_line and cmd_line:match("^duplicate/[^/]+$") then end end -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", translate("Docker - Containers")) m.redirect = luci.dispatcher.build_url("admin", "docker", "containers") s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err=docker:read_status() -s.err=s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err=s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end -s = m:section(SimpleSection, translate("New Container")) +s = m:section(SimpleSection, translate("Create new docker container")) s.addremove = true s.anonymous = true @@ -720,7 +720,7 @@ m.handle = function(self, state, data) local memory = data.memory or 0 local cpu_shares = data.cpu_shares or 0 local cpus = data.cpus or 0 - local blkio_weight = data.blkio_weight or 500 + local blkio_weight = data.blkio_weight or nil local portbindings = {} local exposedports = {} diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua index 2c9cb271fc..a9cd67e1a1 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua @@ -9,18 +9,18 @@ local m, s, o local dk = docker.new() -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", translate("Docker - Network")) m.redirect = luci.dispatcher.build_url("admin", "docker", "networks") s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err=docker:read_status() -s.err=s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err=s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end -s = m:section(SimpleSection, translate("New Network")) +s = m:section(SimpleSection, translate("Create new docker network")) s.addremove = true s.anonymous = true diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua index 59266ac490..0506670cdb 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua @@ -18,12 +18,11 @@ function byte_format(byte) end end -m = Map("dockerd", translate("Docker"), - translate("DockerMan is a Simple Docker manager client for LuCI, If you have any issue please visit:") .. - " " .. - [[<a href="https://github.com/lisaac/luci-app-dockerman" target="_blank">]] .. - translate("Github") .. - [[</a>]]) +m = SimpleForm("dockerd", + translate("Docker - Overview"), + translate("An overview with the relevant data is displayed here with which the LuCI docker client is connected.")) +m.submit=false +m.reset=false local docker_info_table = {} docker_info_table['3ServerVersion'] = {_key=translate("Docker Version"),_value='-'} @@ -68,7 +67,7 @@ if docker.new():_ping().code == 200 then end docker_info_table['8IndexServerAddress']._value = docker_info.body.IndexServerAddress - for i, v in ipairs(docker_info.body.RegistryConfig.Mirrors) do + for i, v in ipairs(docker_info.body.RegistryConfig.Mirrors or {}) do docker_info_table['9RegistryMirrors']._value = docker_info_table['9RegistryMirrors']._value == "-" and v or (docker_info_table['9RegistryMirrors']._value .. ", " .. v) end @@ -90,66 +89,4 @@ if docker.new():_ping().code == 200 then s.volumes_total = tostring(#volumes_list) end -s = m:section(NamedSection, "globals", "section", translate("Setting")) - -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")) -o.default = "unix:///var/run/docker.sock" -o.placeholder = "unix:///var/run/docker.sock" -o:depends("remote_endpoint", 1) - -o = s:option(Value, "remote_host", - translate("Remote Host")) -o.placeholder = "10.1.1.2" -o:depends("remote_endpoint", 1) - -o = s:option(Value, "remote_port", - translate("Remote Port")) -o.placeholder = "2375" -o.default = "2375" -o:depends("remote_endpoint", 1) - -if nixio.fs.access("/usr/bin/dockerd") then - o = s:option(Value, "data_root", - translate("Docker Root Dir")) - o.placeholder = "/opt/docker/" - o:depends("remote_endpoint", 0) - - o = s:option(Value, "bip", - translate("Default bridge"), - translate("Configure the default bridge network")) - o.placeholder = "172.17.0.1/16" - o.default = "172.17.0.1/16" - o.datatype = "ipaddr" - o:depends("remote_endpoint", 0) - - o = s:option(DynamicList, "registry_mirrors", - translate("Registry Mirrors")) - o:value("https://hub-mirror.c.163.com", "https://hub-mirror.c.163.com") - o:depends("remote_endpoint", 0) - - o = s:option(ListValue, "log_level", - translate("Log Level"), - translate('Set the logging level')) - o:value("debug", "debug") - o:value("info", "info") - o:value("warn", "warn") - o:value("error", "error") - o:value("fatal", "fatal") - o:depends("remote_endpoint", 0) - - o = s:option(DynamicList, "hosts", - translate("Client connection"), - 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("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375") - o.rmempty = true - o:depends("remote_endpoint", 0) -end - return m diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/volumes.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/volumes.lua index 8dae4a020d..5fbd55f7b5 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/volumes.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/volumes.lua @@ -66,11 +66,11 @@ end local volume_list = get_volumes() -m = SimpleForm("docker", translate("Docker")) +m = SimpleForm("docker", translate("Docker - Volumes")) m.submit=false m.reset=false -s = m:section(Table, volume_list, translate("Volumes")) +s = m:section(Table, volume_list, translate("Volumes overview")) o = s:option(Flag, "_selected","") o.disabled = 0 @@ -94,7 +94,7 @@ o = s:option(DummyValue, "_created", translate("Created")) s = m:section(SimpleSection) s.template = "dockerman/apply_widget" s.err=docker:read_status() -s.err=s.err and s.err:gsub("\n","<br>"):gsub(" "," ") +s.err=s.err and s.err:gsub("\n","<br />"):gsub(" "," ") if s.err then docker:clear_status() end |