Index: include/libvirt/libvirt.h
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h,v
retrieving revision 1.46
diff -u -p -r1.46 libvirt.h
--- include/libvirt/libvirt.h	25 Jun 2007 13:26:02 -0000	1.46
+++ include/libvirt/libvirt.h	25 Jun 2007 13:53:45 -0000
@@ -296,6 +296,11 @@ int			virConnectNumOfDomains	(virConnect
 
 
 /*
+ * Get connection from domain.
+ */
+virConnectPtr		virDomainGetConnect     (virDomainPtr domain);
+
+/*
  * Domain creation and destruction
  */
 virDomainPtr		virDomainCreateLinux	(virConnectPtr conn,
@@ -524,6 +529,11 @@ typedef struct _virNetwork virNetwork;
 typedef virNetwork *virNetworkPtr;
 
 /*
+ * Get connection from domain.
+ */
+virConnectPtr		virNetworkGetConnect    (virNetworkPtr network);
+
+/*
  * List active networks
  */
 int			virConnectNumOfNetworks	(virConnectPtr conn);
Index: include/libvirt/libvirt.h.in
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v
retrieving revision 1.28
diff -u -p -r1.28 libvirt.h.in
--- include/libvirt/libvirt.h.in	25 Jun 2007 13:26:02 -0000	1.28
+++ include/libvirt/libvirt.h.in	25 Jun 2007 13:53:45 -0000
@@ -296,6 +296,11 @@ int			virConnectNumOfDomains	(virConnect
 
 
 /*
+ * Get connection from domain.
+ */
+virConnectPtr		virDomainGetConnect     (virDomainPtr domain);
+
+/*
  * Domain creation and destruction
  */
 virDomainPtr		virDomainCreateLinux	(virConnectPtr conn,
@@ -524,6 +529,11 @@ typedef struct _virNetwork virNetwork;
 typedef virNetwork *virNetworkPtr;
 
 /*
+ * Get connection from domain.
+ */
+virConnectPtr		virNetworkGetConnect    (virNetworkPtr network);
+
+/*
  * List active networks
  */
 int			virConnectNumOfNetworks	(virConnectPtr conn);
Index: python/generator.py
===================================================================
RCS file: /data/cvs/libvirt/python/generator.py,v
retrieving revision 1.21
diff -u -p -r1.21 generator.py
--- python/generator.py	29 May 2007 14:58:27 -0000	1.21
+++ python/generator.py	25 Jun 2007 13:53:46 -0000
@@ -870,6 +870,10 @@ def buildWrappers():
 		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
+                    # virDomainGetConnect, 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")
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.78
diff -u -p -r1.78 libvirt.c
--- src/libvirt.c	25 Jun 2007 08:23:10 -0000	1.78
+++ src/libvirt.c	25 Jun 2007 13:53:48 -0000
@@ -546,6 +546,26 @@ virConnectNumOfDomains(virConnectPtr con
 }
 
 /**
+ * virDomainGetConnect:
+ * @dom: pointer to a domain
+ *
+ * Returns the connection pointer associated with a domain.  The
+ * reference counter on the connection is not increased by this
+ * call.
+ *
+ * Returns the virConnectPtr or NULL in case of failure.
+ */
+virConnectPtr
+virDomainGetConnect (virDomainPtr dom)
+{
+    if (!VIR_IS_DOMAIN (dom)) {
+        virLibDomainError (dom, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        return NULL;
+    }
+    return dom->conn;
+}
+
+/**
  * virDomainCreateLinux:
  * @conn: pointer to the hypervisor connection
  * @xmlDesc: an XML description of the domain
@@ -2037,6 +2057,26 @@ virDomainDetachDevice(virDomainPtr domai
 }
 
 /**
+ * virNetworkGetConnect:
+ * @net: pointer to a network
+ *
+ * Returns the connection pointer associated with a network.  The
+ * reference counter on the connection is not increased by this
+ * call.
+ *
+ * Returns the virConnectPtr or NULL in case of failure.
+ */
+virConnectPtr
+virNetworkGetConnect (virNetworkPtr net)
+{
+    if (!VIR_IS_NETWORK (net)) {
+        virLibNetworkError (net, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
+        return NULL;
+    }
+    return net->conn;
+}
+
+/**
  * virConnectNumOfNetworks:
  * @conn: pointer to the hypervisor connection
  *
Index: src/libvirt_sym.version
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt_sym.version,v
retrieving revision 1.21
diff -u -p -r1.21 libvirt_sym.version
--- src/libvirt_sym.version	5 Jun 2007 12:06:08 -0000	1.21
+++ src/libvirt_sym.version	25 Jun 2007 13:53:48 -0000
@@ -1,13 +1,14 @@
 {
     global:
         virInitialize;
+        virConnectOpen;
+        virConnectOpenReadOnly;
 	virConnectClose;
 	virConnectGetType;
 	virConnectGetVersion;
+	virDomainGetConnect;
 	virConnectListDomains;
 	virConnectNumOfDomains;
-        virConnectOpen;
-        virConnectOpenReadOnly;
         virDomainCreate;
 	virDomainCreateLinux;
         virDomainDefineXML;
@@ -66,6 +67,7 @@
 	virDomainAttachDevice;
 	virDomainDetachDevice;
 
+	virNetworkGetConnect;
 	virConnectNumOfNetworks;
 	virConnectListNetworks;
 	virConnectNumOfDefinedNetworks;
