2 Library generating configuration/initial files.
4 The purpose of this library is about to customize conf file creation for special
5 use cases while testing, e.g. non replicated shards.
12 def _parse_input(file_name):
13 """Parses given file and returns it's pyhocon object.
16 :param file_name: path to the filename
19 :returns pyhocon_obj: parsed content of the given file
21 return pyhocon.ConfigFactory.parse_file(file_name)
24 def generate_akka(original_file, node_idx=1, nodes_ip_list=["127.0.0.1"]):
25 """Generates akka.conf content.
28 :param original_file: path to the filename, normally expecting file from system/org/opendaylight...
29 sal-clustering-config-<version>-akkaconf.xml
30 :param node_idx: cluster node index for which the file is generated
31 :param nodes_ip_list: list of luster nodes ip addresses
34 :returns str: akka.conf content
37 conf = _parse_input(original_file)
38 conf["odl-cluster-data"]["akka"]["remote"]["netty"]["tcp"][
40 ] = nodes_ip_list[node_idx - 1]
42 u"akka.tcp://opendaylight-cluster-data@{}:2550".format(ip)
43 for ip in nodes_ip_list
45 conf["odl-cluster-data"]["akka"]["cluster"]["seed-nodes"] = seed_nodes
46 conf["odl-cluster-data"]["akka"]["cluster"]["roles"] = [
47 "member-{}".format(node_idx)
49 return pyhocon.tool.HOCONConverter.to_hocon(conf)
52 def generate_modules(original_file, name="", namespace=""):
53 """Generates modules.conf content.
55 If name and namespace parameters are filled, exactly one module item is added to the content of orginal file.
56 If more modules needed, then use this keyword more times with storing temp file after each addition and use
57 it as <original_file> in the next step.
60 :param original_files: path to the filename, normally expecting file from system/org/opendaylight...
61 sal-clustering-config-<version>-moduleconf.xml
62 :param name: name of the new, addional shard
63 :param namespace: namespace of the new, addional shard
66 :returns str: modules.conf content
68 conf = _parse_input(original_file)
69 if name != "" and namespace != "":
70 conf["modules"].append(
72 [("name", name), ("namespace", namespace), ("shard-strategy", "module")]
75 return pyhocon.tool.HOCONConverter.to_hocon(conf)
78 def generate_module_shards(original_file, nodes=1, shard_name="", replicas=[]):
79 """Generates module-shards.conf content.
81 If shard_name and replicas parameters are filled, exactly one shard item is added to the content of orginal file.
82 If more shards needed, then use this keyword more times with storing temp file after each addition and use it as
83 <original_file> in the next step.
86 :param file_name: path to the filename, normally expecting file from system/org/opendaylight...
87 sal-clustering-config-<version>-moduleshardconf.xml
88 :param: nodes: number of nodes in the cluster
89 :param shard_name: new name of the additional shard
90 :param replicas: list of member indexes which should keep shard replicas
93 :returns str: module-shards.conf content
95 conf = _parse_input(original_file)
96 for module_shard in conf["module-shards"]:
97 module_shard["shards"][0]["replicas"] = [
98 "member-{}".format(i + 1) for i in range(int(nodes))
100 if shard_name != "" and replicas != []:
101 conf["module-shards"].append(
104 ("name", shard_name),
110 ("name", shard_name),
113 ["member-{}".format(i) for i in replicas],
122 return pyhocon.tool.HOCONConverter.to_hocon(conf)