Align template defaults with the client
[apex-tripleo-heat-templates.git] / docker / generate_json_config.sh
1 #!/bin/bash
2
3 KOLLA_DEST=/var/lib/kolla/config_files
4 JSON_DEST=/var/lib/etc-data/json-config
5
6 # For more config file generation, simply define a new SERVICE_DATA_
7 # prefixed variable. The command string is quoted to include config-file
8 # arguments. Note that the variable name following SERVICE_DATA_ will be
9 # the filename the JSON config is written to.
10
11 # [EXAMPLE]: SERVICE_DATA_<SERVICE_NAME>=(<command> <source> <dest> <owner> <perms>)
12
13 SERVICE_DATA_NOVA_LIBVIRT=("/usr/sbin/libvirtd" libvirtd.conf /etc/libvirt/libvirtd.conf root 0644)
14 SERVICE_DATA_NOVA_COMPUTE=("/usr/bin/nova-compute" nova.conf /etc/nova/nova.conf nova 0600)
15 SERVICE_DATA_NEUTRON_OPENVSWITCH_AGENT=("/usr/bin/neutron-openvswitch-agent --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini" neutron.conf /etc/neutron/neutron.conf neutron 0600 ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini neutron 0600)
16 SERVICE_DATA_NEUTRON_AGENT=("/usr/bin/neutron-openvswitch-agent --config-file /usr/share/neutron/neutron-dist.conf --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini" neutron.conf /etc/neutron/neutron.conf neutron 0600 ovs_neutron_plugin.ini /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini neutron 0600)
17 SERVICE_DATA_OVS_VSWITCHD=("/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --log-file=/var/log/openvswitch/ovs-vswitchd.log")
18 SERVICE_DATA_OVS_DBSERVER=("/usr/sbin/ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/run/openvswitch/db.sock --log-file=/var/log/openvswitch/ovsdb-server.log")
19
20 function create_json_header() {
21     local command=$1
22
23     echo "\
24 {
25     \"command\": \"${command[@]}\","
26
27 }
28
29 function create_config_file_header() {
30     echo "    \"config_files\": ["
31 }
32
33 function create_config_file_block() {
34     local source=$KOLLA_DEST/$1
35     local dest=$2
36     local owner=$3
37     local perm=$4
38
39     printf "\
40 \t{
41 \t    \"source\": \"$source\",
42 \t    \"dest\": \"$dest\",
43 \t    \"owner\": \"$owner\",
44 \t    \"perm\": \"$perm\"
45 \t}"
46 }
47
48 function add_trailing_comma() {
49     printf ", \n"
50 }
51
52 function create_config_file_trailer() {
53     echo -e "\n    ]"
54 }
55
56 function create_json_trailer() {
57     echo "}"
58 }
59
60 function create_json_data() {
61     local config_data=$1
62     shift
63
64     create_json_header "$config_data"
65     create_config_file_header
66     while [ "$1" ]; do
67         create_config_file_block "$@"
68         shift 4
69         if [ "$1" ]; then
70             add_trailing_comma
71         fi
72     done
73     create_config_file_trailer
74     create_json_trailer
75 }
76
77 function write_json_data() {
78
79     local name=$1[@]
80     local service_data=("${!name}")
81
82     local service_name=${1#SERVICE_DATA_} # chop SERVICE_DATA_ prefix
83     service_name=${service_name//_/-}     # switch underscore to dash
84     service_name=${service_name,,}        # change to lowercase
85
86     echo "Creating JSON file ${service_name}"
87     create_json_data "${service_data[@]}" > "$JSON_DEST/$service_name.json"
88 }
89
90 function process_configs() {
91     for service in ${!SERVICE_DATA_*}; do
92         write_json_data "${service}"
93     done
94 }
95
96 process_configs