patches/virt-manager-08-dladm-network.diff
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 17045 73df18f69f6e
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.

diff -urN virt-manager-0.6.1/src/virtManager/connection.py ../SUNWvirt-manager-0.6.1.hacked/virt-manager-0.6.1/src/virtManager/connection.py
--- virt-manager-0.6.1/src/virtManager/connection.py	2009-01-26 19:33:33.000000000 +0000
+++ ../SUNWvirt-manager-0.6.1.hacked/virt-manager-0.6.1/src/virtManager/connection.py	2009-11-27 11:36:20.689660379 +0000
@@ -30,6 +30,7 @@
 import threading
 import gtk
 import virtinst
+import re
 
 from virtManager.domain import vmmDomain
 from virtManager.network import vmmNetwork
@@ -142,7 +143,12 @@
 
             # Find info about all current present physical net devices
             # This is OS portable...
-            for path in self.hal_iface.FindDeviceByCapability("net"):
+            #for path in self.hal_iface.FindDeviceByCapability("net"):
+
+            # Not completely :( HAL on solaris does not support network devices
+            # So parsing dladm/ifconfig to get possible information 
+            output0=os.popen("/usr/sbin/dladm show-link -p -o LINK")
+            for path in output0.readlines():
                 self._net_phys_device_added(path)
         except:
             (_type, value, stacktrace) = sys.exc_info ()
@@ -154,37 +160,23 @@
 
     def _net_phys_device_added(self, path):
         logging.debug("Got physical device %s" % path)
-        obj = self.bus.get_object("org.freedesktop.Hal", path)
-        objif = dbus.Interface(obj, "org.freedesktop.Hal.Device")
-        if objif.QueryCapability("net"):
-            name = objif.GetPropertyString("net.interface")
-            # XXX ...but this is Linux specific again - patches welcomed
-            #sysfspath = objif.GetPropertyString("linux.sysfs_path")
-            # XXX hal gives back paths to /sys/devices/pci0000:00/0000:00:1e.0/0000:01:00.0/net/eth0
-            # which doesnt' work so well - we want this:
-            sysfspath = "/sys/class/net/" + name
-
-            # If running a device in bridged mode, there's a reasonable
-            # chance that the actual ethernet device has been renamed to
-            # something else. ethN -> pethN
-            psysfspath = sysfspath[0:len(sysfspath)-len(name)] + "p" + name
-            if os.path.exists(psysfspath):
-                logging.debug("Device %s named to p%s" % (name, name))
-                name = "p" + name
-                sysfspath = psysfspath
-
-            # Ignore devices that are slaves of a bond
-            if self._net_is_bonding_slave(name, sysfspath):
-                logging.debug("Skipping device %s in bonding slave" % name)
-                return
-
-            mac = objif.GetPropertyString("net.address")
+        # Parse dladm output here and use ifconfig -a to get more info
+        if not self.netdevs.has_key(path):
+            name = path.split('\n')[0]
+            shared = False
+            mac = None
+            bridge = name
+
+            # Parse ifconfig output for MAC address, and whether shared
+            output=os.popen("/sbin/ifconfig %s" % name)
+            for line in output.readlines():
+                if "ether" in line:
+                    mac = line.split(' ')[1]
+                    shared = True
+                    break
 
             # Add the main NIC
-            self._net_device_added(name, mac, sysfspath)
-
-            # Add any associated VLANs
-            self._net_tag_device_added(name, sysfspath)
+            self._net_device_added(name, mac, path, shared)
 
     def _net_tag_device_added(self, name, sysfspath):
         logging.debug("Checking for VLANs on %s" % sysfspath)
@@ -205,15 +197,16 @@
                         vlanpath = pvlanpath
                     self._net_device_added(vlanname, vlanmac, vlanpath)
 
-    def _net_device_added(self, name, mac, sysfspath):
+    def _net_device_added(self, name, mac, sysfspath, shared=None):
         # Race conditions mean we can occassionally see device twice
         if self.netdevs.has_key(name):
             return
 
         bridge = self._net_get_bridge_owner(name, sysfspath)
-        shared = False
-        if bridge is not None:
-            shared = True
+        if shared is None:
+            shared = False
+            if bridge is not None:
+                shared = True
 
         logging.debug("Adding net device %s %s %s (bridge: %s)" % (name, mac, sysfspath, str(bridge)))