trailing spaces
[tests.git] / system / template-qemu / qemu-bridge-init
index 70f3b83..9191e59 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
-# Copyright (C) 2010 INRIA 
+# Copyright (C) 2010 INRIA
 #
 # Establishment of a runtime environment for a
 # virtual  machine  under QEMU, This script allows the host box
@@ -20,18 +20,24 @@ INTERFACE_BRIDGE=br0
 #################### compute INTERFACE_LAN
 # use /proc/net/dev instead of a hard-wired list
 function gather_interfaces () {
-    python <<EOF
-for line in file("/proc/net/dev"):
-    if ':' not in line: continue
-    ifname=line.replace(" ","").split(":")[0]
-    if ifname.find("lo")==0: continue
-    if ifname.find("br")==0: continue
-    if ifname.find("virbr")==0: continue
-    if ifname.find("tap")==0: continue
-    print ifname
+    python3 << EOF
+with open("/proc/net/dev") as feed:
+    for line in feed:
+        if ':' not in line:
+            continue
+        ifname = line.replace(" ","").split(":")[0]
+        if ifname.find("lo")==0: 
+            continue
+        if ifname.find("br")==0: 
+            continue
+        if ifname.find("virbr")==0: 
+            continue
+        if ifname.find("tap")==0: 
+            continue
+        print(ifname)
 EOF
 }
-    
+
 function discover_interface () {
     for ifname in $(gather_interfaces); do
        ip link show $ifname | grep -qi 'state UP' && { echo $ifname; return; }
@@ -80,7 +86,7 @@ function start () {
     #Getting host IP/masklen
     address=$(/sbin/ip address show $INTERFACE_LAN | grep -v inet6 | grep inet | head --lines=1 | awk '{print $2;}')
     [ -z "$address" ] && { echo "ERROR: Could not determine IP address for $INTERFACE_LAN" ; exit 1 ; }
-    
+
     broadcast=$(/sbin/ip address show $INTERFACE_LAN | grep -v inet6 | grep inet | head --lines=1 | awk '{print $4;}')
     [ -z "$broadcast" ] && echo "WARNING: Could not determine broadcast address for $INTERFACE_LAN"
 
@@ -117,13 +123,15 @@ function start () {
     sleep 2
     echo "Setting bridge address=$address broadcast=$broadcast"
     # static
-    ip address add $address broadcast $broadcast dev $INTERFACE_BRIDGE 
-    ip address del $address dev $INTERFACE_LAN 
+    ip address add $address broadcast $broadcast dev $INTERFACE_BRIDGE
+    # turn on bridge interface
+    ip link set dev $INTERFACE_BRIDGE up
+    ip address del $address dev $INTERFACE_LAN
     sleep 1
-       
+
     #Reconfigure the routing table
     echo "Adding default route via gateway=$gateway on dev $INTERFACE_LAN"
-    ip route add default via $gateway dev $INTERFACE_BRIDGE
+    ip route add 0.0.0.0/0 via $gateway dev $INTERFACE_BRIDGE
 
     echo "========== $COMMAND: exiting start - beg"
     ip address show
@@ -131,7 +139,7 @@ function start () {
     echo "========== $COMMAND: exiting start - end"
 }
 
-#Adding a new interface to the bridge: this is used by qemu-ifup 
+#Adding a new interface to the bridge: this is used by qemu-ifup
 function add () {
 
     [[ -z "$@" ]] && { echo "Usage: $COMMAND add ifname" ; exit 1 ; }
@@ -168,7 +176,7 @@ function add () {
 
     echo "Installed iptables"
     iptables-save
-    
+
     echo "========== $COMMAND: exiting add - end"
 }
 
@@ -188,8 +196,7 @@ function stop () {
     brctl delif $INTERFACE_BRIDGE $INTERFACE_LAN
     ip address del $address dev $INTERFACE_BRIDGE
     brctl delbr $INTERFACE_BRIDGE
-    /sbin/service network restart
-    /sbin/service iptables restart
+    systemctl NetworkManager restart
 }
 
 function main () {