summaryrefslogtreecommitdiffstats
path: root/clover/tools/jmeter/yaml/render_slave.py
blob: cd9fd916490cecdbcbd1cac7210c2daa6fc57e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) Authors of Clover
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0

import argparse

from jinja2 import Template


def render_yaml(args):
    template_file = 'manifest.template'
    out_file = args['deploy_name'] + '.yaml'

    try:
        with open(template_file) as f:
            tmpl = Template(f.read())
        output = tmpl.render(
            image_path=args['image_path'],
            image_name=args['image_name'],
            image_tag=args['image_tag'],
            deploy_name=args['deploy_name'],
            replica_count=args['replica_count'],
            ssl_port=args['ssl_port'],
            rmi_port=args['rmi_port'],
            http_port=args['http_port']
        )
        with open(out_file, "wb") as fh:
            fh.write(output)
        return "Generated manifest for {}".format(args['deploy_name'])
    except Exception as e:
        print(e)
        return "Unable to generate manifest for {}".format(
                                        args['deploy_name'])


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
            '--image_name', default='clover-jmeter-slave',
            help='The image name to use')
    parser.add_argument(
            '--image_path', default='localhost:5000',
            help='The path to the image to use')
    parser.add_argument(
            '--image_tag', default='latest',
            help='The image tag to use')
    parser.add_argument(
            '--deploy_name', default='clover-jmeter-slave',
            help='The k8s deploy name to use')
    parser.add_argument(
            '--rmi_port', default='1099',
            help='The master-slave remote method invocation port')
    parser.add_argument(
            '--http_port', default='80',
            help='HTTP data-plane traffic')
    parser.add_argument(
            '--replica_count', default='3',
            help='Number of replicas in slave deployment')
    parser.add_argument(
            '--ssl_port', default='443',
            help='HTTPS data-plane traffic')

    args = parser.parse_args()
    print(render_yaml(vars(args)))