xenserver: Synchronize scripts with XenServer 6.0.0.
[sliver-openvswitch.git] / xenserver / etc_xensource_scripts_vif
index 0625498..78434fb 100755 (executable)
@@ -150,6 +150,30 @@ remove_from_bridge()
     esac
 }
 
+call_hook_script() {
+    local domid=$1
+    local action=$2
+    # Call the VIF hotplug hook if present
+    if [ -x /etc/xapi.d/vif-hotplug ]; then
+        local vm=$(xenstore-read "/local/domain/$domid/vm" 2>/dev/null)
+        if [ $? -eq 0 -a -n "${vm}" ] ; then
+            local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null)
+        fi
+        if [ -n "${vm_uuid}" ] ; then
+            logger -t scripts-vif "VM UUID ${vm_uuid}"
+        fi
+
+        local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null)
+        if [ -n "${vif_uuid}" ] ; then
+            logger -t scripts-vif "VIF UUID ${vif_uuid}"
+        fi
+        if [ -n "${vif_uuid}" -a -n "${vm_uuid}" ] ; then
+            logger -t scripts-vif "Calling VIF hotplug hook for VM ${vm_uuid}, VIF ${vif_uuid}"
+            /etc/xapi.d/vif-hotplug -action "${action}" -vifuuid "${vif_uuid}" -vmuuid "${vm_uuid}"
+        fi
+    fi
+}
+
 NETWORK_MODE=$(cat /etc/xensource/network.conf)
 ACTION=$1
 
@@ -171,8 +195,13 @@ esac
 
 case ${TYPE} in
     vif)
-        DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
-        DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
+        if [ -z ${XENBUS_PATH} ]; then
+            DOMID=$3
+            DEVID=$4
+        else
+            DOMID=`echo ${XENBUS_PATH} | cut -f 3 -d '/'`
+            DEVID=`echo ${XENBUS_PATH} | cut -f 4 -d '/'`
+        fi
         dev=vif${DOMID}.${DEVID}
         ;;
     tap)
@@ -210,6 +239,7 @@ online)
 
         # xs-xen.pq.hq:91e986b8e49f netback-wait-for-hotplug
         xenstore-write "/local/domain/0/backend/vif/${DOMID}/${DEVID}/hotplug-status" "connected"
+        call_hook_script $DOMID "${ACTION}"
     fi
     ;;
 
@@ -222,8 +252,14 @@ add)
 remove)
     if [ "${TYPE}" = "vif" ] ;then
         xenstore-rm "${HOTPLUG}/hotplug"
+        call_hook_script $DOMID "${ACTION}"
     fi
     logger -t scripts-vif "${dev} has been removed"
     remove_from_bridge
     ;;
+
+move)
+    if [ "${TYPE}" = "vif" ] ;then
+        add_to_bridge
+    fi
 esac