[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH 11 of 33] interface-reconfigure: Add run_command utility to encapsulate os.spawnl usage



Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 85ffcded8ba0 -r 2ae49cc1bed6 scripts/interface-reconfigure
--- a/scripts/interface-reconfigure     Fri Dec 18 14:16:32 2009 +0000
+++ b/scripts/interface-reconfigure     Fri Dec 18 14:16:32 2009 +0000
@@ -72,6 +72,18 @@
     rec['pif_netdev_name'] = interface_name(pif)
     rec['message'] = "Bring %(action)s PIF %(uuid)s" % rec
     log("%(message)s: %(pif_netdev_name)s configured as 
%(ip_configuration_mode)s" % rec)
+
+#
+# Run external utilities
+#
+
+def run_command(command):
+    log("Running command: " + ' '.join(command))
+    rc = os.spawnl(os.P_WAIT, command[0], *command)
+    if rc != 0:
+        log("Command failed %d: " % rc + ' '.join(command))
+        return False
+    return True
 
 #
 # Exceptions.
@@ -256,34 +268,27 @@
     # bridges confusingly return "unknown" when they are up
     return state in ["up", "unknown"]
 
-def ifup(interface):
-    command = "/sbin/ifup"
-    if os.spawnl(os.P_WAIT, command, command, interface) != 0:
-        raise Error("Command failed: %s %s" % (command, interface))
-
 def ifdown(interface):
-    command = "/sbin/ifdown"
     if not interface_exists(interface):
         log("ifdown: interface %s does not exist, ignoring" % interface)
         return
-    if os.spawnl(os.P_WAIT, command, command, interface) != 0:
-        log("Command failed: %s %s" % (command, interface))
+    run_command(["/sbin/ifdown", interface])
+
+def ifup(interface):
+    run_command(["/sbin/ifup", interface])
+
 
 def delbr(bridge):
-    command = "/usr/sbin/brctl"
     if not interface_exists(bridge):
         log("delbr: bridge %s does not exist, ignoring" % bridge)
         return
-    if os.spawnl(os.P_WAIT, command, command, "delbr", bridge) != 0:
-        log("Command failed: %s delbr %s" % (command, bridge))
+    run_command(["/usr/sbin/brctl", "delbr", bridge])
 
 def vconfig_rem(vlan):
-    command = "/sbin/vconfig"
     if not interface_exists(vlan):
         log("vconfig del: vlan %s does not exist, ignoring" % vlan)
         return
-    if os.spawnl(os.P_WAIT, command, command, "rem", vlan) != 0:
-        log("Command failed: %s rem %s" % (command, vlan))
+    run_command(["/sbin/vconfig", "rem", vlan])
 
 def configure_ethtool(oc, f):
     # Options for "ethtool -s"
@@ -809,7 +814,7 @@
 
 def load_bonding_driver():
     log("Loading bonding driver")
-    os.spawnl(os.P_WAIT, "/sbin/modprobe", "/sbin/modprobe", "bonding")
+    run_command(["/sbin/modprobe", "bonding"])
     try:
         # bond_device_exists() uses the contents of sysfs_bonding_masters to 
work out which devices
         # have already been created.  Unfortunately the driver creates "bond0" 
automatically at

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.