xenserver: Put XenServer network UUIDs into ovs-vswitchd.conf.
authorBen Pfaff <blp@nicira.com>
Fri, 29 May 2009 22:15:53 +0000 (15:15 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 May 2009 22:15:53 +0000 (15:15 -0700)
vNetManager needs the UUIDs of the XenServer networks represented by a
bridge.  interface-reconfigure has all the necessary information to figure
this out, so make it add them to the configuration file.

xenserver/opt_xensource_libexec_interface-reconfigure

index b0dac5afb7c9a6955f4a3ca37d90c3be88784cc0..fab8513520bc3e8a4a0b984bf8cd526290224847 100755 (executable)
@@ -302,9 +302,9 @@ class DatabaseCache(object):
 
         return pifs[0]
 
-    def get_pif_by_record(self, record):
+    def get_pifs_by_record(self, record):
         """record is partial pif record.
-        Get the pif whose record matches.
+        Get the pif(s) whose record matches.
         """
         def match(pifrec):
             for key in record:
@@ -312,9 +312,15 @@ class DatabaseCache(object):
                     return False
             return True
             
-        pifs = map(lambda (ref,rec): ref,
-                  filter(lambda (ref,rec): match(rec),
-                         self.__pifs.items()))
+        return map(lambda (ref,rec): ref,
+                   filter(lambda (ref,rec): match(rec),
+                          self.__pifs.items()))
+
+    def get_pif_by_record(self, record):
+        """record is partial pif record.
+        Get the pif whose record matches.
+        """
+        pifs = self.get_pifs_by_record(record)
         if len(pifs) == 0:
             raise Error("No matching PIF \"%s\"" % str(record))
         elif len(pifs) > 1:
@@ -366,6 +372,8 @@ class DatabaseCache(object):
         if self.__networks.has_key(network):
             return self.__networks[network]
         raise Error("Unknown network \"%s\"" % network)
+    def get_all_networks(self):
+        return self.__networks
 
     def get_bond_record(self, bond):
         if self.__bonds.has_key(bond):
@@ -852,6 +860,18 @@ def action_up(pif):
     #    implicitly being asked to take them down.)
     del_ports = add_ports + physdevs + bond_masters
 
+    # What networks does this datapath carry?
+    #
+    # - The network corresponding to the datapath's PIF.
+    #
+    # - The networks corresponding to any VLANs attached to the
+    #   datapath's PIF.
+    network_uuids = []
+    for nwpif in db.get_pifs_by_record({'device': pifrec['device'],
+                                        'host': pifrec['host']}):
+        net = db.get_pif_record(nwpif)['network']
+        network_uuids += [db.get_network_record(net)['uuid']]
+
     # Now modify the ovs-vswitchd config file.
     argv = []
     for port in set(del_ports):
@@ -876,6 +896,9 @@ def action_up(pif):
             os.unlink("%s/br-%s" % (vswitch_config_dir, bridge))
         except OSError:
             pass
+    argv += ['--del-match=bridge.%s.xs-network-uuids=*' % datapath]
+    argv += ['--add=bridge.%s.xs-network-uuids=%s' % (datapath, uuid)
+             for uuid in set(network_uuids)]
     if bond_master:
         argv += configure_bond(bond_master)
     modify_config(argv)