[virt-tools-list] [PATCH 02/10] Modified libvirtwork to use vmmNetwork objects.

Darryl L. Pierce dpierce at redhat.com
Thu May 26 18:37:17 UTC 2011


Modified the list_networks() API to return the UUIDs for network.

Modified get_network() to take as input a UUID rather than a name, and
return a vmmNetwork object.
---
 src/virtManagerTui/configscreen.py  |    9 +++++----
 src/virtManagerTui/libvirtworker.py |   20 ++++++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/virtManagerTui/configscreen.py b/src/virtManagerTui/configscreen.py
index 77fe983..61021e9 100644
--- a/src/virtManagerTui/configscreen.py
+++ b/src/virtManagerTui/configscreen.py
@@ -192,14 +192,15 @@ class NetworkListConfigScreen(ConfigScreen):
         ConfigScreen.__init__(self, title)
 
     def get_network_list_page(self, screen, defined=True, created=True):
-        networks = self.get_libvirt().list_networks(defined, created)
+        uuids = self.get_libvirt().list_networks(defined, created)
         result = None
 
-        if len(networks) > 0:
+        if len(uuids) > 0:
             self.__has_networks = True
             self.__network_list = Listbox(0)
-            for name in networks:
-                self.__network_list.append(name, name)
+            for uuid in uuids:
+                network = self.get_libvirt().get_network(uuid)
+                self.__network_list.append(uuid, network.get_name())
             result = self.__network_list
         else:
             self.__has_networks = False
diff --git a/src/virtManagerTui/libvirtworker.py b/src/virtManagerTui/libvirtworker.py
index 7421282..677f252 100644
--- a/src/virtManagerTui/libvirtworker.py
+++ b/src/virtManagerTui/libvirtworker.py
@@ -165,20 +165,28 @@ class LibvirtWorker:
         started -- Include only started networks. (default True)
 
         '''
+        self.__vmmconn.tick()
+        uuids = self.__vmmconn.list_net_uuids()
         result = []
-        if defined: result.extend(self.__conn.listDefinedNetworks())
-        if started: result.extend(self.__conn.listNetworks())
+        for uuid in uuids:
+            include = False
+            net = self.__vmmconn.get_net(uuid)
+            if net.is_active():
+                if started: include = True
+            else:
+                if defined: include = True
+            if include: result.append(uuid)
         return result
 
-    def get_network(self, name):
+    def get_network(self, uuid):
         '''Returns the specified network. Raises an exception if the netowrk does not exist.
 
         Keyword arguments:
-        name -- the name of the network
+        uuid -- the network's identifier
 
         '''
-        result = self.__conn.networkLookupByName(name)
-        if result is None: raise Exception("No such network exists: %s" % name)
+        result = self.__vmmconn.get_net(uuid)
+        if result is None: raise Exception("No such network exists: uuid=%s" % uuid)
 
         return result
 
-- 
1.7.5.1




More information about the virt-tools-list mailing list