summaryrefslogtreecommitdiffstats
path: root/retiolum/bin/nodes-to-json.py
diff options
context:
space:
mode:
authormakefu <root@pigstarter.de>2013-02-08 10:10:43 +0000
committermakefu <root@pigstarter.de>2013-02-08 10:10:43 +0000
commit59ccc0fd871c4bbd12066f2f6aacf835a839885d (patch)
tree09bd178d2b9cb14225c402c0915cc560246c4e36 /retiolum/bin/nodes-to-json.py
parent453593943e41edc1b55372951af1e3b2768e59c0 (diff)
add nodes-to-json: parses retiolum/hosts folder into json
Diffstat (limited to 'retiolum/bin/nodes-to-json.py')
-rw-r--r--retiolum/bin/nodes-to-json.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/retiolum/bin/nodes-to-json.py b/retiolum/bin/nodes-to-json.py
new file mode 100644
index 00000000..ca9d3c8c
--- /dev/null
+++ b/retiolum/bin/nodes-to-json.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+def parse_hosts_path(path="/etc/tinc/retiolum/hosts"):
+ import os
+ import re
+
+ needle_addr = re.compile("Subnet\s*=\s*(.*)/[0-9]+")
+ needle_port = re.compile("Port\s*=\s*(.*)")
+ for f in os.listdir(path):
+ with open(path+"/"+f) as of:
+ addrs = []
+ port = "655"
+
+ for line in of.readlines():
+
+ addr_found = needle_addr.match(line)
+ if addr_found:
+ addrs.append(addr_found.group(1))
+
+ port_found = needle_port.match(line)
+ if port_found:
+ port = port_found.group(1)
+
+ if addrs : yield (f ,[(addr ,int(port)) for addr in addrs])
+
+
+
+if __name__ == "__main__":
+ """
+ usage
+ """
+ import json
+ import sys
+ db={}
+ for host,addrs in parse_hosts_path(sys.argv[1] if len(sys.argv) > 2 else "/etc/tinc/retiolum/hosts"):
+ db[host] = addrs
+ print(json.dumps(db))