xenserver: Implement missing interface-reconfigure settings.
authorBen Pfaff <blp@nicira.com>
Tue, 2 Mar 2010 22:52:05 +0000 (14:52 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 3 Mar 2010 17:55:33 +0000 (09:55 -0800)
These settings are supported by the bridge, and they were supported
earlier by the vswitch, but support regressed when OVSDB was initially
introduced because at first ovs-vsctl did not support these settings.
This commit restores support.

Related to bug #2430, #2442.

Signed-off-by: Ben Pfaff <blp@nicira.com>
tests/interface-reconfigure.at
xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py

index 597a8f1b8496eb4e404ba5750d6382453434da29..04f32552fadb7cb1780b8e519062b3ad85bd27d5 100644 (file)
@@ -654,6 +654,7 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xenbr2 configuration
     --may-exist add-br xenbr2
     --may-exist add-port xenbr2 eth2
     br-set-external-id xenbr2 xs-network-uuids d08c8749-0c8f-9e8d-ce25-fd364661ee99
+    set Interface xenbr2 MAC="00:15:17:a0:29:80"
 /sbin/ifup xenbr2
 /sbin/update-issue
 Committing changes to /etc/sysconfig/network-scripts/route-xenbr2 configuration
@@ -716,9 +717,11 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi3 configuration
     --may-exist add-br xenbr3
     --may-exist add-port xenbr3 eth3
     br-set-external-id xenbr3 xs-network-uuids 2902ae1b-8013-897a-b697-0b200ea3aaa5;db7bdc03-074d-42ae-fc73-9b06de1d57f6
+    set Interface xenbr3 MAC="00:15:17:a0:29:81"
     --if-exists del-br xapi3
     --may-exist add-br xapi3 xenbr3 123
     br-set-external-id xapi3 xs-network-uuids 2902ae1b-8013-897a-b697-0b200ea3aaa5;db7bdc03-074d-42ae-fc73-9b06de1d57f6
+    set Interface xapi3 MAC="00:15:17:a0:29:81"
 /sbin/ifup xapi3
 /sbin/update-issue
 Committing changes to /etc/sysconfig/network-scripts/route-xapi3 configuration
@@ -797,7 +800,9 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi1 configuration
     --may-exist add-br xapi1
     --with-iface --if-exists del-port bond0
     --fake-iface add-bond xapi1 bond0 eth0 eth1
+    set Port bond0 MAC="00:22:19:22:4b:af" bond_downdelay=200 other-config:"bond-miimon"=100 other-config:"bond-use_carrier"=1 other-config:"bond-mode"="balance-slb" bond_updelay=31000
     br-set-external-id xapi1 xs-network-uuids 99be2da4-6c33-6f8e-49ea-3bc592fe3c85;45cbbb43-113d-a712-3231-c6463f253cef
+    set Interface xapi1 MAC="00:22:19:22:4b:af"
 /sbin/ifup xapi1
 action_up: bring up bond0
 /sbin/ifconfig bond0 up
@@ -876,10 +881,13 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi2 configuration
     --may-exist add-br xapi1
     --with-iface --if-exists del-port bond0
     --fake-iface add-bond xapi1 bond0 eth0 eth1
+    set Port bond0 MAC="00:22:19:22:4b:af" bond_downdelay=200 other-config:"bond-miimon"=100 other-config:"bond-use_carrier"=1 other-config:"bond-mode"="balance-slb" bond_updelay=31000
     br-set-external-id xapi1 xs-network-uuids 99be2da4-6c33-6f8e-49ea-3bc592fe3c85;45cbbb43-113d-a712-3231-c6463f253cef
+    set Interface xapi1 MAC="00:22:19:22:4b:af"
     --if-exists del-br xapi2
     --may-exist add-br xapi2 xapi1 4
     br-set-external-id xapi2 xs-network-uuids 99be2da4-6c33-6f8e-49ea-3bc592fe3c85;45cbbb43-113d-a712-3231-c6463f253cef
+    set Interface xapi2 MAC="00:22:19:22:4b:af"
 /sbin/ifup xapi2
 action_up: bring up bond0
 /sbin/ifconfig bond0 up
index 67636c0a383e6f0367ad86c681116fa3cc147d5c..5fb7a92bd0bed0f0b3f20155ce0acd0fba0cb9e2 100644 (file)
@@ -12,6 +12,7 @@
 # GNU Lesser General Public License for more details.
 #
 from InterfaceReconfigure import *
+import re
 
 #
 # Bare Network Devices -- network devices without IP configuration
@@ -100,6 +101,30 @@ A VLAN PIF cannot be a datapath PIF.
 def datapath_deconfigure_physical(netdev):
     return ['--', '--with-iface', '--if-exists', 'del-port', netdev]
 
+def vsctl_escape(s):
+    if s.isalnum():
+        return s
+
+    def escape(match):
+        c = match.group(0)
+        if c == '\0':
+            raise Error("strings may not contain null bytes")
+        elif c == '\\':
+            return r'\\'
+        elif c == '\n':
+            return r'\n'
+        elif c == '\r':
+            return r'\r'
+        elif c == '\t':
+            return r'\t'
+        elif c == '\b':
+            return r'\b'
+        elif c == '\a':
+            return r'\a'
+        else:
+            return r'\x%02x' % ord(c)
+    return '"' + re.sub(r'["\\\000-\037]', escape, s) + '"'
+
 def datapath_configure_bond(pif,slaves):
     bridge = pif_bridge_name(pif)
     pifrec = db().get_pif_record(pif)
@@ -109,10 +134,6 @@ def datapath_configure_bond(pif,slaves):
     for slave in slaves:
         argv += [pif_netdev_name(slave)]
 
-    # XXX need ovs-vsctl support
-    #if pifrec['MAC'] != "":
-    #    argv += ['--add=port.%s.mac=%s' % (interface, pifrec['MAC'])]
-
     # Bonding options.
     bond_options = {
         "mode":   "balance-slb",
@@ -128,10 +149,26 @@ def datapath_configure_bond(pif,slaves):
                            key.startswith("bond-"), oc.items())
     overrides = map(lambda (key,val): (key[5:], val), overrides)
     bond_options.update(overrides)
+
+    argv += ['--', 'set', 'Port', interface]
+    if pifrec['MAC'] != "":
+        argv += ['MAC=%s' % vsctl_escape(pifrec['MAC'])]
     for (name,val) in bond_options.items():
-        # XXX need ovs-vsctl support for bond options
-        #argv += ["--add=bonding.%s.%s=%s" % (interface, name, val)]
-        pass
+        if name in ['updelay', 'downdelay']:
+            # updelay and downdelay have dedicated schema columns.
+            # The value must be a nonnegative integer.
+            try:
+                value = int(val)
+                if value < 0:
+                    raise ValueError
+
+                argv += ['bond_%s=%d' % (name, value)]
+            except ValueError:
+                log("bridge %s has invalid %s '%s'" % (bridge, name, value))
+        else:
+            # Pass other bond options into other_config.
+            argv += ["other-config:%s=%s" % (vsctl_escape("bond-%s" % name),
+                                             vsctl_escape(val))]
     return argv
 
 def datapath_deconfigure_bond(netdev):
@@ -278,8 +315,12 @@ def deconfigure_bridge(pif):
     return vsctl_argv
 
 def set_br_external_ids(pif):
+    pifrec = db().get_pif_record(pif)
+    dp = pif_datapath(pif)
+    dprec = db().get_pif_record(dp)
+
     xs_network_uuids = []
-    for nwpif in db().get_pifs_by_device(db().get_pif_record(pif)['device']):
+    for nwpif in db().get_pifs_by_device(pifrec['device']):
         rec = db().get_pif_record(nwpif)
 
         # When state is read from dbcache PIF.currently_attached
@@ -295,6 +336,11 @@ def set_br_external_ids(pif):
     vsctl_argv += ['# configure xs-network-uuids']
     vsctl_argv += ['--', 'br-set-external-id', pif_bridge_name(pif),
             'xs-network-uuids', ';'.join(xs_network_uuids)]
+
+    vsctl_argv += ['# configure MAC']
+    vsctl_argv += ['--', 'set', 'Interface', pif_ipdev_name(pif),
+                   'MAC=%s' % vsctl_escape(dprec['MAC'])]
+
     return vsctl_argv
 
 #
@@ -346,12 +392,6 @@ class DatapathVswitch(Datapath):
             vsctl_argv += ["# reconfigure ipdev %s" % ipdev]
             vsctl_argv += ['--', 'add-port', bridge, ipdev]
 
-        # XXX Needs support in ovs-vsctl
-        #if bridge == ipdev:
-        #    vsctl_argv += ['--add=bridge.%s.mac=%s' % (bridge, dprec['MAC'])]
-        #else:
-        #    vsctl_argv += ['--add=iface.%s.mac=%s' % (ipdev, dprec['MAC'])]
-
         self._vsctl_argv = vsctl_argv
         self._extra_ports = extra_ports