WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH 11 of 33] interface-reconfigure: Add run_command utilit

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 11 of 33] interface-reconfigure: Add run_command utility to encapsulate os.spawnl usage
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 18 Dec 2009 14:17:06 +0000
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 18 Dec 2009 06:19:23 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1261145815@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
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

<Prev in Thread] Current Thread [Next in Thread>