ovsdb-server: Improve logging for referential integrity violations.
[sliver-openvswitch.git] / xenserver / opt_xensource_libexec_InterfaceReconfigureVswitch.py
index 5fb7a92..a4b9da7 100644 (file)
@@ -297,6 +297,10 @@ def configure_datapath(pif):
         vsctl_argv += ['# add physical device %s' % iface]
         vsctl_argv += ['--', '--may-exist', 'add-port', bridge, iface]
 
+    vsctl_argv += ['# configure Bridge MAC']
+    vsctl_argv += ['--', 'set', 'Bridge', bridge,
+                   'other-config:hwaddr=%s' % vsctl_escape(db().get_pif_record(pif)['MAC'])]
+
     vsctl_argv += set_br_external_ids(pif)
     vsctl_argv += ['## done configuring datapath %s' % bridge]
 
@@ -333,13 +337,9 @@ def set_br_external_ids(pif):
         xs_network_uuids += [nwrec['uuid']]
 
     vsctl_argv = []
-    vsctl_argv += ['# configure xs-network-uuids']
+    vsctl_argv += ['# configure 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'])]
+            'network-uuids', ';'.join(xs_network_uuids)]
 
     return vsctl_argv
 
@@ -358,6 +358,17 @@ class DatapathVswitch(Datapath):
         
         log("Configured for Vswitch datapath")
 
+    @classmethod
+    def rewrite(cls):
+        vsctl_argv = []
+        for pif in db().get_all_pifs():
+            pifrec = db().get_pif_record(pif)
+            if not pif_is_vlan(pif) and pifrec['currently_attached']:
+                vsctl_argv += set_br_external_ids(pif)
+
+        if vsctl_argv != []:
+            datapath_modify_config(vsctl_argv)
+
     def configure_ipdev(self, cfg):
         cfg.write("TYPE=Ethernet\n")
 
@@ -374,6 +385,8 @@ class DatapathVswitch(Datapath):
         vsctl_argv += c
         extra_ports += e
 
+        dpname = pif_bridge_name(self._dp)
+        
         if pif_is_vlan(self._pif):
             # XXX this is only needed on XS5.5, because XAPI misguidedly
             # creates the fake bridge (via bridge ioctl) before it calls us.
@@ -382,7 +395,7 @@ class DatapathVswitch(Datapath):
             # configure_datapath() set up the underlying datapath bridge.
             # Stack a VLAN bridge on top of it.
             vsctl_argv += ['--', '--may-exist', 'add-br',
-                           bridge, pif_bridge_name(self._dp), pifrec['VLAN']]
+                           bridge, dpname, pifrec['VLAN']]
 
             vsctl_argv += set_br_external_ids(self._pif)
 
@@ -392,6 +405,11 @@ class DatapathVswitch(Datapath):
             vsctl_argv += ["# reconfigure ipdev %s" % ipdev]
             vsctl_argv += ['--', 'add-port', bridge, ipdev]
 
+        if ipdev != dpname:
+            vsctl_argv += ['# configure Interface MAC']
+            vsctl_argv += ['--', 'set', 'Interface', pif_ipdev_name(self._pif),
+                           'MAC=%s' % vsctl_escape(dprec['MAC'])]
+
         self._vsctl_argv = vsctl_argv
         self._extra_ports = extra_ports
 
@@ -438,8 +456,8 @@ class DatapathVswitch(Datapath):
 
         #nw = db().get_pif_record(self._pif)['network']
         #nwrec = db().get_network_record(nw)
-        #vsctl_argv += ['# deconfigure xs-network-uuids']
-        #vsctl_argv += ['--del-entry=bridge.%s.xs-network-uuids=%s' % (bridge,nwrec['uuid'])]
+        #vsctl_argv += ['# deconfigure network-uuids']
+        #vsctl_argv += ['--del-entry=bridge.%s.network-uuids=%s' % (bridge,nwrec['uuid'])]
 
         log("deconfigure ipdev %s on %s" % (ipdev,bridge))
         vsctl_argv += ["# deconfigure ipdev %s" % ipdev]