aboutsummaryrefslogtreecommitdiff
path: root/prepare-config.py
blob: b4644a8679ad853fa592f2c224d8ae5db7a5c9fc (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
#!/usr/bin/env python
import re
import sys
from string import Template

TEMPLATE_PATH = "templates/"
CONFIG_NAME = "config.py"
CONFIG_PATH = TEMPLATE_PATH + CONFIG_NAME
LAVA_CACHE_PATH = "/tmp/lava_multi_node_cache.txt"
ROOT = 'root'

if __name__ == '__main__':
    lava_cache_file = open(LAVA_CACHE_PATH, 'r')
    lava_cache = lava_cache_file.read()
    lava_cache_file.close()
    lava_cache_regexp = re.compile("^(?P<device_id>[a-zA-Z0-9_\-]+):(?P<key>\w+)=(?P<value>.*)$")
    print lava_cache
    lava_cache_match = lava_cache_regexp.search(lava_cache)
    ipaddr = None
    if lava_cache_match:
        ipaddr = lava_cache_match.group("value")
    else:
        sys.exit(1)
    config = open(CONFIG_PATH, "r")
    config_template = Template(config.read())
    config.close()
    dest_config = open(CONFIG_NAME, "w")
    dest_config.write(config_template.safe_substitute(ipaddr=ipaddr + ":5555"))
    dest_config.close()