Merge "Fix a typo in deployed-server/README.rst"
[apex-tripleo-heat-templates.git] / docker / copy-json.py
1 #!/bin/python
2 import json
3 import os
4
5 data = {}
6 file_perms = '0600'
7 libvirt_perms = '0644'
8
9 libvirt_config = os.getenv('libvirt_config').split(',')
10 nova_config = os.getenv('nova_config').split(',')
11 neutron_openvswitch_agent_config = os.getenv('neutron_openvswitch_agent_config').split(',')
12
13 # Command, Config_files, Owner, Perms
14 services = {
15     'nova-libvirt': [
16         '/usr/sbin/libvirtd',
17         libvirt_config,
18         'root',
19         libvirt_perms],
20     'nova-compute': [
21         '/usr/bin/nova-compute',
22         nova_config,
23         'nova',
24         file_perms],
25     'neutron-openvswitch-agent': [
26         '/usr/bin/neutron-openvswitch-agent',
27         neutron_openvswitch_agent_config,
28         'neutron',
29         file_perms],
30     'ovs-vswitchd': [
31         '/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --log-file=/var/log/kolla/openvswitch/ovs-vswitchd.log'],
32     'ovsdb-server': [
33         '/usr/sbin/ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/run/openvswitch/db.sock --remote=ptcp:6640:127.0.0.1 --log-file=/var/log/kolla/openvswitch/ovsdb-server.log']
34 }
35
36
37 def build_config_files(config, owner, perms):
38     config_source = '/var/lib/kolla/config_files/'
39     config_files_dict = {}
40     source = os.path.basename(config)
41     dest = config
42     config_files_dict.update({'source': config_source + source,
43                               'dest': dest,
44                               'owner': owner,
45                               'perm': perms})
46     return config_files_dict
47
48
49 for service in services:
50     if service != 'ovs-vswitchd' and service != 'ovsdb-server':
51         command = services.get(service)[0]
52         config_files = services.get(service)[1]
53         owner = services.get(service)[2]
54         perms = services.get(service)[3]
55         config_files_list = []
56         for config_file in config_files:
57             if service == 'nova-libvirt':
58                 command = command + ' --config ' + config_file
59             else:
60                 command = command + ' --config-file ' + config_file
61             data['command'] = command
62             config_files_dict = build_config_files(config_file, owner, perms)
63             config_files_list.append(config_files_dict)
64         data['config_files'] = config_files_list
65     else:
66         data['command'] = services.get(service)[0]
67         data['config_files'] = []
68
69     json_config_dir = '/var/lib/etc-data/json-config/'
70     with open(json_config_dir + service + '.json', 'w') as json_file:
71         json.dump(data, json_file, sort_keys=True, indent=4,
72                   separators=(',', ': '))