Add virConnectGetLibvirtVersion API

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.
This commit is contained in:
Cole Robinson 2009-11-12 10:53:26 -05:00
parent 632be33689
commit ce4c0bf5a2
25 changed files with 175 additions and 2 deletions

View File

@ -258,6 +258,26 @@ remoteDispatchGetVersion (struct qemud_server *server ATTRIBUTE_UNUSED,
return 0; 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 static int
remoteDispatchGetHostname (struct qemud_server *server ATTRIBUTE_UNUSED, remoteDispatchGetHostname (struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED,

View File

@ -466,6 +466,14 @@ static int remoteDispatchGetHostname(
remote_error *err, remote_error *err,
void *args, void *args,
remote_get_hostname_ret *ret); 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( static int remoteDispatchGetMaxVcpus(
struct qemud_server *server, struct qemud_server *server,
struct qemud_client *client, struct qemud_client *client,

View File

@ -114,3 +114,4 @@
remote_storage_pool_is_active_ret val_remote_storage_pool_is_active_ret; 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_storage_pool_is_persistent_ret val_remote_storage_pool_is_persistent_ret;
remote_interface_is_active_ret val_remote_interface_is_active_ret; remote_interface_is_active_ret val_remote_interface_is_active_ret;
remote_get_lib_version_ret val_remote_get_lib_version_ret;

View File

@ -787,3 +787,8 @@
.args_filter = (xdrproc_t) xdr_remote_interface_is_active_args, .args_filter = (xdrproc_t) xdr_remote_interface_is_active_args,
.ret_filter = (xdrproc_t) xdr_remote_interface_is_active_ret, .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,
},

View File

@ -489,6 +489,8 @@ int virConnectClose (virConnectPtr conn);
const char * virConnectGetType (virConnectPtr conn); const char * virConnectGetType (virConnectPtr conn);
int virConnectGetVersion (virConnectPtr conn, int virConnectGetVersion (virConnectPtr conn,
unsigned long *hvVer); unsigned long *hvVer);
int virConnectGetLibVersion (virConnectPtr conn,
unsigned long *libVer);
char * virConnectGetHostname (virConnectPtr conn); char * virConnectGetHostname (virConnectPtr conn);
char * virConnectGetURI (virConnectPtr conn); char * virConnectGetURI (virConnectPtr conn);

View File

@ -255,6 +255,7 @@ foreign_encoding_args = (
# Class methods which are written by hand in libvir.c but the Python-level # 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()). # code is still automatically generated (so they are not in skip_function()).
skip_impl = ( skip_impl = (
'virConnectGetLibVersion',
'virConnectListDomainsID', 'virConnectListDomainsID',
'virConnectListDefinedDomains', 'virConnectListDefinedDomains',
'virConnectListNetworks', 'virConnectListNetworks',

View File

@ -1,6 +1,11 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<api name='libvir-python'> <api name='libvir-python'>
<symbols> <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'> <function name="virConnectListDomainsID" file='python'>
<info>Returns the list of the ID of the domains on the hypervisor</info> <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'/> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>

View File

@ -728,6 +728,31 @@ libvirt_virGetVersion (PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return Py_BuildValue ((char *) "kk", libVer, typeVer); 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 * static PyObject *
libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
@ -2398,6 +2423,7 @@ libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
static PyMethodDef libvirtMethods[] = { static PyMethodDef libvirtMethods[] = {
#include "libvirt-export.c" #include "libvirt-export.c"
{(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL}, {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL},
{(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL},
{(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL}, {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL},
{(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL}, {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL},

View File

@ -71,6 +71,9 @@ typedef const char *
typedef int typedef int
(*virDrvGetVersion) (virConnectPtr conn, (*virDrvGetVersion) (virConnectPtr conn,
unsigned long *hvVer); unsigned long *hvVer);
typedef int
(*virDrvGetLibVersion) (virConnectPtr conn,
unsigned long *libVer);
typedef char * typedef char *
(*virDrvGetHostname) (virConnectPtr conn); (*virDrvGetHostname) (virConnectPtr conn);
typedef char * typedef char *
@ -366,6 +369,7 @@ struct _virDriver {
virDrvDrvSupportsFeature supports_feature; virDrvDrvSupportsFeature supports_feature;
virDrvGetType type; virDrvGetType type;
virDrvGetVersion version; virDrvGetVersion version;
virDrvGetLibVersion libvirtVersion;
virDrvGetHostname getHostname; virDrvGetHostname getHostname;
virDrvGetMaxVcpus getMaxVcpus; virDrvGetMaxVcpus getMaxVcpus;
virDrvNodeGetInfo nodeGetInfo; virDrvNodeGetInfo nodeGetInfo;

View File

@ -3359,6 +3359,7 @@ static virDriver esxDriver = {
esxSupportsFeature, /* supports_feature */ esxSupportsFeature, /* supports_feature */
esxGetType, /* type */ esxGetType, /* type */
esxGetVersion, /* version */ esxGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
esxGetHostname, /* hostname */ esxGetHostname, /* hostname */
NULL, /* getMaxVcpus */ NULL, /* getMaxVcpus */
esxNodeGetInfo, /* nodeGetInfo */ esxNodeGetInfo, /* nodeGetInfo */

View File

@ -1439,6 +1439,50 @@ error:
return -1; 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: * virConnectGetHostname:
* @conn: pointer to a hypervisor connection * @conn: pointer to a hypervisor connection

View File

@ -331,6 +331,7 @@ LIBVIRT_0.7.2 {
LIBVIRT_0.7.3 { LIBVIRT_0.7.3 {
global: global:
virConnectGetLibVersion;
virConnectIsEncrypted; virConnectIsEncrypted;
virConnectIsSecure; virConnectIsSecure;
virDomainIsActive; virDomainIsActive;

View File

@ -2337,6 +2337,7 @@ static virDriver lxcDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
NULL, /* type */ NULL, /* type */
lxcVersion, /* version */ lxcVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
NULL, /* getMaxVcpus */ NULL, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */ nodeGetInfo, /* nodeGetInfo */

View File

@ -715,6 +715,7 @@ static virDriver oneDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
NULL, /* type */ NULL, /* type */
oneVersion, /* version */ oneVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
NULL, /* getHostname */ NULL, /* getHostname */
NULL, /* getMaxVcpus */ NULL, /* getMaxVcpus */
NULL, /* nodeGetInfo */ NULL, /* nodeGetInfo */

View File

@ -1468,6 +1468,7 @@ static virDriver openvzDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
openvzGetType, /* type */ openvzGetType, /* type */
openvzGetVersion, /* version */ openvzGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
NULL, /* getHostname */ NULL, /* getHostname */
openvzGetMaxVCPUs, /* getMaxVcpus */ openvzGetMaxVCPUs, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */ nodeGetInfo, /* nodeGetInfo */

View File

@ -1584,6 +1584,7 @@ virDriver phypDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
NULL, /* type */ NULL, /* type */
NULL, /* version */ NULL, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
NULL, /* getHostname */ NULL, /* getHostname */
NULL, /* getMaxVcpus */ NULL, /* getMaxVcpus */
NULL, /* nodeGetInfo */ NULL, /* nodeGetInfo */

View File

@ -7485,6 +7485,7 @@ static virDriver qemuDriver = {
qemudSupportsFeature, /* supports_feature */ qemudSupportsFeature, /* supports_feature */
qemudGetType, /* type */ qemudGetType, /* type */
qemudGetVersion, /* version */ qemudGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
qemudGetMaxVCPUs, /* getMaxVcpus */ qemudGetMaxVCPUs, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */ nodeGetInfo, /* nodeGetInfo */

View File

@ -1550,6 +1550,30 @@ done:
return rv; 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 * static char *
remoteGetHostname (virConnectPtr conn) remoteGetHostname (virConnectPtr conn)
{ {
@ -8740,6 +8764,7 @@ static virDriver remote_driver = {
remoteSupportsFeature, /* supports_feature */ remoteSupportsFeature, /* supports_feature */
remoteType, /* type */ remoteType, /* type */
remoteGetVersion, /* version */ remoteGetVersion, /* version */
remoteGetLibVersion, /* libvirtVersion */
remoteGetHostname, /* getHostname */ remoteGetHostname, /* getHostname */
remoteGetMaxVcpus, /* getMaxVcpus */ remoteGetMaxVcpus, /* getMaxVcpus */
remoteNodeGetInfo, /* nodeGetInfo */ remoteNodeGetInfo, /* nodeGetInfo */

View File

@ -308,6 +308,15 @@ xdr_remote_get_version_ret (XDR *xdrs, remote_get_version_ret *objp)
return TRUE; 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 bool_t
xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp) xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp)
{ {

View File

@ -179,6 +179,11 @@ struct remote_get_version_ret {
}; };
typedef struct remote_get_version_ret 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 { struct remote_get_hostname_ret {
remote_nonnull_string hostname; remote_nonnull_string hostname;
}; };
@ -1771,6 +1776,7 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154, REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154,
REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155, 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,
}; };
typedef enum remote_procedure remote_procedure; 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_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_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_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_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_uri_ret (XDR *, remote_get_uri_ret*);
extern bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*); 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_supports_feature_ret ();
extern bool_t xdr_remote_get_type_ret (); extern bool_t xdr_remote_get_type_ret ();
extern bool_t xdr_remote_get_version_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_hostname_ret ();
extern bool_t xdr_remote_get_uri_ret (); extern bool_t xdr_remote_get_uri_ret ();
extern bool_t xdr_remote_get_max_vcpus_args (); extern bool_t xdr_remote_get_max_vcpus_args ();

View File

@ -302,6 +302,10 @@ struct remote_get_version_ret {
hyper hv_ver; hyper hv_ver;
}; };
struct remote_get_lib_version_ret {
hyper lib_ver;
};
struct remote_get_hostname_ret { struct remote_get_hostname_ret {
remote_nonnull_string hostname; remote_nonnull_string hostname;
}; };
@ -1606,8 +1610,8 @@ enum remote_procedure {
REMOTE_PROC_NETWORK_IS_PERSISTENT = 153, REMOTE_PROC_NETWORK_IS_PERSISTENT = 153,
REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154, REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154,
REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155, 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 ? * Notice how the entries are grouped in sets of 10 ?

View File

@ -5167,6 +5167,7 @@ static virDriver testDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
NULL, /* type */ NULL, /* type */
testGetVersion, /* version */ testGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
testGetMaxVCPUs, /* getMaxVcpus */ testGetMaxVCPUs, /* getMaxVcpus */
testNodeGetInfo, /* nodeGetInfo */ testNodeGetInfo, /* nodeGetInfo */

View File

@ -1822,6 +1822,7 @@ static virDriver umlDriver = {
NULL, /* supports_feature */ NULL, /* supports_feature */
umlGetType, /* type */ umlGetType, /* type */
umlGetVersion, /* version */ umlGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
NULL, /* getMaxVcpus */ NULL, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */ nodeGetInfo, /* nodeGetInfo */

View File

@ -6500,6 +6500,7 @@ virDriver NAME(Driver) = {
NULL, /* supports_feature */ NULL, /* supports_feature */
NULL, /* type */ NULL, /* type */
vboxGetVersion, /* version */ vboxGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
vboxGetMaxVcpus, /* getMaxVcpus */ vboxGetMaxVcpus, /* getMaxVcpus */
nodeGetInfo, /* nodeGetInfo */ nodeGetInfo, /* nodeGetInfo */

View File

@ -1794,6 +1794,7 @@ static virDriver xenUnifiedDriver = {
xenUnifiedSupportsFeature, /* supports_feature */ xenUnifiedSupportsFeature, /* supports_feature */
xenUnifiedType, /* type */ xenUnifiedType, /* type */
xenUnifiedGetVersion, /* version */ xenUnifiedGetVersion, /* version */
NULL, /* libvirtVersion (impl. in libvirt.c) */
virGetHostname, /* getHostname */ virGetHostname, /* getHostname */
xenUnifiedGetMaxVcpus, /* getMaxVcpus */ xenUnifiedGetMaxVcpus, /* getMaxVcpus */
xenUnifiedNodeGetInfo, /* nodeGetInfo */ xenUnifiedNodeGetInfo, /* nodeGetInfo */