xci: configure-network: Add ability to configure network on SUSE hosts 23/41623/4
authorMarkos Chandras <mchandras@suse.de>
Fri, 1 Sep 2017 14:47:23 +0000 (15:47 +0100)
committerMarkos Chandras <mchandras@suse.de>
Sun, 17 Sep 2017 21:42:43 +0000 (22:42 +0100)
Change-Id: I42c6f5f07ac87b5599758947fabe5fce36d44a2e
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/playbooks/roles/configure-network/files/network-config-suse [new file with mode: 0755]
xci/playbooks/roles/configure-network/tasks/main.yml
xci/playbooks/roles/configure-network/templates/suse/suse.interface.j2 [new file with mode: 0644]
xci/playbooks/roles/configure-network/templates/suse/suse.routes.j2 [new file with mode: 0644]
xci/var/Suse.yml

diff --git a/xci/playbooks/roles/configure-network/files/network-config-suse b/xci/playbooks/roles/configure-network/files/network-config-suse
new file mode 100755 (executable)
index 0000000..1a9f1e7
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+INTERFACE=$1
+ACTION=$4
+
+if [[ $INTERFACE == "br-vlan" ]]; then
+    if [[ $ACTION == "pre-up" ]]; then
+        ip link add br-vlan-veth type veth peer name eth12 || true
+        ip link set br-vlan-veth up
+        ip link set eth12 up
+    else
+        ip link del br-vlan-veth || true
+    fi
+fi
+
index df1580e..126389d 100644 (file)
@@ -7,7 +7,11 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-# TODO: this role needs to be adjusted for different distros
+- name: ensure glean rules are removed
+  file:
+    path: "/etc/udev/rules.d/99-glean.rules"
+    state: absent
+
 - block:
     - name: configure modules
       lineinfile:
       modprobe:
         name: 8021q
         state: present
-    - name: ensure glean rules are removed
-      file:
-        path: "/etc/udev/rules.d/99-glean.rules"
-        state: absent
     - name: ensure interfaces.d folder is empty
       shell: "/bin/rm -rf /etc/network/interfaces.d/*"
     - name: ensure interfaces file is updated
     - name: restart network service
       shell: "/sbin/ifconfig {{ interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
   when: ansible_os_family | lower == "debian"
+
+- block:
+    - name: Remove existing network configuration
+      file:
+        path: "/etc/sysconfig/network/{{ item }}"
+        state: absent
+      with_items:
+        - "ifcfg-eth0"
+        - "ifroute-eth0"
+
+    - name: Configure networking on SUSE
+      template:
+        src: "{{ ansible_os_family | lower }}/suse.interface.j2"
+        dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}"
+      with_items:
+        - { name: "{{ interface }}" }
+        - { name: "{{ interface }}.10", vlan_id: 10 }
+        - { name: "{{ interface }}.30", vlan_id: 30 }
+        - { name: "{{ interface }}.20", vlan_id: 20 }
+        - { name: "br-mgmt", bridge_ports: "{{ interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" }
+        - { name: "br-vxlan", bridge_ports: "{{ interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" }
+        - { name: "br-vlan", bridge_ports: "{{ interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" }
+        - { name: "br-storage", bridge_ports: "{{ interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" }
+
+    - name: Add postup/postdown scripts on SUSE
+      copy:
+        src: "network-config-suse"
+        dest: "/etc/sysconfig/network/scripts/network-config-suse"
+
+    - name: Configure routes on SUSE
+      template:
+        src: "{{ ansible_os_family | lower }}/suse.routes.j2"
+        dest: "/etc/sysconfig/network/ifroute-{{ item.name }}"
+      with_items:
+        - { name: "br-vlan", gateway: "192.168.122.1", route: "default" }
+
+    - name: restart network service
+      shell: "/usr/sbin/wicked ifreload all"
+  when: ansible_os_family | lower == "suse"
diff --git a/xci/playbooks/roles/configure-network/templates/suse/suse.interface.j2 b/xci/playbooks/roles/configure-network/templates/suse/suse.interface.j2
new file mode 100644 (file)
index 0000000..ffa418d
--- /dev/null
@@ -0,0 +1,17 @@
+STARTMODE='auto'
+BOOTPROTO='static'
+{% if item.vlan_id is defined %}
+ETHERDEVICE={{ interface }}
+VLAN_ID={{ item.vlan_id }}
+{% endif %}
+{% if item.bridge_ports is defined %}
+BRIDGE='yes'
+BRIDGE_FORWARDDELAY='0'
+BRIDGE_STP=off
+BRIDGE_PORTS={{ item.bridge_ports }}
+{% endif %}
+{% if item.ip is defined %}
+IPADDR={{ item.ip }}
+{% endif %}
+PRE_UP_SCRIPT="compat:suse:network-config-suse"
+POST_DOWN_SCRIPT="compat:suse:network-config-suse"
diff --git a/xci/playbooks/roles/configure-network/templates/suse/suse.routes.j2 b/xci/playbooks/roles/configure-network/templates/suse/suse.routes.j2
new file mode 100644 (file)
index 0000000..7c86844
--- /dev/null
@@ -0,0 +1 @@
+{{ item.route }} {{ item.gateway }}
index 9674ed2..786a875 100644 (file)
@@ -7,5 +7,6 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-# this is placeholder and left blank intentionally to complete later on
+# this is the interface the VM nodes are connected to libvirt network "default"
+interface: "eth0"
 python_crypto_package_name: python-pycrypto