summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-04-14 13:10:36 +0000
committerFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>2015-04-14 16:36:12 +0000
commitc27edd805fdb6120684c45bdb9035d91586f268c (patch)
tree40a363a08f631773a41d14ec720f25dcad3281c7
parent666a79968f83a1ba45e7c2d4ad47d5939fa53af7 (diff)
downloaddefinitions-c27edd805fdb6120684c45bdb9035d91586f268c.tar.gz
Openstack: Add support to configure the network of the node
Signed-off-by: Pedro Alvarez <pedro.alvarez@codethink.co.uk> Signed-off-by: Richard Maw <richard.maw@codethink.co.uk> Change-Id: I215b4d0c23a9c1c82e3668b3f23a9f2766b3173a
-rw-r--r--openstack-network.configure37
-rw-r--r--openstack/manifest9
-rw-r--r--openstack/usr/lib/systemd/system/openstack-network-setup.service11
-rw-r--r--openstack/usr/lib/systemd/system/openvswitch-db-server.service11
-rw-r--r--openstack/usr/lib/systemd/system/openvswitch-setup.service10
-rw-r--r--openstack/usr/lib/systemd/system/openvswitch.service12
-rw-r--r--openstack/usr/share/openstack/extras/00-disable-device.network2
-rw-r--r--openstack/usr/share/openstack/extras/10-device-dhcp.network5
-rw-r--r--openstack/usr/share/openstack/network.yml123
-rw-r--r--openstack/usr/share/openstack/openvswitch.yml39
-rw-r--r--systems/openstack-server.morph1
11 files changed, 260 insertions, 0 deletions
diff --git a/openstack-network.configure b/openstack-network.configure
new file mode 100644
index 00000000..a4d43a6a
--- /dev/null
+++ b/openstack-network.configure
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2015 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, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+ROOT="$1"
+
+ln -sf "/usr/lib/systemd/system/openvswitch-setup.service" \
+ "$ROOT/etc/systemd/system/multi-user.target.wants/openvswitch-setup.service"
+
+ln -sf "/usr/lib/systemd/system/openstack-network-setup.service" \
+ "$ROOT/etc/systemd/system/multi-user.target.wants/openstack-network-setup.service"
+
+python <<'EOF' >"$ROOT/etc/openstack/network.conf"
+import os, sys, yaml
+
+network_configuration = {}
+
+optional_keys = ('EXTERNAL_INTERFACE',)
+
+network_configuration.update((k, os.environ[k]) for k in optional_keys if k in os.environ)
+
+yaml.dump(network_configuration, sys.stdout, default_flow_style=False)
+EOF
diff --git a/openstack/manifest b/openstack/manifest
index 6876f1ba..8cec2322 100644
--- a/openstack/manifest
+++ b/openstack/manifest
@@ -5,6 +5,9 @@
0100644 0 0 /usr/share/openstack/cinder/cinder.conf
0100644 0 0 /usr/share/openstack/cinder/api-paste.ini
0100644 0 0 /usr/share/openstack/cinder/policy.json
+0040755 0 0 /usr/share/openstack/extras
+0100644 0 0 /usr/share/openstack/extras/00-disable-device.network
+0100644 0 0 /usr/share/openstack/extras/10-device-dhcp.network
0100644 0 0 /usr/share/openstack/glance.yml
0040755 0 0 /usr/share/openstack/glance
0100644 0 0 /usr/share/openstack/glance/logging.conf
@@ -22,6 +25,7 @@
0100644 0 0 /usr/share/openstack/keystone/keystone.conf
0100644 0 0 /usr/share/openstack/keystone/policy.json
0100644 0 0 /usr/share/openstack/keystone/keystone-paste.ini
+0100644 0 0 /usr/share/openstack/network.yml
0040755 0 0 /usr/share/openstack/nova
0100644 0 0 /usr/share/openstack/nova.yml
0100644 0 0 /usr/share/openstack/nova/logging.conf
@@ -30,6 +34,7 @@
0100644 0 0 /usr/share/openstack/nova/policy.json
0100644 0 0 /usr/share/openstack/nova/cells.json
0100644 0 0 /usr/share/openstack/nova/api-paste.ini
+0100644 0 0 /usr/share/openstack/openvswitch.yml
0040755 0 0 /usr/share/openstack/postgres
0100644 0 0 /usr/share/openstack/postgres/pg_hba.conf
0100644 0 0 /usr/share/openstack/postgres/postgresql.conf
@@ -41,6 +46,7 @@
0100644 0 0 /usr/lib/systemd/system/openstack-glance-setup.service
0100644 0 0 /usr/lib/systemd/system/openstack-glance-api.service
0100644 0 0 /usr/lib/systemd/system/openstack-glance-registry.service
+0100644 0 0 /usr/lib/systemd/system/openstack-network-setup.service
0100644 0 0 /usr/lib/systemd/system/openstack-nova-setup.service
0100644 0 0 /usr/lib/systemd/system/openstack-nova-compute.service
0100644 0 0 /usr/lib/systemd/system/openstack-nova-conductor.service
@@ -56,4 +62,7 @@
0100644 0 0 /usr/lib/systemd/system/openstack-cinder-scheduler.service
0100644 0 0 /usr/lib/systemd/system/openstack-cinder-volume.service
0100644 0 0 /usr/lib/systemd/system/openstack-cinder-backup.service
+0100644 0 0 /usr/lib/systemd/system/openvswitch-setup.service
+0100644 0 0 /usr/lib/systemd/system/openvswitch-db-server.service
+0100644 0 0 /usr/lib/systemd/system/openvswitch.service
0100644 0 0 /usr/lib/systemd/system/postgres-server.service
diff --git a/openstack/usr/lib/systemd/system/openstack-network-setup.service b/openstack/usr/lib/systemd/system/openstack-network-setup.service
new file mode 100644
index 00000000..90c9ecf7
--- /dev/null
+++ b/openstack/usr/lib/systemd/system/openstack-network-setup.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Run Ansible scripts to configure internal network for OpenStack
+After=openvswitch.service openvswitch-setup.service
+Before=systemd-networkd.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/ansible-playbook -v -M /usr/share/ansible/ansible-openstack-modules -i /usr/share/openstack/hosts /usr/share/openstack/network.yml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/openstack/usr/lib/systemd/system/openvswitch-db-server.service b/openstack/usr/lib/systemd/system/openvswitch-db-server.service
new file mode 100644
index 00000000..7ea7942a
--- /dev/null
+++ b/openstack/usr/lib/systemd/system/openvswitch-db-server.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Open vSwitch Database Server Daemon
+After=local-fs.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/ovsdb-server --remote=punix:/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
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/openstack/usr/lib/systemd/system/openvswitch-setup.service b/openstack/usr/lib/systemd/system/openvswitch-setup.service
new file mode 100644
index 00000000..6fdd7db6
--- /dev/null
+++ b/openstack/usr/lib/systemd/system/openvswitch-setup.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run openvswitch-setup Ansible scripts
+After=local-fs.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/ansible-playbook -v -i /usr/share/openstack/hosts /usr/share/openstack/openvswitch.yml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/openstack/usr/lib/systemd/system/openvswitch.service b/openstack/usr/lib/systemd/system/openvswitch.service
new file mode 100644
index 00000000..6f1a93a8
--- /dev/null
+++ b/openstack/usr/lib/systemd/system/openvswitch.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Open vSwitch Daemon
+Wants=network-pre.target
+After=openvswitch-initialize-db.service
+Before=network-pre.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/ovs-vswitchd --pidfile --detach
+
+[Install]
+WantedBy=multi-user.target
diff --git a/openstack/usr/share/openstack/extras/00-disable-device.network b/openstack/usr/share/openstack/extras/00-disable-device.network
new file mode 100644
index 00000000..8e2532d0
--- /dev/null
+++ b/openstack/usr/share/openstack/extras/00-disable-device.network
@@ -0,0 +1,2 @@
+[Match]
+Name={{ item }}
diff --git a/openstack/usr/share/openstack/extras/10-device-dhcp.network b/openstack/usr/share/openstack/extras/10-device-dhcp.network
new file mode 100644
index 00000000..6fdbfd8d
--- /dev/null
+++ b/openstack/usr/share/openstack/extras/10-device-dhcp.network
@@ -0,0 +1,5 @@
+[Match]
+Name={{ item }}
+
+[Network]
+DHCP=yes
diff --git a/openstack/usr/share/openstack/network.yml b/openstack/usr/share/openstack/network.yml
new file mode 100644
index 00000000..955a617b
--- /dev/null
+++ b/openstack/usr/share/openstack/network.yml
@@ -0,0 +1,123 @@
+---
+- hosts: localhost
+ vars_files:
+ - /etc/openstack/network.conf
+ tasks:
+# 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/
+
+# Count number of network interfaces (interfaces starting with 'e')
+ - shell: ls /sys/class/net | grep ^e.* | wc -l
+ register: number_interfaces
+
+# Abort if there number of interfaces != 1
+ - fail:
+ msg: More than one, or none network interfaces found.
+ when: EXTERNAL_INTERFACE is not defined and number_interfaces.stdout != "1"
+
+ - shell: ls /sys/class/net | grep ^e.*
+ register: interface_name
+ when: EXTERNAL_INTERFACE is not defined
+
+ - set_fact:
+ ETH_INTERFACE: "{{ interface_name.stdout }}"
+ when: EXTERNAL_INTERFACE is not defined
+
+ - set_fact:
+ ETH_INTERFACE: "{{ EXTERNAL_INTERFACE }}"
+ when: EXTERNAL_INTERFACE is defined
+
+ - set_fact:
+ ETH_MAC_ADDRESS: "{{ hostvars['localhost']['ansible_' + ETH_INTERFACE]['macaddress'] }}"
+
+ - name: Create the /run/systemd/network
+ file:
+ path: /run/systemd/network
+ state: directory
+
+ - name: Disable dhcp on the bound physical interface
+ template:
+ src: /usr/share/openstack/extras/00-disable-device.network
+ dest: /run/systemd/network/00-disable-{{ item }}-config.network
+ with_items:
+ - "{{ ETH_INTERFACE }}"
+
+
+ - name: Disable dhcp on all the internal interfaces
+ template:
+ src: /usr/share/openstack/extras/00-disable-device.network
+ dest: /run/systemd/network/00-disable-{{ item }}-config.network
+ with_items:
+ - br-eth1
+ - br-ex
+ - eth1-br-proxy
+ - proxy-br-eth1
+ - proxy-br-ex
+ - ovs-system
+
+#ovs-vsctl \
+# -- add-br br-eth0 \
+# -- add-port br-eth0 $eth_dev \
+# -- set bridge br-eth0 other-config:hwaddr=$eth_mac
+#
+
+
+ - openvswitch_bridge:
+ bridge: br-eth0
+ state: present
+
+ - openvswitch_port:
+ bridge: br-eth0
+ port: "{{ ETH_INTERFACE }}"
+ state: present
+
+ - shell: ovs-vsctl set bridge br-eth0 other-config:hwaddr={{ ETH_MAC_ADDRESS }}
+
+ - name: Enable dhcp on the Open vSwitch device that replaces our external interface
+ template:
+ src: /usr/share/openstack/extras/10-device-dhcp.network
+ dest: /run/systemd/network/10-{{ item }}-dhcp.network
+ with_items:
+ - br-eth0
+
+#ovs-vsctl \
+# -- add-br br-eth1 \
+# -- add-port br-eth1 eth1-br-proxy \
+# -- set interface eth1-br-proxy type=patch options:peer=proxy-br-eth1 \
+# -- add-port br-eth0 proxy-br-eth1 \
+# -- set interface proxy-br-eth1 type=patch options:peer=eth1-br-proxy \
+# -- add-br br-ex \
+# -- add-port br-ex ex-br-proxy \
+# -- set interface ex-br-proxy type=patch options:peer=proxy-br-ex \
+# -- add-port br-eth0 proxy-br-ex \
+# -- set interface proxy-br-ex type=patch options:peer=ex-br-proxy
+
+
+ - openvswitch_bridge:
+ bridge: br-eth1
+ state: present
+ - openvswitch_port:
+ bridge: br-eth1
+ port: eth1-br-proxy
+ state: present
+ - shell: ovs-vsctl set interface eth1-br-proxy type=patch options:peer=proxy-br-eth1
+ - openvswitch_port:
+ bridge: br-eth0
+ port: proxy-br-eth1
+ state: present
+ - shell: ovs-vsctl set interface proxy-br-eth1 type=patch options:peer=eth1-br-proxy
+ - openvswitch_bridge:
+ bridge: br-ex
+ state: present
+ - openvswitch_port:
+ bridge: br-ex
+ port: ex-br-proxy
+ state: present
+ - shell: ovs-vsctl set interface ex-br-proxy type=patch options:peer=proxy-br-ex
+ - openvswitch_port:
+ bridge: br-eth0
+ port: proxy-br-ex
+ state: present
+ - shell: ovs-vsctl set interface proxy-br-ex type=patch options:peer=ex-br-proxy
diff --git a/openstack/usr/share/openstack/openvswitch.yml b/openstack/usr/share/openstack/openvswitch.yml
new file mode 100644
index 00000000..8331c639
--- /dev/null
+++ b/openstack/usr/share/openstack/openvswitch.yml
@@ -0,0 +1,39 @@
+#!/bin/sh
+---
+- hosts: localhost
+ tasks:
+
+ - name: Create openvswitch directories
+ file: path={{ item }} state=directory
+ with_items:
+ - /etc/openvswitch
+ - /var/run/openvswitch
+
+ - shell: >
+ ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
+ creates=/etc/openvswitch/conf.db
+
+ # We enable the openvswitch-db-server in a different task to identify
+ # the first time we run this script by identifying when we enable the
+ # unit.
+ #
+ # We need to identify this to initialise the database.
+ - name: Enable openvswitch database service
+ service: name={{ item }} enabled=yes
+ with_items:
+ - openvswitch-db-server.service
+ register: openvswitch_db_enable
+
+ - name: Start openvswitch database service
+ service: name={{ item }} state=started
+ with_items:
+ - openvswitch-db-server.service
+
+ - name: initialise openvswitch-db
+ shell: ovs-vsctl --no-wait init
+ when: openvswitch_db_enable|changed
+
+ - name: Enable and start openstack-keystone service
+ service: name={{ item }} enabled=yes state=started
+ with_items:
+ - openvswitch.service
diff --git a/systems/openstack-server.morph b/systems/openstack-server.morph
index 17c1bbff..64b5646b 100644
--- a/systems/openstack-server.morph
+++ b/systems/openstack-server.morph
@@ -67,3 +67,4 @@ configuration-extensions:
- openstack-glance
- openstack-cinder
- openstack-nova
+- openstack-network