diff --git a/README.md b/README.md index fa7489f..9f06afb 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,14 @@ rounds: # rounds to run continuously, each round will be an iteration tx_size: 200 ``` +#### Generating Config Files + +To generate a config file from a template, you can use the `tmpl.py` script: + +```bash +python3 ./scripts/tmpl.py ./tmpl/hotshot.testrpc.yaml.j2 ./tmpl/values/hotshot.yaml --num-nodes 10 +``` + ## Usage diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..df67e0d --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,2 @@ +jinja2 +pyyaml \ No newline at end of file diff --git a/scripts/tmpl.py b/scripts/tmpl.py new file mode 100644 index 0000000..5bffa9d --- /dev/null +++ b/scripts/tmpl.py @@ -0,0 +1,39 @@ +import argparse +import jinja2 +import yaml + +def render_template(template_path, values_path, num_nodes = 5): + """ + Renders a Jinja2 template with variables from a YAML file and prints the output. + + Args: + template_path (str): The path to the Jinja2 template file. + values_path (str): The path to the YAML file with variables. + --num-nodes (int): The number of nodes to create. + """ + try: + with open(values_path, 'r') as f: + values = yaml.safe_load(f) + + values['num_nodes'] = num_nodes + template_loader = jinja2.FileSystemLoader(searchpath="./") + env = jinja2.Environment(loader=template_loader) + template = env.get_template(template_path) + + rendered_output = template.render(values) + print(rendered_output) + except FileNotFoundError as e: + print(f"Error: {e}") + except jinja2.exceptions.TemplateError as e: + print(f"Template rendering error: {e}") + except yaml.YAMLError as e: + print(f"YAML parsing error: {e}") + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Render a Jinja2 template with variables from a YAML file.") + parser.add_argument("tmpl", help="The path to the Jinja2 template file.") + parser.add_argument("values", help="The path to the YAML file with variables.") + parser.add_argument("--num-nodes", type=int, default=5, help="The number of nodes to create.") + + args = parser.parse_args() + render_template(args.tmpl, args.values, args.num_nodes) \ No newline at end of file diff --git a/tmpl/hotshot.testrpc.yaml.j2 b/tmpl/hotshot.testrpc.yaml.j2 new file mode 100644 index 0000000..12a01e6 --- /dev/null +++ b/tmpl/hotshot.testrpc.yaml.j2 @@ -0,0 +1,23 @@ +interval: 1 +iterations: 100 +adapter: hotshot +args: +{%- if coordinator_addr %} + coordinator_url: {{ coordinator_addr }}:3030 +{%- endif %} +num_of_nodes: {{ num_nodes }} +{%- if node_addr_tmpl %} +rpcs: +{%- for i in range(1, num_nodes + 1) %} + - http://{{ node_addr_tmpl | format(i) }}:{{ i + 5000 }} +{%- endfor %} +{%- endif %} +round_templates: + tmpl: + txs: {{ tx_per_sec }} + tx_size: {{ tx_size }} +rounds: +{%- for i in range(0, num_nodes) %} + - rpcs: [{{ i }}] + use_template: tmpl +{%- endfor %} \ No newline at end of file diff --git a/tmpl/values/hotshot.yaml b/tmpl/values/hotshot.yaml new file mode 100644 index 0000000..829bc32 --- /dev/null +++ b/tmpl/values/hotshot.yaml @@ -0,0 +1,4 @@ +coordinator_addr: coordinator +node_addr_tmpl: hotshot-%d +tx_per_sec: 100 +tx_size: 1000 \ No newline at end of file