2018-02-05 08:47:07 +00:00
|
|
|
local mymodule = {}
|
|
|
|
|
|
|
|
posix = require("posix")
|
|
|
|
fs = require("acf.fs")
|
2018-08-28 10:55:33 +00:00
|
|
|
json = require('cjson')
|
|
|
|
modelfunctions = require("modelfunctions")
|
2018-02-05 08:47:07 +00:00
|
|
|
|
2018-08-28 10:55:33 +00:00
|
|
|
local outletsConfigfile = "/etc/openpdu/outlets.conf"
|
|
|
|
local boardsConfigfile = "/etc/openpdu/boards.conf"
|
|
|
|
local s = modelfunctions.run_executable({"/usr/bin/openpdu", "outlets", "-j"})
|
|
|
|
local o = json.decode(s)
|
|
|
|
local outlets = {}
|
2018-02-05 08:47:07 +00:00
|
|
|
|
2018-08-28 10:55:33 +00:00
|
|
|
for Index, Value in pairs( o.outlets ) do
|
|
|
|
if (Value.powerstatus) then
|
|
|
|
s = "On"
|
|
|
|
else
|
|
|
|
s = "Off"
|
|
|
|
end
|
|
|
|
outlets[Value.outlet+1] = {outlet=Value.outlet,status=s,description=Value.description,actions={"on","off"}}
|
2018-02-05 08:47:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-28 10:55:33 +00:00
|
|
|
mymodule.status = function()
|
|
|
|
return cfe({ type="structure", value=outlets, label="Outlets" })
|
|
|
|
end
|
|
|
|
|
|
|
|
mymodule.setpower = function(outlet, power, ret)
|
|
|
|
return modelfunctions.run_executable({"/usr/bin/openpdu", "setpower", outlet, power})
|
2018-02-05 08:47:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mymodule.get_setpower = function(self, clientdata)
|
2018-08-28 10:55:33 +00:00
|
|
|
local outlet = cfe({label="Outlet", value=clientdata.outlet or ""})
|
|
|
|
return cfe({ type="group", label="Set Outlet Power state", value={outlet=outlet} })
|
2018-02-05 08:47:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
mymodule.setpoweron = function(self, r)
|
2018-08-28 10:55:33 +00:00
|
|
|
mymodule.setpower(r.value.outlet.value, 1, r)
|
2018-02-05 08:47:07 +00:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
mymodule.setpoweroff = function(self, r)
|
2018-08-28 10:55:33 +00:00
|
|
|
mymodule.setpower(r.value.outlet.value, 0, r)
|
2018-02-05 08:47:07 +00:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
2018-08-28 10:55:33 +00:00
|
|
|
function mymodule.get_outletsFiledetails()
|
|
|
|
return modelfunctions.getfiledetails(outletsConfigfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mymodule.update_outletsFiledetails(self, filedetails)
|
|
|
|
return modelfunctions.setfiledetails(self, filedetails, {outletsConfigfile})
|
|
|
|
end
|
|
|
|
|
|
|
|
function mymodule.get_boardsFiledetails()
|
|
|
|
return modelfunctions.getfiledetails(boardsConfigfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mymodule.update_boardsFiledetails(self, filedetails)
|
|
|
|
return modelfunctions.setfiledetails(self, filedetails, {boardsConfigfile})
|
|
|
|
end
|
|
|
|
|
2018-02-05 08:47:07 +00:00
|
|
|
return mymodule
|