summaryrefslogtreecommitdiff
path: root/openstack/usr
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-04-14 13:10:36 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-04-16 14:09:52 +0000
commit882c3912e7aea98ff6f945a7e6bdc926b1cfc790 (patch)
tree67c3530a3beaa48489fead3b6375fcb2898d5437 /openstack/usr
parenteb5f7d081841925c5324411e6861119404e26a5d (diff)
downloaddefinitions-882c3912e7aea98ff6f945a7e6bdc926b1cfc790.tar.gz
Openstack: Add support to configure the network of the node
Change-Id: I8f8bfb231ab5ff4c2a825451a57a5b38a641c300 Signed-off-by: Pedro Alvarez <pedro.alvarez@codethink.co.uk> Signed-off-by: Richard Maw <richard.maw@codethink.co.uk>
Diffstat (limited to 'openstack/usr')
-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/60-device-dhcp.network5
-rw-r--r--openstack/usr/share/openstack/network.yml67
-rw-r--r--openstack/usr/share/openstack/openvswitch.yml38
8 files changed, 156 insertions, 0 deletions
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/60-device-dhcp.network b/openstack/usr/share/openstack/extras/60-device-dhcp.network
new file mode 100644
index 00000000..6fdbfd8d
--- /dev/null
+++ b/openstack/usr/share/openstack/extras/60-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..f99f7f1a
--- /dev/null
+++ b/openstack/usr/share/openstack/network.yml
@@ -0,0 +1,67 @@
+---
+- hosts: localhost
+ vars_files:
+ - /etc/openstack/network.conf
+ tasks:
+# Create the bridges to use the External network mapped
+
+# 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:
+ - ovs-system
+
+ - openvswitch_bridge:
+ bridge: br-ex
+ state: present
+
+ - openvswitch_port:
+ bridge: br-ex
+ port: "{{ ETH_INTERFACE }}"
+ state: present
+
+ - shell: ovs-vsctl set bridge br-ex 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/60-device-dhcp.network
+ dest: /run/systemd/network/60-{{ item }}-dhcp.network
+ with_items:
+ - br-ex
diff --git a/openstack/usr/share/openstack/openvswitch.yml b/openstack/usr/share/openstack/openvswitch.yml
new file mode 100644
index 00000000..4393e3db
--- /dev/null
+++ b/openstack/usr/share/openstack/openvswitch.yml
@@ -0,0 +1,38 @@
+---
+- 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