xenserver: Make basic VM networking work.
authorBen Pfaff <blp@nicira.com>
Thu, 10 Dec 2009 23:53:03 +0000 (15:53 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 10 Dec 2009 23:56:11 +0000 (15:56 -0800)
Tested by starting and stopping a VM that has a single VIF and verifying
that the VM could get an IP address via DHCP and access the network and
that the VIF's external-ids were set to plausible values.

xenserver/etc_xensource_scripts_vif
xenserver/usr_share_vswitch_scripts_dump-vif-details

index c649e926b0e436e8623645253f15358c0b57afbc..a9b62ff4f2b3ee4461eafa22439ad1f7f3e556cb 100755 (executable)
@@ -21,7 +21,6 @@
 
 # Keep other-config/ keys in sync with device.ml:vif_udev_keys
 
-cfg_mod="/usr/bin/ovs-cfg-mod"
 vsctl="/usr/bin/ovs-vsctl"
 dump_vif_details="/usr/share/vswitch/scripts/dump-vif-details"
 service="/sbin/service"
@@ -81,13 +80,6 @@ add_to_bridge()
     fi
     logger -t scripts-vif "Adding ${vif} to ${bridge} with address ${address}"
 
-    local VLAN_ID=$($vsctl br-to-vlan $bridge)
-    local vid=
-    if [ "$VLAN_ID" -ne 0 ] ; then
-       bridge=$($vsctl br-to-parent $bridge)
-       vid="--add=vlan.${vif}.tag=${VLAN_ID}"
-    fi
-
     ${IP} link set "${vif}" down                        || logger -t scripts-vif "Failed to ip link set ${vif} down"
     ${IP} link set "${vif}" arp off                     || logger -t scripts-vif "Failed to ip link set ${vif} arp off"
     ${IP} link set "${vif}" multicast off               || logger -t scripts-vif "Failed to ip link set ${vif} multicast off"
@@ -99,14 +91,7 @@ add_to_bridge()
            logger -t scripts-vif "Failed to retrieve vif details for vswitch"
     fi
 
-    $cfg_mod -F /etc/ovs-vswitchd.conf \
-        --del-match="bridge.*.port=$vif" \
-        --del-match="vlan.$vif.trunks=*" \
-        --del-match="vlan.$vif.tag=*" \
-        --del-match="port.$vif.[!0-9]*" \
-        --add="bridge.$bridge.port=$vif" \
-        $vid $vif_details -c 
-    $service vswitch reload
+    $vsctl add-port $bridge $vif $vif_details
 
     ${IP} link set "${vif}" up                          || logger -t scripts-vif "Failed to ip link set ${vif} up"
 }
index 7ce8bf7817abae4dbaa2e1ee176bcaeed5fe7d65..1340adddd8594dfd94267e928ca4e582bfc92fc9 100755 (executable)
@@ -25,7 +25,6 @@ def get_vif_ref(domid, devid):
 
 # Query XAPI for the information we need using the vif's opaque reference
 def dump_vif_info(domid, devid, vif_ref):
-       vif_info = []
        session = XenAPI.xapi_local()
        session.xenapi.login_with_password("root", "")
        try: 
@@ -34,11 +33,14 @@ def dump_vif_info(domid, devid, vif_ref):
                vm_uuid = session.xenapi.VM.get_uuid(vif_rec["VM"])
 
                # Data to allow vNetManager to associate VIFs with xapi data
-               add_port = '--add=port.vif%s.%s' % (domid, devid)
-               vif_info.append('%s.net-uuid=%s' % (add_port, net_rec["uuid"]))
-               vif_info.append('%s.vif-mac=%s' % (add_port, vif_rec["MAC"]))
-               vif_info.append('%s.vif-uuid=%s' % (add_port, vif_rec["uuid"]))
-               vif_info.append('%s.vm-uuid=%s' % (add_port, vm_uuid))
+               vif_info = []
+               vif_info.append(('xs-network-uuid', net_rec["uuid"]))
+               vif_info.append(('xs-vif-mac', vif_rec["MAC"]))
+               vif_info.append(('xs-vif-uuid', vif_rec["uuid"]))
+               vif_info.append(('xs-vm-uuid', vm_uuid))
+               for key, value in vif_info:
+                       print("-- iface-set-external-id vif%s.%s %s %s"
+                             % (domid, devid, key, value))
 
                # vNetManager needs to know the network UUID(s) associated with
                # each datapath.  Normally interface-reconfigure adds them, but
@@ -51,13 +53,13 @@ def dump_vif_info(domid, devid, vif_ref):
                # ovs-vswitchd connection to vNetManager and setting this
                # configuration variable, but vNetManager can tolerate that.
                if not net_rec['PIFs']:
-                       key = 'bridge.%s.xs-network-uuids' % net_rec['bridge']
+                       bridge = net_rec['bridge']
+                       key = "xs-network-uuids"
                        value = net_rec['uuid']
-                       vif_info.append('--del-match=%s=*' % key)
-                       vif_info.append('--add=%s=%s' % (key, value))
+                       print("-- bridge-set-external-id %s %s %s"
+                             % (bridge, key, value))
        finally:
                session.xenapi.session.logout()
-       print ' '.join(vif_info)
        
 if __name__ == '__main__':
        if len(sys.argv) != 3: