summaryrefslogtreecommitdiff
path: root/openstack/usr/share/openstack/openstack-neutron-setup
blob: 17a4e9fda39d56fd4492b93dc0b4d30c2968ee85 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
#
# Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -xe

# Create required system users and groups

getent group neutron >/dev/null || groupadd -r --gid 166 neutron
getent passwd neutron >/dev/null || \
	useradd --uid 166 -r -g neutron -d /var/lib/neutron -s /sbin/nologin \
	-c "OpenStack Neutron Daemons" neutron

chown -R neutron:neutron /var/lib/neutron

# Create the keystone user and services
export OS_SERVICE_TOKEN=##KEYSTONE_TEMPORARY_ADMIN_TOKEN##
export OS_SERVICE_ENDPOINT='http://127.0.0.1:35357/v2.0'

keystone user-create --name ##NEUTRON_SERVICE_USER## --pass ##NEUTRON_SERVICE_PASSWORD##
keystone user-role-add --tenant service --user ##NEUTRON_SERVICE_USER## --role admin

keystone service-create --name neutron --type network --description "OpenStack Networking"
keystone endpoint-create  --service-id $(keystone service-list | awk '/ network / {print $2}') \
	    	          --publicurl ##NEUTRON_PUBLIC_URL## \
	                  --internalurl ##NEUTRON_INTERNAL_URL## \
	                  --adminurl ##NEUTRON_ADMIN_URL## \
			  --region regionOne

# neutron.conf configuration
service_tenant_id=$(keystone tenant-get service | grep id | tr -d " " | cut -d"|" -f3)
sed -i "s/##SERVICE_TENANT_ID##/$service_tenant_id/g" /etc/neutron/neutron.conf

# Neutron compute configuration
if [ ! -d /var/run/neutron ]; then
    mkdir -p /var/run/neutron
    chown -R neutron:neutron /var/run/neutron
fi

if [ ! -d /var/lock/neutron ]; then
    mkdir -p /var/lock/neutron
    chown -R neutron:neutron /var/lock/neutron
fi

if [ ! -d /var/log/neutron ]; then
    mkdir -p /var/log/neutron
    chown -R neutron:neutron /var/log/neutron
fi

# Setup the neutron database
if ! sudo -u postgres psql -lqt | grep -q neutron; then
    # Create postgresSQL user
    sudo -u postgres createuser \
	      --pwprompt --encrypted \
	      --no-adduser --no-createdb \
	      --no-password \
	      ##NEUTRON_DB_USER##
    sudo -u postgres createdb \
	      --owner=##NEUTRON_DB_USER## \
	      neutron
    # Stamp neutron database with the latest stamped version available,
    # in this case "icehouse"
    sudo -u neutron neutron-db-manage \
	              --config-file /etc/neutron/neutron.conf \
	              --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
	              stamp icehouse
    # Upgrade database to "juno"
    sudo -u neutron neutron-db-manage \
                      --config-file /etc/neutron/neutron.conf \
                      --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
                      upgrade juno
fi

# Remove the one-shot setup service
rm /etc/systemd/system/multi-user.target.wants/openstack-neutron-setup.service

# Start neutron services
systemctl start openstack-neutron-server
systemctl start openstack-neutron-metadata-agent
systemctl start openstack-neutron-plugin-openvswitch-agent
systemctl start openstack-neutron-ovs-cleanup
systemctl start openstack-neutron-dhcp-agent
systemctl start openstack-neutron-l3-agent

# Create the links to run neutron services when system start next times.
ln -s "/etc/systemd/system/openstack-neutron-server.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-server.service"

ln -s "/etc/systemd/system/openstack-neutron-metadata-agent.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-metadata-agent.service"

ln -s "/etc/systemd/system/openstack-neutron-plugin-openvswitch-agent.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-plugin-openvswitch-agent.service"

ln -s "/etc/systemd/system/openstack-neutron-ovs-cleanup.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-ovs-cleanup.service"

ln -s "/etc/systemd/system/openstack-neutron-dhcp-agent.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-dhcp-agent.service"

ln -s "/etc/systemd/system/openstack-neutron-l3-agent.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-neutron-l3-agent.service"

exit 0