This commit is contained in:
Morten V. Christiansen 2025-09-08 23:20:23 -04:00
commit 09d2c141f3
3 changed files with 119 additions and 0 deletions

111
Controller.lua Normal file
View File

@ -0,0 +1,111 @@
--controller
local lxp = require("lxp")
local lom = require("lxp.lom")
local inspect = require "inspect"
local easyhttp = require("easyhttp")
local urlencode = require("urlencode")
local _ENV=require "std.strict" (_G)
local live_nodes = {}
function node_start(child)
local host = child.attr.host
local nodetype = child.attr.nodetype
local nodename = child.attr.nodename
local args = child.attr.args --may be nil
local msg = "https://"..host.."/_django_App_start?nodetype=".."\""..nodetype.."\"".."?nodename=".."\""..nodename.."\""
if (args ~= nil) then
msg = msg .."?args=\""..args.."\""
end
local response, code, headers = easyhttp.request(msg)
#print(response)
#print(code)
#print(headers)
print( msg)
--send & handle resp
live_nodes[nodename]=host
end
function node_execute(child)
local nodename=child.attr.nodename
local host=live_nodes[nodename]
print ("https://"..host.."/_django_App_execute?nodename=".."\""..nodename.."\"")
local response, code, headers = easyhttp.request(msg)
end
function node_get_logs(child)
for a, b in pairs(live_nodes) do
print ("https://"..b.."/_django_App_get_logs?nodename=".."\""..a.."\"")
end
local file = io.open("logfil.txt", "w") -- "w" means write (overwrite)
file:write("Test OK")
file:close()
end
function node_check_test(child)
local file = io.open("logfil.txt", "r")
print(file:read("*a"))
end
function node_close(child)
local nodename=child.attr.nodename
local host=live_nodes[nodename]
print ("https://"..host.."/_django_App_close?nodename=".."\""..nodename.."\"")
local response, code, headers = easyhttp.request(msg)
end
function exec_child(child)
if (child.tag == "notetool-node-start") then
node_start(child)
elseif (child.tag == "notetool-node-execute") then
node_execute(child)
elseif (child.tag == "notetool-get-logs") then
node_get_logs(child)
elseif (child.tag == "nodetool-check-test") then
node_check_test(child)
elseif (child.tag == "nodetool-close-node") then
node_close(child)
end
end
--start
local filename
if (#arg<1) then
filename="commands.xml"
else
filename=arg[1]
end
--load data from filename
local xml_file = io.open(filename,"r")
local xml_string = xml_file:read("*a")
xml_file:close()
local xml_string = xml_string:gsub("[\r\n]", "")
local xml_tree = lom.parse("<root>"..xml_string.."</root>")
--print (inspect(xml_tree))
--now we have the xml iń an object. work through it
for i, child in ipairs(xml_tree) do
if type(child) == "table" then
--print("Child tag:", child.tag)
exec_child(child)
--for k, v in pairs(child.attr) do
--print(" -", k, v)
--end
end
end

7
commands.xml Normal file
View File

@ -0,0 +1,7 @@
<notetool-node-start host="10.137.0.13" nodetype="default" nodename="node1" args="host2 node2" />
<notetool-node-start host="10.137.0.13" nodetype="default" nodename="node2" />
<notetool-node-execute nodename="node1" />
<notetool-get-logs />
<nodetool-check-test />
<nodetool-close-node nodename="node1" />
<nodetool-close-node nodename="node2" />

1
logfil.txt Normal file
View File

@ -0,0 +1 @@
Test OK