Update neutron to 9.0.0~b3
[openstack-build/neutron-build.git] / xenial / debian / neutron-common.postinst.in
1 #!/bin/sh
2
3 set -e
4
5 N_CONF=/etc/neutron/neutron.conf
6 OVS_CONF=/etc/neutron/plugins/ml2/openvswitch_agent.ini
7
8 #PKGOS-INCLUDE#
9
10 neutron_core_plugin_class () {
11         case ${1} in
12         "OpenVSwitch"|"ml2"|"LinuxBridge"|"neutron.plugins.ml2.plugin.Ml2Plugin")
13                 NEUTRON_PLUGIN_CLASS=ml2
14         ;;
15         "networking_plumgrid.neutron.plugins.plugin:NeutronPluginPLUMgridV2"|"plumgrid")
16                 NEUTRON_PLUGIN_NAME=plumgrid
17         ;;
18         "midonet.neutron.plugin_v1:MidonetPluginV2"|"midonet")
19                 NEUTRON_PLUGIN_NAME=midonet
20         ;;
21         "midonet.neutron.plugin_v2:MidonetPluginV2"|"midonet_v2")
22                 NEUTRON_PLUGIN_NAME=midonet_v2
23         ;;
24         "networking_nec.nwa.l2.plugin:NECNWAL2Plugin"|"necnwa")
25                 NEUTRON_PLUGIN_NAME=nec
26         ;;
27         "vmware_nsx.plugin:NsxMhPlugin"|"vmware")
28                 NEUTRON_PLUGIN_NAME=vmware
29         ;;
30         *)
31                 NEUTRON_PLUGIN_CLASS=""
32         ;;
33         esac
34 }
35
36 write_nova_admin_credentials () {
37         db_get neutron/nova_url
38         pkgos_inifile set ${N_CONF} nova url ${RET}
39
40         db_get neutron/nova_region
41         pkgos_inifile set ${N_CONF} nova region_name ${RET}
42
43         db_get neutron/nova_admin_tenant_name
44         NOVA_TENANT_NAME_IN_NEUTRON=${RET}
45         pkgos_inifile set ${N_CONF} nova tenant_name ${RET}
46         pkgos_inifile set ${N_CONF} nova project_name ${RET}
47
48         db_get neutron/nova_admin_username
49         pkgos_inifile set ${N_CONF} nova username ${RET}
50
51         db_get neutron/nova_admin_password
52         pkgos_inifile set ${N_CONF} nova password ${RET}
53 }
54
55 if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then
56         . /usr/share/debconf/confmodule
57
58         pkgos_var_user_group neutron
59         chmod 755 /var/lib/neutron
60
61         pkgos_write_new_conf neutron api-paste.ini
62         pkgos_write_new_conf neutron neutron.conf
63         chmod 0660 /etc/neutron/neutron.conf
64
65         # Sets the core_plugin directive according to the value in debconf
66         db_get neutron/plugin-select
67         NEUTRON_plugin=${RET}
68         if [ -n "${RET}" ] ; then
69                 neutron_core_plugin_class ${NEUTRON_plugin}
70                 if [ -n "${NEUTRON_PLUGIN_CLASS}" ] ; then
71                         pkgos_inifile set ${N_CONF} DEFAULT core_plugin ${NEUTRON_PLUGIN_CLASS}
72                 fi
73         fi
74
75         # Write the neutron RabbitMQ credentials
76         pkgos_rabbit_write_conf ${N_CONF} oslo_messaging_rabbit neutron
77
78         # Set the keystone_authtoken directive
79         pkgos_write_admin_creds ${N_CONF} keystone_authtoken neutron
80
81         # Set the sql_connection directive
82         pkgos_dbc_postinst --suite neutron ${N_CONF} database connection neutron $@
83
84         db_get neutron/configure_db
85         if [ "$RET" = "true" ] ; then
86                 # Migrating to latest release of the db
87                 neutron-db-manage --config-file /etc/neutron/neutron.conf upgrade head
88         fi
89
90         # Maintain the OVS config
91         if [ ! -e ${OVS_CONF} ] ; then
92                 install -D -m 0640 -o neutron -g neutron /usr/share/neutron-common/openvswitch_agent.ini ${OVS_CONF}
93         fi
94
95         if [ "${NEUTRON_plugin_path}" = "OpenVSwitch" ] ; then
96                 db_get neutron/tenant_network_type
97                 pkgos_inifile set ${OVS_CONF} OVS tenant_network_type "${RET}"
98
99                 db_get neutron/enable_tunneling
100                 pkgos_inifile set ${OVS_CONF} OVS enable_tunneling "${RET}"
101
102                 db_get neutron/tunnel_id_ranges
103                 pkgos_inifile set ${OVS_CONF} OVS tunnel_id_ranges "${RET}"
104
105                 db_get neutron/local_ip
106                 pkgos_inifile set ${OVS_CONF} OVS local_ip "${RET}"
107         fi
108
109         write_nova_admin_credentials
110         db_stop
111
112         chown -R neutron:adm /var/log/neutron/
113         chmod 0700 /etc/neutron
114         chmod 0750 /var/log/neutron/
115         chown root:root /etc/neutron/rootwrap.conf
116         chown root:root /etc/neutron/rootwrap.d
117         chmod 0755 /etc/neutron/rootwrap.d
118
119         # The /var/lib/neutron/dhcp needs to be readable from the nobody user.
120         chmod 755 /var/lib/neutron
121         mkdir -p /var/lib/neutron/dhcp
122         chown neutron:neutron /var/lib/neutron/dhcp
123         chmod 755 /var/lib/neutron/dhcp
124
125         if [ -f /etc/sudoers.d/neutron_sudoers ] ; then
126                 chmod 0440 /etc/sudoers.d/neutron_sudoers
127         fi
128 fi
129
130 #DEBHELPER#