summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-11-12 01:49:58 +0100
committerMagnus Ahltorp <map@kth.se>2015-11-12 01:49:58 +0100
commitbf7a293a18f104a0bf625934bcdb000136e1ac5f (patch)
treef09727c576c993805f2187ddb398c7a7a43e6d44
parent0e58634a718acd025ac5f1ed9e385e064e530523 (diff)
Handle multiple node types for a node
-rwxr-xr-xtools/compileconfig.py119
1 files changed, 63 insertions, 56 deletions
diff --git a/tools/compileconfig.py b/tools/compileconfig.py
index 6d8e3d0..0d5d347 100755
--- a/tools/compileconfig.py
+++ b/tools/compileconfig.py
@@ -65,54 +65,66 @@ def parse_address(address):
return (parsed_address[0], int(parsed_address[1]))
def get_node_config(nodename, config):
- nodetype = None
- nodeconfig = None
+ nodetype = []
+ nodeconfig = {}
for t in ["frontendnodes", "storagenodes", "signingnodes", "mergenodes"]:
for node in config[t]:
if node["name"] == nodename:
- nodetype = t
- nodeconfig = node
- if nodeconfig == None:
+ nodetype.append(t)
+ nodeconfig[t] = node
+ if len(nodetype) == 0:
print >>sys.stderr, "Cannot find config for node", nodename
sys.exit(1)
- return (nodetype, nodeconfig)
+ if len(nodetype) >= 2 and set(nodetype) != set(["frontendnodes", "storagenodes"]):
+ print >>sys.stderr, "Node type unsupported:", nodetype
+ sys.exit(1)
+ return (set(nodetype), nodeconfig)
-def gen_http_servers(nodetype, nodeconfig, bind_address, bind_publicaddress, bind_publichttpaddress):
+def get_address(bind_address, nodeconfig):
if bind_address:
(host, port) = parse_address(bind_address)
else:
(_, port) = parse_address(nodeconfig["address"])
host = "0.0.0.0"
- if nodetype == "frontendnodes":
+ return (host, port)
+
+def gen_http_servers(nodetype, nodeconfig, bind_address, bind_publicaddress, bind_publichttpaddress):
+ http_servers = []
+ https_servers = []
+
+ if "frontendnodes" in nodetype and "mergenodes" in nodetype:
+ print >>sys.stderr, "cannot have both frontend node and merge node at the same time", nodetype
+ sys.exit(1)
+
+ if "frontendnodes" in nodetype:
+ (host, port) = get_address(bind_address, nodeconfig["frontendnodes"])
if bind_publicaddress:
(publichost, publicport) = parse_address(bind_publicaddress)
else:
(_, publicport) = parse_address(nodeconfig["publicaddress"])
publichost = "0.0.0.0"
- http_servers = []
- https_servers = []
if bind_publichttpaddress:
(publichttphost, publichttpport) = parse_address(bind_publichttpaddress)
http_servers.append((Symbol("external_http_api"), publichttphost, publichttpport, Symbol("v1")))
https_servers.append((Symbol("external_https_api"), publichost, publicport, Symbol("v1")))
https_servers.append((Symbol("frontend_https_api"), host, port, Symbol("frontend")))
- return (http_servers,
- https_servers)
-
- elif nodetype == "storagenodes":
- return ([],
- [(Symbol("storage_https_api"), host, port, Symbol("storage"))])
- elif nodetype == "signingnodes":
- return ([],
- [(Symbol("signing_https_api"), host, port, Symbol("signing"))])
- elif nodetype == "mergenodes":
- return ([],
- [(Symbol("frontend_https_api"), host, port, Symbol("frontend"))])
- else:
+ if "storagenodes" in nodetype:
+ (host, port) = get_address(bind_address, nodeconfig["storagenodes"])
+ https_servers.append((Symbol("storage_https_api"), host, port, Symbol("storage")))
+ if "signingnodes" in nodetype:
+ (host, port) = get_address(bind_address, nodeconfig["signingnodes"])
+ https_servers.append((Symbol("signing_https_api"), host, port, Symbol("signing")))
+ if "mergenodes" in nodetype:
+ (host, port) = get_address(bind_address, nodeconfig["mergenodes"])
+ https_servers.append((Symbol("frontend_https_api"), host, port, Symbol("frontend")))
+ if nodetype - set(["frontendnodes", "storagenodes", "signingnodes", "mergenodes"]):
print >>sys.stderr, "unknown nodetype", nodetype
sys.exit(1)
+ return (http_servers,
+ https_servers)
+
def allowed_clients_frontend(mergenodenames, primarymergenode):
return [
("/plop/v1/frontend/sendentry", mergenodenames),
@@ -198,9 +210,9 @@ def gen_config(nodename, config, localconfig):
catlfishconfig = []
plopconfig = []
- if nodetype in ("frontendnodes", "mergenodes"):
+ if nodetype & set(["frontendnodes", "mergenodes"]):
catlfishconfig.append((Symbol("known_roots_path"), localconfig["paths"]["knownroots"]))
- if nodetype == "frontendnodes":
+ if "frontendnodes" in nodetype:
if "sctcaching" in options:
catlfishconfig.append((Symbol("sctcache_root_path"), paths["db"] + "sctcache/"))
if "ratelimits" in localconfig:
@@ -230,39 +242,34 @@ def gen_config(nodename, config, localconfig):
plopconfig += [
(Symbol("db_backend"), Symbol(localconfig["dbbackend"])),
]
- assert nodetype == "mergenodes"
+ assert nodetype == set("mergenodes")
- if nodetype in ("frontendnodes", "storagenodes"):
+ print "nodetype", nodetype
+ if nodetype & set(["frontendnodes", "storagenodes"]):
plopconfig += [
(Symbol("entry_root_path"), paths["db"] + "certentries"),
- ]
- if nodetype == "frontendnodes":
- plopconfig += [
- (Symbol("index_path"), paths["db"] + "index"),
- ]
- elif nodetype == "storagenodes":
- plopconfig += [
- (Symbol("newentries_path"), paths["db"] + "newentries"),
- (Symbol("lastverifiednewentry_path"), paths["db"] + "lastverifiednewentry"),
- ]
- if nodetype in ("frontendnodes", "storagenodes"):
- plopconfig += [
(Symbol("entryhash_root_path"), paths["db"] + "entryhash"),
(Symbol("indexforhash_root_path"), paths["db"] + "certindex"),
]
- if nodetype == "frontendnodes":
+ if "frontendnodes" in nodetype:
plopconfig += [
+ (Symbol("index_path"), paths["db"] + "index"),
(Symbol("sth_path"), paths["db"] + "sth"),
(Symbol("sendsth_verified_path"), paths["db"] + "sendsth-verified"),
(Symbol("entryhash_from_entry"),
(Symbol("catlfish"), Symbol("entryhash_from_entry"))),
]
- if nodetype in ("frontendnodes", "mergenodes"):
+ if "storagenodes" in nodetype:
+ plopconfig += [
+ (Symbol("newentries_path"), paths["db"] + "newentries"),
+ (Symbol("lastverifiednewentry_path"), paths["db"] + "lastverifiednewentry"),
+ ]
+ if nodetype & set(["frontendnodes", "mergenodes"]):
plopconfig += [
(Symbol("verify_entry"),
(Symbol("catlfish"), Symbol("verify_entry"))),
]
- if nodetype == "mergenodes":
+ if "mergenodes" in nodetype:
plopconfig += [
(Symbol("verifiedsize_path"), paths["mergedb"] + "/verifiedsize"),
(Symbol("index_path"), paths["mergedb"] + "/logorder"),
@@ -278,33 +285,33 @@ def gen_config(nodename, config, localconfig):
allowed_clients = []
allowed_servers = []
+ services = set()
- if nodetype == "frontendnodes":
+ if "frontendnodes" in nodetype:
storagenodenames = [node["name"] for node in config["storagenodes"]]
plopconfig.append((Symbol("storage_nodes"), storagenodeaddresses))
plopconfig.append((Symbol("storage_nodes_quorum"), config["storage-quorum-size"]))
- services = [Symbol("ht")]
+ services.add(Symbol("ht"))
allowed_clients += allowed_clients_frontend(mergenodenames, primarymergenode)
- allowed_clients += allowed_clients_public()
+ allowed_clients += allowed_clients_public()
allowed_servers += allowed_servers_frontend([node["name"] for node in signingnodes], storagenodenames)
- elif nodetype == "storagenodes":
+ if "storagenodes" in nodetype:
allowed_clients += allowed_clients_storage(frontendnodenames, mergenodenames)
- services = []
- elif nodetype == "signingnodes":
+ if "signingnodes" in nodetype:
allowed_clients += allowed_clients_signing(frontendnodenames, primarymergenode)
services = [Symbol("sign")]
- elif nodetype == "mergenodes":
+ if "mergenodes" in nodetype:
storagenodenames = [node["name"] for node in config["storagenodes"]]
plopconfig.append((Symbol("storage_nodes"), storagenodeaddresses))
plopconfig.append((Symbol("storage_nodes_quorum"), config["storage-quorum-size"]))
- services = [Symbol("ht")]
+ services.add(Symbol("ht"))
allowed_clients += allowed_clients_mergesecondary(primarymergenode)
plopconfig += [
(Symbol("publickey_path"), paths["publickeys"]),
- (Symbol("services"), services),
+ (Symbol("services"), list(services)),
]
- if nodetype == "signingnodes":
+ if "signingnodes" in nodetype:
hsm = localconfig.get("hsm")
if "logprivatekey" in paths:
plopconfig.append((Symbol("log_private_key"), paths["logprivatekey"]))
@@ -317,11 +324,11 @@ def gen_config(nodename, config, localconfig):
(Symbol("log_public_key"), paths["logpublickey"]),
(Symbol("own_key"), (nodename, "%s/%s-private.pem" % (paths["privatekeys"], nodename))),
]
- if nodetype == "frontendnodes":
+ if "frontendnodes" in nodetype:
plopconfig.append((Symbol("signing_nodes"), signingnodeaddresses))
plopconfig += [
- (Symbol("allowed_clients"), allowed_clients),
- (Symbol("allowed_servers"), allowed_servers),
+ (Symbol("allowed_clients"), list(allowed_clients)),
+ (Symbol("allowed_servers"), list(allowed_servers)),
]
erlangconfig = [
@@ -330,7 +337,7 @@ def gen_config(nodename, config, localconfig):
(Symbol("lager"), lagerconfig),
(Symbol("plop"), plopconfig),
]
-
+
print >>configfile, gen_erlang(erlangconfig) + ".\n"
configfile.close()