New utility ovs-vsctl.
[openvswitch] / xenserver / opt_xensource_libexec_interface-reconfigure
index fdb91abe5595172f1d27cc3e30e7a2a0e416de0c..13c68884493d186f5964115adb2a1238f13aff94 100755 (executable)
@@ -8,6 +8,7 @@
     %(command-name)s --session <SESSION-REF> --pif <PIF-REF> [up|down|rewrite]
     %(command-name)s --force <BRIDGE> [up|down|rewrite <CONFIG>]
     %(command-name)s --force all down
+    %(command-name)s init-dbcache
 
     where,
           <CONFIG> = --device=<INTERFACE> --mode=dhcp
 # 3. A network may have an associated bridge, allowing vifs to be attached
 # 4. A network may be bridgeless (there's no point having a bridge over a storage pif)
 
-# XXX: --force-interface=all down
-
-# XXX: --force-interface rewrite
-
-# XXX: Sometimes this leaves "orphaned" datapaths, e.g. a datapath whose
-#      only port is the local port.  Should delete those.
-
-# XXX: This can leave crud in ovs-vswitchd.conf in this scenario:
-#      - Create bond in XenCenter.
-#      - Create VLAN on bond in XenCenter.
-#      - Attempt to delete bond in XenCenter (this will fail because there
-#        is a VLAN on the bond, although the error may not be reported
-#        until the next step)
-#      - Delete VLAN in XenCenter.
-#      - Delete bond in XenCenter.
-# At this point there will still be some configuration data for the bond
-# or the VLAN in ovs-vswitchd.conf.
-
 import XenAPI
 import os, sys, getopt, time, signal
 import syslog
@@ -456,7 +439,11 @@ class DatabaseCache(object):
             rec = session.xenapi.network.get_record(n)
             self.__networks[n] = {}
             for f in NETWORK_ATTRS:
-                self.__networks[n][f] = rec[f]
+                if f == "PIFs":
+                    # drop PIFs on other hosts
+                    self.__networks[n][f] = [p for p in rec[f] if self.__pif_on_host(p)]
+                else:
+                    self.__networks[n][f] = rec[f]
             self.__networks[n]['other_config'] = {}
             for f in NETWORK_OTHERCONFIG_ATTRS:
                 if not rec['other_config'].has_key(f): continue
@@ -1044,7 +1031,7 @@ def configure_physdev(pif):
     run_ethtool(device, oc)
 
 def modify_config(commands):
-    run_command(['/root/vswitch/bin/ovs-cfg-mod', '-vANY:console:emer',
+    run_command(['/usr/bin/ovs-cfg-mod', '-vANY:console:emer',
                  '-F', '/etc/ovs-vswitchd.conf']
                 + commands + ['-c'])
     run_command(['/sbin/service', 'vswitch', 'reload'])
@@ -1455,6 +1442,9 @@ def main(argv=None):
         if len(force_rewrite_config) and not (force_interface and action == "rewrite"):
             raise Usage("\"--force rewrite\" needed for --device, --mode, --ip, --netmask, and --gateway")
 
+        if action == "init-dbcache" and arglist:
+            raise Usage("\"init-dbcache\" action does not accept any options")
+
         global db
         if force_interface:
             log("Force interface %s %s" % (force_interface, action))
@@ -1472,6 +1462,8 @@ def main(argv=None):
                     action_down(pif)
                 else:
                     raise Usage("Unknown action %s"  % action)
+        elif action == "init-dbcache":
+            DatabaseCache().save(dbcache_file)
         else:
             db = DatabaseCache(session_ref=session)
 
@@ -1505,7 +1497,6 @@ def main(argv=None):
                 raise Usage("Unknown action %s"  % action)
 
             # Save cache.
-            pifrec = db.get_pif_record(pif)
             db.save(dbcache_file)
         
     except Usage, err: