Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nodes = {}
- local nodeIDs = {}
- local function initNodes()
- nodes = {}
- nodeIDs = {}
- end
- local function addNode(hostName, computerID)
- if not nodes[hostName] then
- nodes[hostName] = {
- type = hostName:match("^(%a+)_"),
- id = tonumber(hostName:match("_(%d+)$")),
- status = "UNKNOWN",
- stayOnline = false,
- storage = 0
- }
- nodeIDs[hostName] = computerID
- end
- end
- local function validateNodeStates()
- for hostName, node in pairs(nodes) do
- if node.stayOnline and node.status ~= "RUNNING" then
- print("Node " .. hostName .. " should be running. Toggling...")
- rednet.send(nodeIDs[hostName], { type = "toggle" }, PROTOCOL)
- node.status = "PENDING"
- elseif not node.stayOnline and node.status == "RUNNING" then
- print("Node " .. hostName .. " should be stopped. Toggling...")
- rednet.send(nodeIDs[hostName], { type = "toggle" }, PROTOCOL)
- node.status = "PENDING"
- end
- end
- sleep(5) -- Delay between validations
- end
- local function getNodes()
- return nodes
- end
- return {
- initNodes = initNodes,
- addNode = addNode,
- validateNodeStates = validateNodeStates,
- getNodes = getNodes,
- }
Advertisement
Add Comment
Please, Sign In to add comment