-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'libremesh:master' into refstate
- Loading branch information
Showing
11 changed files
with
204 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (C) 2023 Javier Jorge <[email protected]> | ||
# Copyright (C) 2023 Asociación Civil Altermundi <[email protected]> | ||
# This is free software, licensed under the GNU Affero General Public License v3. | ||
# | ||
|
||
include ../../libremesh.mk | ||
|
||
define Package/$(PKG_NAME) | ||
SECTION:=lime | ||
CATEGORY:=LibreMesh | ||
TITLE:=Node information module for shared-state | ||
MAINTAINER:= Javier <[email protected]> | ||
DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ | ||
+lime-system +ubus-lime-location shared-state | ||
PKGARCH:=all | ||
endef | ||
|
||
define Package/$(PKG_NAME)/description | ||
Syncronize node information beween nodes. | ||
endef | ||
|
||
$(eval $(call BuildPackage,$(PKG_NAME))) |
1 change: 1 addition & 0 deletions
1
...s/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../usr/bin/shared-state-publish_node_info |
9 changes: 9 additions & 0 deletions
9
packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
unique_append() | ||
{ | ||
grep -qF "$1" "$2" || echo "$1" >> "$2" | ||
} | ||
|
||
unique_append \ | ||
'*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync node_info &> /dev/null)&)'\ | ||
/etc/crontabs/root |
46 changes: 46 additions & 0 deletions
46
packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/lua | ||
|
||
--! LibreMesh | ||
--! Copyright (C) 2023 Javier Jorge <[email protected]> | ||
--! Copyright (C) 2023 Asociación Civil Altermundi <[email protected]> | ||
--! | ||
--! This program is free software: you can redistribute it and/or modify | ||
--! it under the terms of the GNU Affero General Public License as | ||
--! published by the Free Software Foundation, either version 3 of the | ||
--! License, or (at your option) any later version. | ||
--! | ||
--! This program is distributed in the hope that it will be useful, | ||
--! but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
--! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
--! GNU Affero General Public License for more details. | ||
--! | ||
--! You should have received a copy of the GNU Affero General Public License | ||
--! along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
local JSON = require("luci.jsonc") | ||
local network = require ("lime.network") | ||
local location = require("lime.location") | ||
local utils = require('lime.utils') | ||
local config = require("lime.config") | ||
|
||
local hostname = utils.hostname() | ||
function get_node_info() | ||
local uci = config.get_uci_cursor() | ||
local coords = location.get_node() or location.get_community() or | ||
{lat="FIXME", long="FIXME"} | ||
local fw_version = "no version" | ||
pcall(function () fw_version = utils.release_info()['DISTRIB_RELEASE'] end) | ||
local board = "no board" | ||
pcall(function () board = utils.current_board() end) | ||
local ipv4 = uci:get("network", "lan", "ipaddr") | ||
local ipv6 = uci:get("network", "lan", "ip6addr") | ||
if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end | ||
local uptime = utils.uptime_s() | ||
local macs = network.get_own_macs("*") | ||
return {hostname=hostname, firmware_version=fw_version, board=board, | ||
ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime, | ||
device = "Router" } | ||
end | ||
|
||
local result = { [hostname] = get_node_info() } | ||
io.popen("shared-state insert node_info", "w"):write(JSON.stringify(result)) |
33 changes: 33 additions & 0 deletions
33
packages/shared-state-node_info/tests/test_shared-state-node_info.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local JSON = require("luci.jsonc") | ||
local test_utils = require('tests.utils') | ||
local utils = require('lime.utils') | ||
|
||
local uci = nil | ||
|
||
package.path = package.path .. ";packages/shared-state-node_info/files/usr/bin/?;;" | ||
require ("shared-state-publish_node_info") | ||
|
||
describe('Tests network_nodes #network_nodes', function () | ||
before_each('', function() | ||
uci = test_utils.setup_test_uci() | ||
stub(utils, "release_info", function () return {DISTRIB_RELEASE='2021.1'} end) | ||
stub(utils, "current_board", function () return 'devboard' end) | ||
end) | ||
|
||
after_each('', function() | ||
test_utils.teardown_test_uci(uci) | ||
end) | ||
|
||
it('a simple test to get node info and assert requiered fields are present', function() | ||
uci = config.get_uci_cursor() | ||
uci:set('network', 'lan', 'interface') | ||
uci:set('network', 'lan', 'ipaddr', '10.5.0.5') | ||
uci:set('network', 'lan', 'ip6addr', 'fd0d:fe46:8ce8::ab:cd00/64') | ||
uci:commit('network') | ||
nodeinfo = get_node_info() | ||
assert.are.equal('devboard', nodeinfo.board) | ||
assert.are.equal('2021.1', nodeinfo.firmware_version) | ||
assert.are.equal('10.5.0.5', nodeinfo.ipv4) | ||
assert.are.equal('fd0d:fe46:8ce8::ab:cd00', nodeinfo.ipv6) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters