[PATCH] Python bindings: Use virDomain/NetworkGetConnect instead of storing connection in domain/network object

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

 



Previously[1] I patched libvirt to add the virDomainGetConnect and virNetworkGetConnect functions. The rationale for these is explained here[2].

The attached patch makes the Python bindings use these functions instead of storing the connection object explicitly.

Rich.

[1]https://www.redhat.com/archives/libvir-list/2007-June/msg00365.html
[2]https://www.redhat.com/archives/libvir-list/2007-June/msg00352.html
Index: python/generator.py
===================================================================
RCS file: /data/cvs/libvirt/python/generator.py,v
retrieving revision 1.22
diff -u -p -r1.22 generator.py
--- python/generator.py	25 Jun 2007 15:56:18 -0000	1.22
+++ python/generator.py	23 Jul 2007 14:55:20 -0000
@@ -537,10 +537,10 @@ def buildStubs():
 # The type automatically remapped to generated classes
 #
 classes_type = {
-    "virDomainPtr": ("._o", "virDomain(self,_obj=%s)", "virDomain"),
-    "virDomain *": ("._o", "virDomain(self, _obj=%s)", "virDomain"),
-    "virNetworkPtr": ("._o", "virNetwork(self, _obj=%s)", "virNetwork"),
-    "virNetwork *": ("._o", "virNetwork(self, _obj=%s)", "virNetwork"),
+    "virDomainPtr": ("._o", "virDomain(_obj=%s)", "virDomain"),
+    "virDomain *": ("._o", "virDomain(_obj=%s)", "virDomain"),
+    "virNetworkPtr": ("._o", "virNetwork(_obj=%s)", "virNetwork"),
+    "virNetwork *": ("._o", "virNetwork(_obj=%s)", "virNetwork"),
     "virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"),
     "virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"),
 }
@@ -869,20 +869,11 @@ def buildWrappers():
 	    else:
 		txt.write("Class %s()\n" % (classname))
 		classes.write("class %s:\n" % (classname))
-                if classname == "virDomain" or classname == "virNetwork":
-                    # NB: Earlier versions of libvirt did not provide
-                    # vir{Domain,Network}GetConnect, so we had to explicitly
-                    # store the connection object in _conn.  In future
-                    # we won't need to do this.
-                    classes.write("    def __init__(self, conn, _obj=None):\n")
-                else:
-                    classes.write("    def __init__(self, _obj=None):\n")
+                classes.write("    def __init__(self, _obj=None):\n")
 		if reference_keepers.has_key(classname):
 		    list = reference_keepers[classname]
 		    for ref in list:
 		        classes.write("        self.%s = None\n" % ref[1])
-                if classname == "virDomain" or classname == "virNetwork":
-                    classes.write("        self._conn = conn\n")
 		classes.write("        if _obj != None:self._o = _obj;return\n")
 		classes.write("        self._o = None\n\n");
 	    destruct=None
Index: python/libvir.py
===================================================================
RCS file: /data/cvs/libvirt/python/libvir.py,v
retrieving revision 1.5
diff -u -p -r1.5 libvir.py
--- python/libvir.py	29 May 2007 14:58:27 -0000	1.5
+++ python/libvir.py	23 Jul 2007 14:55:20 -0000
@@ -13,9 +13,9 @@ class libvirtError(Exception):
         Exception.__init__(self, msg)
 
         if dom is not None:
-            conn = dom._conn
+            conn = libvirtmod.virDomainGetConnect (dom)
         elif net is not None:
-            conn = net._conn
+            conn = libvirtmod.virNetworkGetConnect (net)
 
         if conn is None:
             self.err = virGetLastError()
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]