summaryrefslogtreecommitdiff
path: root/openstack/usr/share/openstack/openstack-neutron-setup
blob: bcaa038f193d845469670a3ece963a21c17d787a (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/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 -e

# 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

# Create the keystone user and services

export OS_SERVICE_TOKEN=##KEYSTONE_TEMPORARY_ADMIN_TOKEN##
export OS_SERVICE_ENDPOINT='http://localhost: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 Compute Service"
keystone endpoint-create  --service-id $(keystone service-list | awk '/ network / {print $2}') \
	    	          --publicurl ##NEUTRON_PUBLIC_URL## \
	                  --internalurl ##NEUTRON_INTERNAL_URL## \
	                  --adminurl ##NEUTRON_ADMIN_URL##

# 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 [ ! -e /var/lib/neutron/neutron.sqlite ]; then
    chown -R neutron:neutron /var/lib/neutron
    # Stamp the database with the version of neutron we are using. This is
    # needed before we can run any neutron services.
    sudo -u neutron neutron-db-manage --config-file /etc/neutron/neutron.conf \
	      --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
	      stamp --sql juno
fi

# Create the openvswitch required folders
if [ ! -d /usr/local/var/run/openvswitch ]; then
    mkdir -p /usr/local/etc/openvswitch
    mkdir -p /usr/local/var/run/openvswitch
fi

# Define openvswitch files
openvswitch_database=/usr/local/etc/openvswitch/conf.db
openvswitch_pidfile=/usr/local/var/run/openvswitch/ovsdb-server.pid
openvswitch_logfile=/usr/local/var/run/openvswitch/ovsdb-server.log

# Create openvswitch database
ovsdb-tool create $openvswitch_database /usr/share/openvswitch/vswitch.ovsschema

# Start openvswitch database server
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
	     --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
	     --private-key=db:Open_vSwitch,SSL,private_key \
	     --certificate=db:Open_vSwitch,SSL,certificate \
	     --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
	     --pidfile --detach

ovs-vsctl --no-wait init

ovs-vswitchd --pidfile --detach
ovs-vsctl show

# Create the bridges to use the External network mapped
# This configuration is for 1 node and it was taken from:
# https://fosskb.wordpress.com/2014/10/18/openstack-juno-on-ubuntu-14-10/
# and https://fosskb.wordpress.com/2014/06/10/managing-openstack-internaldataexternal-network-in-one-interface/
ovs-vsctl add-br br-eth0
ovs-vsctl add-port br-eth0 ens3
ifconfig br-eth0 $(hostname -i | awk '{ print $1 }') up
ip link set br-eth0 promisc on
ip link add proxy-br-eth1 type veth peer name eth1-br-proxy
ip link add proxy-br-ex type veth peer name ex-br-proxy
ovs-vsctl add-br br-eth1
ovs-vsctl add-br br-ex
ovs-vsctl add-port br-eth1 eth1-br-proxy
ovs-vsctl add-port br-ex ex-br-proxy
ovs-vsctl add-port br-eth0 proxy-br-eth1
ovs-vsctl add-port br-eth0 proxy-br-ex
ip link set eth1-br-proxy up promisc on
ip link set ex-br-proxy up promisc on
ip link set proxy-br-eth1 up promisc on
ip link set proxy-br-ex up promisc on

# 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