luci-app-dockerman: cbi/container update coding style

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2020-07-23 08:52:03 +02:00
parent 10e6f62904
commit 30caab1e73

View file

@ -4,50 +4,73 @@ Copyright 2019 lisaac <https://github.com/lisaac/luci-app-dockerman>
]]-- ]]--
require "luci.util" require "luci.util"
local docker = require "luci.model.docker" local docker = require "luci.model.docker"
local dk = docker.new() local dk = docker.new()
container_id = arg[1] container_id = arg[1]
local action = arg[2] or "info" local action = arg[2] or "info"
local images, networks, container_info local m, s, o
if not container_id then return end local images, networks, container_info, res
local res = dk.containers:inspect({id = container_id})
if res.code < 300 then container_info = res.body else return end if not container_id then
return
end
res = dk.containers:inspect({id = container_id})
if res.code < 300 then
container_info = res.body
else
return
end
res = dk.networks:list() res = dk.networks:list()
if res.code < 300 then networks = res.body else return end if res.code < 300 then
networks = res.body
else
return
end
local get_ports = function(d) local get_ports = function(d)
local data local data
if d.HostConfig and d.HostConfig.PortBindings then if d.HostConfig and d.HostConfig.PortBindings then
for inter, out in pairs(d.HostConfig.PortBindings) do 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
end end
return data return data
end end
local get_env = function(d) local get_env = function(d)
local data local data
if d.Config and d.Config.Env then if d.Config and d.Config.Env then
for _,v in ipairs(d.Config.Env) do for _,v in ipairs(d.Config.Env) do
data = (data and (data .. "<br>") or "") .. v data = (data and (data .. "<br>") or "") .. v
end end
end end
return data return data
end end
local get_command = function(d) local get_command = function(d)
local data local data
if d.Config and d.Config.Cmd then if d.Config and d.Config.Cmd then
for _,v in ipairs(d.Config.Cmd) do for _,v in ipairs(d.Config.Cmd) do
data = (data and (data .. " ") or "") .. v data = (data and (data .. " ") or "") .. v
end end
end end
return data return data
end end
local get_mounts = function(d) local get_mounts = function(d)
local data local data
if d.Mounts then if d.Mounts then
for _,v in ipairs(d.Mounts) do for _,v in ipairs(d.Mounts) do
local v_sorce_d, v_dest_d local v_sorce_d, v_dest_d
@ -70,79 +93,95 @@ local get_mounts = function(d)
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
end end
return data return data
end end
local get_device = function(d) local get_device = function(d)
local data local data
if d.HostConfig and d.HostConfig.Devices then if d.HostConfig and d.HostConfig.Devices then
for _,v in ipairs(d.HostConfig.Devices) do 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
end end
return data return data
end end
local get_links = function(d) local get_links = function(d)
local data local data
if d.HostConfig and d.HostConfig.Links then if d.HostConfig and d.HostConfig.Links then
for _,v in ipairs(d.HostConfig.Links) do for _,v in ipairs(d.HostConfig.Links) do
data = (data and (data .. "<br>") or "") .. v data = (data and (data .. "<br>") or "") .. v
end end
end end
return data return data
end end
local get_tmpfs = function(d) local get_tmpfs = function(d)
local data local data
if d.HostConfig and d.HostConfig.Tmpfs then if d.HostConfig and d.HostConfig.Tmpfs then
for k, v in pairs(d.HostConfig.Tmpfs) do 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
end end
return data return data
end end
local get_dns = function(d) local get_dns = function(d)
local data local data
if d.HostConfig and d.HostConfig.Dns then if d.HostConfig and d.HostConfig.Dns then
for _, v in ipairs(d.HostConfig.Dns) do for _, v in ipairs(d.HostConfig.Dns) do
data = (data and (data .. "<br>") or "") .. v data = (data and (data .. "<br>") or "") .. v
end end
end end
return data return data
end end
local get_sysctl = function(d) local get_sysctl = function(d)
local data local data
if d.HostConfig and d.HostConfig.Sysctls then if d.HostConfig and d.HostConfig.Sysctls then
for k, v in pairs(d.HostConfig.Sysctls) do 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
end end
return data return data
end end
local get_networks = function(d) local get_networks = function(d)
local data={} local data={}
if d.NetworkSettings and d.NetworkSettings.Networks and type(d.NetworkSettings.Networks) == "table" then if d.NetworkSettings and d.NetworkSettings.Networks and type(d.NetworkSettings.Networks) == "table" then
for k,v in pairs(d.NetworkSettings.Networks) do for k,v in pairs(d.NetworkSettings.Networks) do
data[k] = v.IPAddress or "" data[k] = v.IPAddress or ""
end end
end end
return data return data
end end
local start_stop_remove = function(m, cmd) local start_stop_remove = function(m, cmd)
local res
docker:clear_status() docker:clear_status()
docker:append_status("Containers: " .. cmd .. " " .. container_id .. "...") docker:append_status("Containers: " .. cmd .. " " .. container_id .. "...")
local res
if cmd ~= "upgrade" then if cmd ~= "upgrade" then
res = dk.containers[cmd](dk, {id = container_id}) res = dk.containers[cmd](dk, {id = container_id})
else else
res = dk.containers_upgrade(dk, {id = container_id}) res = dk.containers_upgrade(dk, {id = container_id})
end end
if res and res.code >= 300 then if res and res.code >= 300 then
docker:append_status("code:" .. res.code.." ".. (res.body.message and res.body.message or res.message)) docker:append_status("code:" .. res.code.." ".. (res.body.message and res.body.message or res.message))
luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id)) luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id))
@ -158,103 +197,165 @@ end
m=SimpleForm("docker", container_info.Name:sub(2), translate("Docker Container") ) m=SimpleForm("docker", container_info.Name:sub(2), translate("Docker Container") )
m.redirect = luci.dispatcher.build_url("admin/docker/containers") m.redirect = luci.dispatcher.build_url("admin/docker/containers")
-- m:append(Template("dockerman/container"))
docker_status = m:section(SimpleSection)
docker_status.template = "dockerman/apply_widget"
docker_status.err=docker:read_status()
docker_status.err=docker_status.err and docker_status.err:gsub("\n","<br>"):gsub(" ","&nbsp;")
if docker_status.err then docker:clear_status() 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(" ","&nbsp;")
if s.err then
docker:clear_status()
end
action_section = m:section(Table,{{}}) s = m:section(Table,{{}})
action_section.notitle=true s.notitle=true
action_section.rowcolors=false s.rowcolors=false
action_section.template = "cbi/nullsection" s.template = "cbi/nullsection"
btnstart=action_section:option(Button, "_start") o = s:option(Button, "_start")
btnstart.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnstart.inputtitle=translate("Start") o.inputtitle=translate("Start")
btnstart.inputstyle = "apply" o.inputstyle = "apply"
btnstart.forcewrite = true o.forcewrite = true
btnrestart=action_section:option(Button, "_restart") o.write = function(self, section)
btnrestart.template = "dockerman/cbi/inlinebutton"
btnrestart.inputtitle=translate("Restart")
btnrestart.inputstyle = "reload"
btnrestart.forcewrite = true
btnstop=action_section:option(Button, "_stop")
btnstop.template = "dockerman/cbi/inlinebutton"
btnstop.inputtitle=translate("Stop")
btnstop.inputstyle = "reset"
btnstop.forcewrite = true
btnkill=action_section:option(Button, "_kill")
btnkill.template = "dockerman/cbi/inlinebutton"
btnkill.inputtitle=translate("Kill")
btnkill.inputstyle = "reset"
btnkill.forcewrite = true
btnupgrade=action_section:option(Button, "_upgrade")
btnupgrade.template = "dockerman/cbi/inlinebutton"
btnupgrade.inputtitle=translate("Upgrade")
btnupgrade.inputstyle = "reload"
btnstop.forcewrite = true
btnduplicate=action_section:option(Button, "_duplicate")
btnduplicate.template = "dockerman/cbi/inlinebutton"
btnduplicate.inputtitle=translate("Duplicate/Edit")
btnduplicate.inputstyle = "add"
btnstop.forcewrite = true
btnremove=action_section:option(Button, "_remove")
btnremove.template = "dockerman/cbi/inlinebutton"
btnremove.inputtitle=translate("Remove")
btnremove.inputstyle = "remove"
btnremove.forcewrite = true
btnstart.write = function(self, section)
start_stop_remove(m,"start") start_stop_remove(m,"start")
end end
btnrestart.write = function(self, section)
o = s:option(Button, "_restart")
o.template = "dockerman/cbi/inlinebutton"
o.inputtitle=translate("Restart")
o.inputstyle = "reload"
o.forcewrite = true
o.write = function(self, section)
start_stop_remove(m,"restart") start_stop_remove(m,"restart")
end end
btnupgrade.write = function(self, section)
start_stop_remove(m,"upgrade") o = s:option(Button, "_stop")
end o.template = "dockerman/cbi/inlinebutton"
btnremove.write = function(self, section) o.inputtitle=translate("Stop")
start_stop_remove(m,"remove") o.inputstyle = "reset"
end o.forcewrite = true
btnstop.write = function(self, section) o.write = function(self, section)
start_stop_remove(m,"stop") start_stop_remove(m,"stop")
end end
btnkill.write = function(self, section)
o = s:option(Button, "_kill")
o.template = "dockerman/cbi/inlinebutton"
o.inputtitle=translate("Kill")
o.inputstyle = "reset"
o.forcewrite = true
o.write = function(self, section)
start_stop_remove(m,"kill") start_stop_remove(m,"kill")
end end
btnduplicate.write = function(self, section)
o = s:option(Button, "_upgrade")
o.template = "dockerman/cbi/inlinebutton"
o.inputtitle=translate("Upgrade")
o.inputstyle = "reload"
o.forcewrite = true
o.write = function(self, section)
start_stop_remove(m,"upgrade")
end
o = s:option(Button, "_duplicate")
o.template = "dockerman/cbi/inlinebutton"
o.inputtitle=translate("Duplicate/Edit")
o.inputstyle = "add"
o.forcewrite = true
o.write = function(self, section)
luci.http.redirect(luci.dispatcher.build_url("admin/docker/newcontainer/duplicate/"..container_id)) luci.http.redirect(luci.dispatcher.build_url("admin/docker/newcontainer/duplicate/"..container_id))
end end
tab_section = m:section(SimpleSection) o = s:option(Button, "_remove")
tab_section.template = "dockerman/container" o.template = "dockerman/cbi/inlinebutton"
o.inputtitle=translate("Remove")
o.inputstyle = "remove"
o.forcewrite = true
o.write = function(self, section)
start_stop_remove(m,"remove")
end
s = m:section(SimpleSection)
s.template = "dockerman/container"
if action == "info" then if action == "info" then
m.submit = false m.submit = false
m.reset = false m.reset = false
table_info = { table_info = {
["01name"] = {_key = translate("Name"), _value = container_info.Name:sub(2) or "-", _button=translate("Update")}, ["01name"] = {
["02id"] = {_key = translate("ID"), _value = container_info.Id or "-"}, _key = translate("Name"),
["03image"] = {_key = translate("Image"), _value = container_info.Config.Image .. "<br>" .. container_info.Image}, _value = container_info.Name:sub(2) or "-",
["04status"] = {_key = translate("Status"), _value = container_info.State and container_info.State.Status or "-"}, _button=translate("Update")
["05created"] = {_key = translate("Created"), _value = container_info.Created or "-"}, },
["02id"] = {
_key = translate("ID"),
_value = container_info.Id or "-"
},
["03image"] = {
_key = translate("Image"),
_value = container_info.Config.Image .. "<br>" .. container_info.Image
},
["04status"] = {
_key = translate("Status"),
_value = container_info.State and container_info.State.Status or "-"
},
["05created"] = {
_key = translate("Created"),
_value = container_info.Created or "-"
},
} }
table_info["06start"] = container_info.State.Status == "running" and {_key = translate("Start Time"), _value = container_info.State and container_info.State.StartedAt or "-"} or {_key = translate("Finish Time"), _value = container_info.State and container_info.State.FinishedAt or "-"} table_info["06start"] = container_info.State.Status == "running" and {_key = translate("Start Time"), _value = container_info.State and container_info.State.StartedAt or "-"} or {_key = translate("Finish Time"), _value = container_info.State and container_info.State.FinishedAt or "-"}
table_info["07healthy"] = {_key = translate("Healthy"), _value = container_info.State and container_info.State.Health and container_info.State.Health.Status or "-"}
table_info["08restart"] = {_key = translate("Restart Policy"), _value = container_info.HostConfig and container_info.HostConfig.RestartPolicy and container_info.HostConfig.RestartPolicy.Name or "-", _button=translate("Update")} table_info["07healthy"] = {
table_info["081user"] = {_key = translate("User"), _value = container_info.Config and (container_info.Config.User ~="" and container_info.Config.User or "-") or "-"} _key = translate("Healthy"),
table_info["09mount"] = {_key = translate("Mount/Volume"), _value = get_mounts(container_info) or "-"} _value = container_info.State and container_info.State.Health and container_info.State.Health.Status or "-"
table_info["10cmd"] = {_key = translate("Command"), _value = get_command(container_info) or "-"} }
table_info["11env"] = {_key = translate("Env"), _value = get_env(container_info) or "-"} table_info["08restart"] = {
table_info["12ports"] = {_key = translate("Ports"), _value = get_ports(container_info) or "-"} _key = translate("Restart Policy"),
table_info["13links"] = {_key = translate("Links"), _value = get_links(container_info) or "-"} _value = container_info.HostConfig and container_info.HostConfig.RestartPolicy and container_info.HostConfig.RestartPolicy.Name or "-",
table_info["14device"] = {_key = translate("Device"), _value = get_device(container_info) or "-"} _button=translate("Update")
table_info["15tmpfs"] = {_key = translate("Tmpfs"), _value = get_tmpfs(container_info) or "-"} }
table_info["16dns"] = {_key = translate("DNS"), _value = get_dns(container_info) or "-"} table_info["081user"] = {
table_info["17sysctl"] = {_key = translate("Sysctl"), _value = get_sysctl(container_info) or "-"} _key = translate("User"),
_value = container_info.Config and (container_info.Config.User ~="" and container_info.Config.User or "-") or "-"
}
table_info["09mount"] = {
_key = translate("Mount/Volume"),
_value = get_mounts(container_info) or "-"
}
table_info["10cmd"] = {
_key = translate("Command"),
_value = get_command(container_info) or "-"
}
table_info["11env"] = {
_key = translate("Env"),
_value = get_env(container_info) or "-"
}
table_info["12ports"] = {
_key = translate("Ports"),
_value = get_ports(container_info) or "-"
}
table_info["13links"] = {
_key = translate("Links"),
_value = get_links(container_info) or "-"
}
table_info["14device"] = {
_key = translate("Device"),
_value = get_device(container_info) or "-"
}
table_info["15tmpfs"] = {
_key = translate("Tmpfs"),
_value = get_tmpfs(container_info) or "-"
}
table_info["16dns"] = {
_key = translate("DNS"),
_value = get_dns(container_info) or "-"
}
table_info["17sysctl"] = {
_key = translate("Sysctl"),
_value = get_sysctl(container_info) or "-"
}
info_networks = get_networks(container_info) info_networks = get_networks(container_info)
list_networks = {} list_networks = {}
for _, v in ipairs (networks) do for _, v in ipairs (networks) do
@ -270,20 +371,26 @@ if action == "info" then
if type(info_networks)== "table" then if type(info_networks)== "table" then
for k,v in pairs(info_networks) do for k,v in pairs(info_networks) do
table_info["14network"..k] = { table_info["14network"..k] = {
_key = translate("Network"), _value = k.. (v~="" and (" | ".. v) or ""), _button=translate("Disconnect") _key = translate("Network"),
value = k.. (v~="" and (" | ".. v) or ""),
_button=translate("Disconnect")
} }
list_networks[k]=nil list_networks[k]=nil
end end
end end
table_info["15connect"] = {_key = translate("Connect Network"), _value = list_networks ,_opts = "", _button=translate("Connect")} table_info["15connect"] = {
_key = translate("Connect Network"),
_value = list_networks ,_opts = "",
_button=translate("Connect")
}
d_info = m:section(Table,table_info) d_info = m:section(Table,table_info)
d_info.nodescr=true d_info.nodescr=true
d_info.formvalue=function(self, section) d_info.formvalue=function(self, section)
return table_info return table_info
end end
dv_key = d_info:option(DummyValue, "_key", translate("Info")) dv_key = d_info:option(DummyValue, "_key", translate("Info"))
dv_key.width = "20%" dv_key.width = "20%"
dv_value = d_info:option(ListValue, "_value") dv_value = d_info:option(ListValue, "_value")
@ -325,6 +432,7 @@ if action == "info" then
DummyValue.render(self, section, scope) DummyValue.render(self, section, scope)
end end
end end
dv_value.forcewrite = true -- for write function using simpleform dv_value.forcewrite = true -- for write function using simpleform
dv_value.write = function(self, section, value) dv_value.write = function(self, section, value)
table_info[section]._value=value table_info[section]._value=value
@ -335,7 +443,6 @@ if action == "info" then
dv_opts = d_info:option(Value, "_opts") dv_opts = d_info:option(Value, "_opts")
dv_opts.forcewrite = true -- for write function using simpleform dv_opts.forcewrite = true -- for write function using simpleform
dv_opts.write = function(self, section, value) dv_opts.write = function(self, section, value)
table_info[section]._opts=value table_info[section]._opts=value
end end
dv_opts.validate = function(self, value) dv_opts.validate = function(self, value)
@ -357,6 +464,7 @@ if action == "info" then
DummyValue.render(self, section, scope) DummyValue.render(self, section, scope)
end end
end end
btn_update = d_info:option(Button, "_button") btn_update = d_info:option(Button, "_button")
btn_update.forcewrite = true btn_update.forcewrite = true
btn_update.render = function(self, section, scope) btn_update.render = function(self, section, scope)
@ -371,26 +479,51 @@ if action == "info" then
DummyValue.render(self, section, scope) DummyValue.render(self, section, scope)
end end
end end
btn_update.write = function(self, section, value) btn_update.write = function(self, section, value)
local res local res
docker:clear_status() docker:clear_status()
if section == "01name" then if section == "01name" then
docker:append_status("Containers: rename " .. container_id .. "...") docker:append_status("Containers: rename " .. container_id .. "...")
local new_name = table_info[section]._value local new_name = table_info[section]._value
res = dk.containers:rename({id = container_id, query = {name=new_name}}) res = dk.containers:rename({
id = container_id,
query = {
name=new_name
}
})
elseif section == "08restart" then elseif section == "08restart" then
docker:append_status("Containers: update " .. container_id .. "...") docker:append_status("Containers: update " .. container_id .. "...")
local new_restart = table_info[section]._value local new_restart = table_info[section]._value
res = dk.containers:update({id = container_id, body = {RestartPolicy = {Name = new_restart}}}) res = dk.containers:update({
id = container_id,
body = {
RestartPolicy = {
Name = new_restart
}
}
})
elseif table_info[section]._key == translate("Network") then elseif table_info[section]._key == translate("Network") then
local _,_,leave_network = table_info[section]._value:find("(.-) | .+") local _,_,leave_network
_, _, leave_network = table_info[section]._value:find("(.-) | .+")
leave_network = leave_network or table_info[section]._value leave_network = leave_network or table_info[section]._value
docker:append_status("Network: disconnect " .. leave_network .. container_id .. "...") docker:append_status("Network: disconnect " .. leave_network .. container_id .. "...")
res = dk.networks:disconnect({name = leave_network, body = {Container = container_id}}) res = dk.networks:disconnect({
name = leave_network,
body = {
Container = container_id
}
})
elseif section == "15connect" then elseif section == "15connect" then
local connect_network = table_info[section]._value local connect_network = table_info[section]._value
local network_opiton local network_opiton
if connect_network ~= "none" and connect_network ~= "bridge" and connect_network ~= "host" then if connect_network ~= "none"
and connect_network ~= "bridge"
and connect_network ~= "host" then
network_opiton = table_info[section]._opts ~= "" and { network_opiton = table_info[section]._opts ~= "" and {
IPAMConfig={ IPAMConfig={
IPv4Address=table_info[section]._opts IPv4Address=table_info[section]._opts
@ -398,8 +531,15 @@ if action == "info" then
} or nil } or nil
end end
docker:append_status("Network: connect " .. connect_network .. container_id .. "...") docker:append_status("Network: connect " .. connect_network .. container_id .. "...")
res = dk.networks:connect({name = connect_network, body = {Container = container_id, EndpointConfig= network_opiton}}) res = dk.networks:connect({
name = connect_network,
body = {
Container = container_id,
EndpointConfig= network_opiton
}
})
end end
if res and res.code > 300 then if res and res.code > 300 then
docker:append_status("code:" .. res.code.." ".. (res.body.message and res.body.message or res.message)) docker:append_status("code:" .. res.code.." ".. (res.body.message and res.body.message or res.message))
else else
@ -407,32 +547,38 @@ if action == "info" then
end end
luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id.."/info")) luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id.."/info"))
end end
-- info end
elseif action == "resources" then elseif action == "resources" then
local resources_section= m:section(SimpleSection) local s = m:section(SimpleSection)
d = resources_section:option( Value, "cpus", translate("CPUs"), translate("Number of CPUs. Number is a fractional number. 0.000 means no limit.")) o = s:option( Value, "cpus",
d.placeholder = "1.5" translate("CPUs"),
d.rmempty = true translate("Number of CPUs. Number is a fractional number. 0.000 means no limit."))
d.datatype="ufloat" o.placeholder = "1.5"
d.default = container_info.HostConfig.NanoCpus / (10^9) o.rmempty = true
o.datatype="ufloat"
o.default = container_info.HostConfig.NanoCpus / (10^9)
d = resources_section:option(Value, "cpushares", translate("CPU Shares Weight"), translate("CPU shares relative weight, if 0 is set, the system will ignore the value and use the default of 1024.")) o = s:option(Value, "cpushares",
d.placeholder = "1024" translate("CPU Shares Weight"),
d.rmempty = true translate("CPU shares relative weight, if 0 is set, the system will ignore the value and use the default of 1024."))
d.datatype="uinteger" o.placeholder = "1024"
d.default = container_info.HostConfig.CpuShares o.rmempty = true
o.datatype="uinteger"
o.default = container_info.HostConfig.CpuShares
d = resources_section:option(Value, "memory", translate("Memory"), translate("Memory limit (format: <number>[<unit>]). Number is a positive integer. Unit can be one of b, k, m, or g. Minimum is 4M.")) o = s:option(Value, "memory",
d.placeholder = "128m" translate("Memory"),
d.rmempty = true translate("Memory limit (format: <number>[<unit>]). Number is a positive integer. Unit can be one of b, k, m, or g. Minimum is 4M."))
d.default = container_info.HostConfig.Memory ~=0 and ((container_info.HostConfig.Memory / 1024 /1024) .. "M") or 0 o.placeholder = "128m"
o.rmempty = true
o.default = container_info.HostConfig.Memory ~=0 and ((container_info.HostConfig.Memory / 1024 /1024) .. "M") or 0
d = resources_section:option(Value, "blkioweight", translate("Block IO Weight"), translate("Block IO weight (relative weight) accepts a weight value between 10 and 1000.")) o = s:option(Value, "blkioweight",
d.placeholder = "500" translate("Block IO Weight"),
d.rmempty = true translate("Block IO weight (relative weight) accepts a weight value between 10 and 1000."))
d.datatype="uinteger" o.placeholder = "500"
d.default = container_info.HostConfig.BlkioWeight o.rmempty = true
o.datatype="uinteger"
o.default = container_info.HostConfig.BlkioWeight
m.handle = function(self, state, data) m.handle = function(self, state, data)
if state == FORM_VALID then if state == FORM_VALID then
@ -452,12 +598,14 @@ elseif action == "resources" then
end end
end end
end end
request_body = { request_body = {
BlkioWeight = tonumber(data.blkioweight), BlkioWeight = tonumber(data.blkioweight),
NanoCPUs = tonumber(data.cpus)*10^9, NanoCPUs = tonumber(data.cpus)*10^9,
Memory = tonumber(memory), Memory = tonumber(memory),
CpuShares = tonumber(data.cpushares) CpuShares = tonumber(data.cpushares)
} }
docker:write_status("Containers: update " .. container_id .. "...") docker:write_status("Containers: update " .. container_id .. "...")
local res = dk.containers:update({id = container_id, body = request_body}) local res = dk.containers:update({id = container_id, body = request_body})
if res and res.code >= 300 then if res and res.code >= 300 then
@ -468,6 +616,7 @@ elseif action == "resources" then
luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id.."/resources")) luci.http.redirect(luci.dispatcher.build_url("admin/docker/container/"..container_id.."/resources"))
end end
end end
elseif action == "file" then elseif action == "file" then
local filesection= m:section(SimpleSection) local filesection= m:section(SimpleSection)
m.submit = false m.submit = false
@ -489,12 +638,14 @@ elseif action == "logs" then
stderr = 1, stderr = 1,
tail = 1000 tail = 1000
} }
local logs = dk.containers:logs({id = container_id, query = query}) local logs = dk.containers:logs({id = container_id, query = query})
if logs.code == 200 then if logs.code == 200 then
logsection.syslog=logs.body logsection.syslog=logs.body
else else
logsection.syslog="Get Logs ERROR\n"..logs.code..": "..logs.body logsection.syslog="Get Logs ERROR\n"..logs.code..": "..logs.body
end end
logsection.title=translate("Container Logs") logsection.title=translate("Container Logs")
logsection.template = "dockerman/logs" logsection.template = "dockerman/logs"
m.submit = false m.submit = false
@ -517,11 +668,13 @@ elseif action == "console" then
vcommand.write = function(self, section, value) vcommand.write = function(self, section, value)
cmd = value cmd = value
end end
local vuid = consolesection:option(Value, "uid", translate("UID")) local vuid = consolesection:option(Value, "uid", translate("UID"))
vuid.forcewrite = true vuid.forcewrite = true
vuid.write = function(self, section, value) vuid.write = function(self, section, value)
uid = value uid = value
end end
local btn_connect = consolesection:option(Button, "connect") local btn_connect = consolesection:option(Button, "connect")
btn_connect.render = function(self, section, scope) btn_connect.render = function(self, section, scope)
self.inputstyle = "add" self.inputstyle = "add"
@ -572,7 +725,16 @@ elseif action == "stats" then
stat_section = m:section(SimpleSection) stat_section = m:section(SimpleSection)
stat_section.container_id = container_id stat_section.container_id = container_id
stat_section.template = "dockerman/container_stats" stat_section.template = "dockerman/container_stats"
table_stats = {cpu={key=translate("CPU Useage"),value='-'},memory={key=translate("Memory Useage"),value='-'}} table_stats = {
cpu={
key=translate("CPU Useage"),
value='-'
},
memory={
key=translate("Memory Useage"),
value='-'
}
}
stat_section = m:section(Table, table_stats, translate("Stats")) stat_section = m:section(Table, table_stats, translate("Stats"))
stat_section:option(DummyValue, "key", translate("Stats")).width="33%" stat_section:option(DummyValue, "key", translate("Stats")).width="33%"
stat_section:option(DummyValue, "value") stat_section:option(DummyValue, "value")