vswitch: do not access XenAPI from VIF hotplug script
authorIan Campbell <ian.campbell@citrix.com>
Fri, 26 Feb 2010 21:25:09 +0000 (13:25 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 1 Mar 2010 19:10:11 +0000 (11:10 -0800)
XenAPI accesses must go through the pool master which introduces a
scalability issue.  All but one of the required values are already
present in xenstore for this reason

The only exception is the network UUID for an internal network. Rather
than working around the lack of callout to interface-reconfigure for
these networks simply pass the network uuid when creating calling out
to create the bridge.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
xenserver/etc_xensource_scripts_vif

index d27bc10daa73d5b57bc0f5972689ed5882fc9fe5..d042875fe888dc41a9f9b851211b2d7354c40f6c 100755 (executable)
@@ -66,6 +66,43 @@ handle_mtu()
     fi
 }
 
+set_vif_external_id()
+{
+    local key=$1
+    local value=$2
+
+    logger -t scripts-vif "vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
+
+    echo "-- set interface vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
+}
+
+handle_vswitch_vif_details()
+{
+    local vif_details=
+    local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null)
+    if [ -n "${net_uuid}" ] ; then
+       set_vif_external_id "xs-network-uuid" "${net_uuid}"
+    fi
+
+    local address=$(xenstore-read "/local/domain/$DOMID/device/vif/$DEVID/mac" 2>/dev/null)
+    if [ -n "${address}" ] ; then
+       set_vif_external_id "xs-vif-mac" "${address}"
+    fi
+
+    local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null)
+    if [ -n "${vif_uuid}" ] ; then
+       set_vif_external_id "xs-vif-uuid" "${vif_uuid}"
+    fi
+
+    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
+       set_vif_external_id "xs-vm-uuid" "${vm_uuid}"
+    fi
+}
+
 add_to_bridge()
 {
     local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
@@ -92,12 +129,11 @@ add_to_bridge()
            ${BRCTL} addif "${bridge}" "${dev}"                 || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}"
            ;;
        vswitch)
-               local vif_details=$($dump_vif_details $DOMID $DEVID)
-               if [ $? -ne 0 -o -z "${vif_details}" ]; then
-                       logger -t scripts-vif "Failed to retrieve vif details for vswitch"
-               fi
+           if [ "$TYPE" = "vif" ] ; then
+               local vif_details=$(handle_vswitch_vif_details)
+           fi
 
-               $vsctl -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details
+           $vsctl -- --if-exists del-port $dev -- add-port $bridge $dev $vif_details
            ;;
     esac
            
@@ -111,7 +147,7 @@ remove_from_bridge()
            # Nothing to do
            ;;
        vswitch)
-        $vsctl del-port $bridge $dev
+           $vsctl del-port $bridge $dev
            ;;
     esac
 }