blob: 5cb482bb08ba3221bbfffe40d797f86569439159 [file] [log] [blame]
YongchaoWu4e489b02020-02-24 09:18:16 +01001import json
2import subprocess
3import os
4
5print("Update fresh ric configuration in Consul configuration file")
6
7p = os.path.abspath('..')
8consul_config = p + '/consul_cbs' + '/config.json'
9
10
11def write_json(data, filename=consul_config):
12 with open(filename, 'w') as f:
13 json.dump(data, f, indent=4)
14
15
16def bash_command(cmd):
17 result = []
18 sp = subprocess.Popen(['/bin/bash', '-c', cmd], stdout=subprocess.PIPE)
19 for line in sp.stdout.readlines():
20 result.append(line.decode().strip())
21 return result
22
23
24command = "docker ps | grep simulator | awk '{print $NF}'"
25
26ric_list = bash_command(command)
27
28with open(consul_config) as json_file:
29 data = json.load(json_file)
30 temp = data['ric']
31 for ric in ric_list:
32 y = {"name": ric,
33 "baseUrl": "http://" + ric + ":8085/",
34 "managedElementIds": [
35 "kista_" + ric,
36 "stockholm_" + ric
37 ]
38 }
39 temp.append(y)
40
41
42write_json(data)
43print("Update Consul config file with fresh ric configuration, done")