]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add virConnectGetLibvirtVersion API
authorCole Robinson <crobinso@redhat.com>
Thu, 12 Nov 2009 15:53:26 +0000 (10:53 -0500)
committerCole Robinson <crobinso@redhat.com>
Thu, 12 Nov 2009 15:53:26 +0000 (10:53 -0500)
There is currently no way to determine the libvirt version of a remote
libvirtd we are connected to. This is a useful piece of data to enable
feature detection.

25 files changed:
daemon/remote.c
daemon/remote_dispatch_prototypes.h
daemon/remote_dispatch_ret.h
daemon/remote_dispatch_table.h
include/libvirt/libvirt.h.in
python/generator.py
python/libvirt-override-api.xml
python/libvirt-override.c
src/driver.h
src/esx/esx_driver.c
src/libvirt.c
src/libvirt_public.syms
src/lxc/lxc_driver.c
src/opennebula/one_driver.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_driver.c
src/remote/remote_driver.c
src/remote/remote_protocol.c
src/remote/remote_protocol.h
src/remote/remote_protocol.x
src/test/test_driver.c
src/uml/uml_driver.c
src/vbox/vbox_tmpl.c
src/xen/xen_driver.c

index 8dccb57641ddd31e89413e0466da820c3797fda5..31176153eebde99fde45cb6cd32295cf96fc1d48 100644 (file)
@@ -258,6 +258,26 @@ remoteDispatchGetVersion (struct qemud_server *server ATTRIBUTE_UNUSED,
     return 0;
 }
 
+static int
+remoteDispatchGetLibVersion (struct qemud_server *server ATTRIBUTE_UNUSED,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
+                             remote_message_header *hdr ATTRIBUTE_UNUSED,
+                             remote_error *rerr,
+                             void *args ATTRIBUTE_UNUSED,
+                             remote_get_lib_version_ret *ret)
+{
+    unsigned long libVer;
+
+    if (virConnectGetLibVersion (conn, &libVer) == -1) {
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    ret->lib_ver = libVer;
+    return 0;
+}
+
 static int
 remoteDispatchGetHostname (struct qemud_server *server ATTRIBUTE_UNUSED,
                            struct qemud_client *client ATTRIBUTE_UNUSED,
index 7c2da07a9f515f2085ee2af7236d54d65e800377..b05a9a48e57606f4f49321943e82b2b0e1eea71c 100644 (file)
@@ -466,6 +466,14 @@ static int remoteDispatchGetHostname(
     remote_error *err,
     void *args,
     remote_get_hostname_ret *ret);
+static int remoteDispatchGetLibVersion(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    void *args,
+    remote_get_lib_version_ret *ret);
 static int remoteDispatchGetMaxVcpus(
     struct qemud_server *server,
     struct qemud_client *client,
index c37744a39ecd8ff9f3682a8aa9b420f85d190acf..4543dc5e2fda43f341baa5856730ba27dc382bed 100644 (file)
     remote_storage_pool_is_active_ret val_remote_storage_pool_is_active_ret;
     remote_storage_pool_is_persistent_ret val_remote_storage_pool_is_persistent_ret;
     remote_interface_is_active_ret val_remote_interface_is_active_ret;
+    remote_get_lib_version_ret val_remote_get_lib_version_ret;
index cb640b67ca28193fe8f893582ac09c70aa53caf0..f7c8a13ea113ce407ad614dd1e10eab69f07593b 100644 (file)
     .args_filter = (xdrproc_t) xdr_remote_interface_is_active_args,
     .ret_filter = (xdrproc_t) xdr_remote_interface_is_active_ret,
 },
+{   /* GetLibVersion => 157 */
+    .fn = (dispatch_fn) remoteDispatchGetLibVersion,
+    .args_filter = (xdrproc_t) xdr_void,
+    .ret_filter = (xdrproc_t) xdr_remote_get_lib_version_ret,
+},
index 311ee838ec9904d8c9c346e757ed1847553d17a7..5bc76947c9783abb28af90b099722fe6c759b435 100644 (file)
@@ -489,6 +489,8 @@ int                     virConnectClose         (virConnectPtr conn);
 const char *            virConnectGetType       (virConnectPtr conn);
 int                     virConnectGetVersion    (virConnectPtr conn,
                                                  unsigned long *hvVer);
+int                     virConnectGetLibVersion (virConnectPtr conn,
+                                                 unsigned long *libVer);
 char *                  virConnectGetHostname   (virConnectPtr conn);
 char *                  virConnectGetURI        (virConnectPtr conn);
 
index 21b413772bc1eac2eb725670f4affcfc073a89ee..0b321169a03e0002b558a02f24394a168de3d326 100755 (executable)
@@ -255,6 +255,7 @@ foreign_encoding_args = (
 # Class methods which are written by hand in libvir.c but the Python-level
 # code is still automatically generated (so they are not in skip_function()).
 skip_impl = (
+    'virConnectGetLibVersion',
     'virConnectListDomainsID',
     'virConnectListDefinedDomains',
     'virConnectListNetworks',
index 148b89be11a0de16bd05dc2950289fb3a8e160cb..4e551825c69d8007b84c81736b34b43150f19da7 100644 (file)
@@ -1,6 +1,11 @@
 <?xml version="1.0"?>
 <api name='libvir-python'>
   <symbols>
+    <function name="virConnectGetLibVersion" file='python'>
+      <info>Returns the libvirt version of the connection host</info>
+      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+      <return type='int' info="0 on success, -1 on error"/>
+    </function>
     <function name="virConnectListDomainsID" file='python'>
       <info>Returns the list of the ID of the domains on the hypervisor</info>
       <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
index 6c6155b9f28835cf25e09ef5fea6036bdcd8f19f..20037efc5ccda77c148092cfdd8dd6527e70a60e 100644 (file)
@@ -728,6 +728,31 @@ libvirt_virGetVersion (PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
         return Py_BuildValue ((char *) "kk", libVer, typeVer);
 }
 
+static PyObject *
+libvirt_virConnectGetLibVersion (PyObject *self ATTRIBUTE_UNUSED,
+                                     PyObject *args)
+{
+    unsigned long libVer;
+    int c_retval;
+    virConnectPtr conn;
+    PyObject *pyobj_conn;
+
+    if (!PyArg_ParseTuple(args, (char *)"O:virConnectGetLibVersion",
+                          &pyobj_conn))
+        return(NULL);
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+
+    c_retval = virConnectGetLibVersion(conn, &libVer);
+
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_retval == -1)
+        return VIR_PY_INT_FAIL;
+
+    return PyInt_FromLong (libVer);
+}
 
 static PyObject *
 libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
@@ -2398,6 +2423,7 @@ libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
 static PyMethodDef libvirtMethods[] = {
 #include "libvirt-export.c"
     {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
+    {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
     {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
     {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
     {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},
index a9fedc2d316020d724eba082e1beecba96cb7f61..09ce8e23875713bead44881b86f889babf6b8d64 100644 (file)
@@ -71,6 +71,9 @@ typedef const char *
 typedef int
         (*virDrvGetVersion)            (virConnectPtr conn,
                                          unsigned long *hvVer);
+typedef int
+        (*virDrvGetLibVersion)      (virConnectPtr conn,
+                                     unsigned long *libVer);
 typedef char *
     (*virDrvGetHostname)    (virConnectPtr conn);
 typedef char *
@@ -366,6 +369,7 @@ struct _virDriver {
     virDrvDrvSupportsFeature   supports_feature;
     virDrvGetType                      type;
     virDrvGetVersion           version;
+    virDrvGetLibVersion                libvirtVersion;
     virDrvGetHostname       getHostname;
     virDrvGetMaxVcpus          getMaxVcpus;
     virDrvNodeGetInfo          nodeGetInfo;
index 43776c04a3b0ce11c0f6173fd68396654b397ca2..fe75aa352c7ea542330b503c7c49decf7555915d 100644 (file)
@@ -3359,6 +3359,7 @@ static virDriver esxDriver = {
     esxSupportsFeature,              /* supports_feature */
     esxGetType,                      /* type */
     esxGetVersion,                   /* version */
+    NULL,                            /* libvirtVersion (impl. in libvirt.c) */
     esxGetHostname,                  /* hostname */
     NULL,                            /* getMaxVcpus */
     esxNodeGetInfo,                  /* nodeGetInfo */
index 4598f26ce01c3bb490beaf9353612549500230d8..05e45f35f074d7f2d4120da676e2f34c775ad5a5 100644 (file)
@@ -1439,6 +1439,50 @@ error:
     return -1;
 }
 
+/**
+ * virConnectGetLibVersion:
+ * @conn: pointer to the hypervisor connection
+ * @libVer: returns the libvirt library version used on the connection (OUT)
+ *
+ * Provides @libVer, which is the version of libvirt used by the
+ *   daemon running on the @conn host
+ *
+ * Returns -1 in case of failure, 0 otherwise, and values for @libVer have
+ *      the format major * 1,000,000 + minor * 1,000 + release.
+ */
+int
+virConnectGetLibVersion(virConnectPtr conn, unsigned long *libVer)
+{
+    int ret = -1;
+    DEBUG("conn=%p, libVir=%p", conn, libVer);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        return -1;
+    }
+
+    if (libVer == NULL) {
+        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->libvirtVersion) {
+        ret = conn->driver->libvirtVersion(conn, libVer);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+   *libVer = LIBVIR_VERSION_NUMBER;
+    ret = 0;
+error:
+    /* Copy to connection error object for back compatability */
+    virSetConnError(conn);
+    return ret;
+}
+
 /**
  * virConnectGetHostname:
  * @conn: pointer to a hypervisor connection
index 739f8b0ab77831806fb47067ca9027ffce1eb5c2..b4f57e77b1f9f932632254425ddc9145971052da 100644 (file)
@@ -331,6 +331,7 @@ LIBVIRT_0.7.2 {
 
 LIBVIRT_0.7.3 {
     global:
+       virConnectGetLibVersion;
        virConnectIsEncrypted;
        virConnectIsSecure;
        virDomainIsActive;
index 7af4161fb8372f8704b7e8bcd6646d9eb8f11dae..d0fc01a316ba25615812811dce590a27f400804f 100644 (file)
@@ -2337,6 +2337,7 @@ static virDriver lxcDriver = {
     NULL, /* supports_feature */
     NULL, /* type */
     lxcVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     NULL, /* getMaxVcpus */
     nodeGetInfo, /* nodeGetInfo */
index 4ecb81ef30dced7b7fca8aae6e4a5ccb52ec1be8..4857f54048c5bf1b3e7d11297f463a8b30248cf3 100644 (file)
@@ -715,6 +715,7 @@ static virDriver oneDriver = {
     NULL, /* supports_feature */
     NULL, /* type */
     oneVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     NULL, /* getHostname */
     NULL, /* getMaxVcpus */
     NULL, /* nodeGetInfo */
index 75b807aa50d29d5f077393766851163efde9640b..aac2eb8056291ff7d5e52dfe70b1b8e127e39ab4 100644 (file)
@@ -1468,6 +1468,7 @@ static virDriver openvzDriver = {
     NULL, /* supports_feature */
     openvzGetType, /* type */
     openvzGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     NULL, /* getHostname */
     openvzGetMaxVCPUs, /* getMaxVcpus */
     nodeGetInfo, /* nodeGetInfo */
index c73834cc9906897a9fbf2c4c81ba69ebaff05a72..ea9555aa0f084bb30a94f959814e36f0306fed58 100644 (file)
@@ -1584,6 +1584,7 @@ virDriver phypDriver = {
     NULL,                       /* supports_feature */
     NULL,                       /* type */
     NULL,                       /* version */
+    NULL,                       /* libvirtVersion (impl. in libvirt.c) */
     NULL,                       /* getHostname */
     NULL,                       /* getMaxVcpus */
     NULL,                       /* nodeGetInfo */
index b0239022027b6d79e6638241bd26408e42d00cc8..968118ecaa204033c639d93d289f7d2ae37e7887 100644 (file)
@@ -7485,6 +7485,7 @@ static virDriver qemuDriver = {
     qemudSupportsFeature, /* supports_feature */
     qemudGetType, /* type */
     qemudGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     qemudGetMaxVCPUs, /* getMaxVcpus */
     nodeGetInfo, /* nodeGetInfo */
index 71678942de6161e31df7f47d69b1f1b8c724cdd9..ecc0c17fc01110a2dd50f7c109443fc06648fa98 100644 (file)
@@ -1550,6 +1550,30 @@ done:
     return rv;
 }
 
+static int
+remoteGetLibVersion (virConnectPtr conn, unsigned long *libVer)
+{
+    int rv = -1;
+    remote_get_lib_version_ret ret;
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    memset (&ret, 0, sizeof ret);
+    if (call (conn, priv, 0, REMOTE_PROC_GET_LIB_VERSION,
+              (xdrproc_t) xdr_void, (char *) NULL,
+              (xdrproc_t) xdr_remote_get_lib_version_ret,
+              (char *) &ret) == -1)
+        goto done;
+
+    if (libVer) *libVer = ret.lib_ver;
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 static char *
 remoteGetHostname (virConnectPtr conn)
 {
@@ -8740,6 +8764,7 @@ static virDriver remote_driver = {
     remoteSupportsFeature, /* supports_feature */
     remoteType, /* type */
     remoteGetVersion, /* version */
+    remoteGetLibVersion, /* libvirtVersion */
     remoteGetHostname, /* getHostname */
     remoteGetMaxVcpus, /* getMaxVcpus */
     remoteNodeGetInfo, /* nodeGetInfo */
index 939bb4e2c1dc7d20d4e43770b3d03b5acd0f9675..a10558a1ba66790f79e9fd7165fa999a0abe324e 100644 (file)
@@ -308,6 +308,15 @@ xdr_remote_get_version_ret (XDR *xdrs, remote_get_version_ret *objp)
         return TRUE;
 }
 
+bool_t
+xdr_remote_get_lib_version_ret (XDR *xdrs, remote_get_lib_version_ret *objp)
+{
+
+         if (!xdr_int64_t (xdrs, &objp->lib_ver))
+                 return FALSE;
+        return TRUE;
+}
+
 bool_t
 xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp)
 {
index 885695c39e347afb5f47fa7f611012d4d34b51ba..2ba9be42c2e58ba44278a7bc6af3d51c9aa93d5c 100644 (file)
@@ -179,6 +179,11 @@ struct remote_get_version_ret {
 };
 typedef struct remote_get_version_ret remote_get_version_ret;
 
+struct remote_get_lib_version_ret {
+        int64_t lib_ver;
+};
+typedef struct remote_get_lib_version_ret remote_get_lib_version_ret;
+
 struct remote_get_hostname_ret {
         remote_nonnull_string hostname;
 };
@@ -1771,6 +1776,7 @@ enum remote_procedure {
         REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154,
         REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155,
         REMOTE_PROC_INTERFACE_IS_ACTIVE = 156,
+        REMOTE_PROC_GET_LIB_VERSION = 157,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -1828,6 +1834,7 @@ extern  bool_t xdr_remote_supports_feature_args (XDR *, remote_supports_feature_
 extern  bool_t xdr_remote_supports_feature_ret (XDR *, remote_supports_feature_ret*);
 extern  bool_t xdr_remote_get_type_ret (XDR *, remote_get_type_ret*);
 extern  bool_t xdr_remote_get_version_ret (XDR *, remote_get_version_ret*);
+extern  bool_t xdr_remote_get_lib_version_ret (XDR *, remote_get_lib_version_ret*);
 extern  bool_t xdr_remote_get_hostname_ret (XDR *, remote_get_hostname_ret*);
 extern  bool_t xdr_remote_get_uri_ret (XDR *, remote_get_uri_ret*);
 extern  bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*);
@@ -2098,6 +2105,7 @@ extern bool_t xdr_remote_supports_feature_args ();
 extern bool_t xdr_remote_supports_feature_ret ();
 extern bool_t xdr_remote_get_type_ret ();
 extern bool_t xdr_remote_get_version_ret ();
+extern bool_t xdr_remote_get_lib_version_ret ();
 extern bool_t xdr_remote_get_hostname_ret ();
 extern bool_t xdr_remote_get_uri_ret ();
 extern bool_t xdr_remote_get_max_vcpus_args ();
index 1886282a0d8e5b2182ef5a1a1d840249845a6c31..92f7010f79bdb1a1c073529d934f0f6ac743a4b6 100644 (file)
@@ -302,6 +302,10 @@ struct remote_get_version_ret {
     hyper hv_ver;
 };
 
+struct remote_get_lib_version_ret {
+    hyper lib_ver;
+};
+
 struct remote_get_hostname_ret {
     remote_nonnull_string hostname;
 };
@@ -1606,8 +1610,8 @@ enum remote_procedure {
     REMOTE_PROC_NETWORK_IS_PERSISTENT = 153,
     REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154,
     REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155,
-    REMOTE_PROC_INTERFACE_IS_ACTIVE = 156
-
+    REMOTE_PROC_INTERFACE_IS_ACTIVE = 156,
+    REMOTE_PROC_GET_LIB_VERSION = 157
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
index e882f0ca96c8f09ce8deef8df45682740ed124f9..d03d55d560fd5aac7492a7981218d56f3ada4ae9 100644 (file)
@@ -5167,6 +5167,7 @@ static virDriver testDriver = {
     NULL, /* supports_feature */
     NULL, /* type */
     testGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     testGetMaxVCPUs, /* getMaxVcpus */
     testNodeGetInfo, /* nodeGetInfo */
index 5e8aa589217852c5dad85a0419361ce368f73888..7ef5a0b47a4c89a43f0a70d249276adfea824be1 100644 (file)
@@ -1822,6 +1822,7 @@ static virDriver umlDriver = {
     NULL, /* supports_feature */
     umlGetType, /* type */
     umlGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     NULL, /* getMaxVcpus */
     nodeGetInfo, /* nodeGetInfo */
index 8154f713023d590098d6aba289966e97f7d1d928..cd60b729ceb237cf29e02b94f57f39c46caf3d2e 100644 (file)
@@ -6500,6 +6500,7 @@ virDriver NAME(Driver) = {
     NULL, /* supports_feature */
     NULL, /* type */
     vboxGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     vboxGetMaxVcpus, /* getMaxVcpus */
     nodeGetInfo, /* nodeGetInfo */
index 80e81326ff5bc6a5e111c24906648dc44cbc520d..4bfcce4eee39c0cb41c28248f4c1d68d7bc5f8ce 100644 (file)
@@ -1794,6 +1794,7 @@ static virDriver xenUnifiedDriver = {
     xenUnifiedSupportsFeature, /* supports_feature */
     xenUnifiedType, /* type */
     xenUnifiedGetVersion, /* version */
+    NULL, /* libvirtVersion (impl. in libvirt.c) */
     virGetHostname, /* getHostname */
     xenUnifiedGetMaxVcpus, /* getMaxVcpus */
     xenUnifiedNodeGetInfo, /* nodeGetInfo */