Browse Source

Some netconf-service renames and add initdb script for user use.

Adam Ierymenko 11 years ago
parent
commit
b8d29cb6ba

+ 75 - 0
netconf-service/initdb.js

@@ -0,0 +1,75 @@
+/*
+ * Populates a new Redis database with data, which can be edited below.
+ */
+
+var INIT_DATA = {
+	// Must be present in any database
+	"zt1": 1,
+
+	/* The network ID here must be set to the ZeroTier address of your netconf
+	 * master (the node where netconf-master will be running) plus an arbitrary
+	 * 24-bit network ID. This will create the full 16-digit network ID of the
+	 * network you will join. This must be in the object name and in the "id"
+	 * field within the object itself. */
+	"zt1:network:ffffffffff111111:~": {
+		"id": "ffffffffff111111",     // netconf master ZT address + 24-bit ID
+		"name": "zerotier-testnet",   // short name, no spaces or special chars
+		"desc": "Test Network",       // description
+		"infrastructure": 0,          // unused by netconf-master
+		"private": 0,                 // set to '1' to require member approval
+		"creationTime": 0,            // unuxed by netconf-master
+		"owner": "",                  // unused by netconf-master
+		"etherTypes": "0800,0806",    // hex ethernet frame types allowed
+		"enableBroadcast": 1,         // set to '1' to enable ff:ff:ff:ff:ff:ff
+		"v4AssignMode": "zt",         // 'zt' to assign, 'none' to let OS do it
+		"v4AssignPool": "28.0.0.0/7", // IPv4 net block / netmask bits
+		"v6AssignMode": "none"        // 'zt' to assign, 'none' to let OS do it
+	}
+};
+
+var config = require('./config.js');
+
+config.redisDb = 2;
+
+var async = require('async');
+var redis = require('redis');
+var DB = redis.createClient();
+DB.on("error",function(err) { console.error('redis query error: '+err); });
+DB.select(config.redisDb,function() {});
+
+DB.get("zt1",function(err,value) {
+	if ((value)&&(!err)) {
+		console.log("Redis database #"+config.redisDb+" appears to already contain data; flush it first!");
+		return process.exit(0);
+	}
+
+	async.eachSeries(Object.keys(INIT_DATA),function(key,next) {
+		var value = INIT_DATA[key];
+		if (typeof value === 'object') {
+			console.log(key);
+			async.eachSeries(Object.keys(value),function(hkey,next2) {
+				var hvalue = value[hkey];
+				if (hvalue === true)
+					hvalue = 1;
+				if (hvalue === false)
+					hvalue = 0;
+				if (typeof hvalue !== 'string')
+					hvalue = hvalue.toString();
+				console.log('\t'+hkey+': '+hvalue);
+				DB.hset(key,hkey,hvalue,next2);
+			},next);
+		} else if ((typeof value !== 'undefined')&&(value !== null)) {
+			if (value === true)
+				value = 1;
+			if (value === false)
+				value = 0;
+			if (typeof value !== 'string')
+				value = value.toString();
+			console.log(key+': '+value);
+			DB.set(key,value,next);
+		} else return next(null);
+	},function(err) {
+		console.log('Done!');
+		return process.exit(0);
+	});
+});

+ 0 - 0
netconf-service/index.js → netconf-service/netconf-master.js


+ 1 - 1
netconf-service/netconf.service

@@ -10,4 +10,4 @@ if [ ! -d ./services.d/netconf-service ]; then
 fi
 
 cd services.d/netconf-service
-exec node index.js
+exec node netconf-master.js

+ 1 - 1
netconf-service/package.json

@@ -2,7 +2,7 @@
   "name": "zt1-netconf-service",
   "version": "0.0.0",
   "description": "Worker in charge of issuing network configuration from ZeroTier One netconf masters",
-  "main": "index.js",
+  "main": "netconf-master.js",
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },