mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
Python binding for node device APIs (David Lively)
This commit is contained in:
parent
1ee5367c19
commit
83928c2074
@ -1,3 +1,9 @@
|
|||||||
|
Fri Nov 21 12:40:14 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
Python binding for node device APIs (David Lively)
|
||||||
|
* python/generator.py, python/libvir.c, python/libvirt-python-api.xml,
|
||||||
|
python/libvirt_wrap.h, python/types.c: Bindings for node device APis
|
||||||
|
|
||||||
Fri Nov 21 12:38:14 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
Fri Nov 21 12:38:14 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
Node device support in virsh (David Lively)
|
Node device support in virsh (David Lively)
|
||||||
|
@ -260,6 +260,11 @@ py_types = {
|
|||||||
'const virConnectPtr': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
'const virConnectPtr': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
||||||
'virConnect *': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
'virConnect *': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
||||||
'const virConnect *': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
'const virConnect *': ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
|
||||||
|
|
||||||
|
'virNodeDevicePtr': ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
|
||||||
|
'const virNodeDevicePtr': ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
|
||||||
|
'virNodeDevice *': ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
|
||||||
|
'const virNodeDevice *': ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
|
||||||
}
|
}
|
||||||
|
|
||||||
py_return_types = {
|
py_return_types = {
|
||||||
@ -318,6 +323,8 @@ skip_impl = (
|
|||||||
'virDomainBlockPeek',
|
'virDomainBlockPeek',
|
||||||
'virDomainMemoryPeek',
|
'virDomainMemoryPeek',
|
||||||
'virEventRegisterImpl',
|
'virEventRegisterImpl',
|
||||||
|
'virNodeListDevices',
|
||||||
|
'virNodeDeviceListCaps',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -601,6 +608,8 @@ classes_type = {
|
|||||||
"virStoragePool *": ("._o", "virStoragePool(self, _obj=%s)", "virStoragePool"),
|
"virStoragePool *": ("._o", "virStoragePool(self, _obj=%s)", "virStoragePool"),
|
||||||
"virStorageVolPtr": ("._o", "virStorageVol(self, _obj=%s)", "virStorageVol"),
|
"virStorageVolPtr": ("._o", "virStorageVol(self, _obj=%s)", "virStorageVol"),
|
||||||
"virStorageVol *": ("._o", "virStorageVol(self, _obj=%s)", "virStorageVol"),
|
"virStorageVol *": ("._o", "virStorageVol(self, _obj=%s)", "virStorageVol"),
|
||||||
|
"virNodeDevicePtr": ("._o", "virNodeDevice(self, _obj=%s)", "virNodeDevice"),
|
||||||
|
"virNodeDevice *": ("._o", "virNodeDevice(self, _obj=%s)", "virNodeDevice"),
|
||||||
"virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"),
|
"virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"),
|
||||||
"virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"),
|
"virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"),
|
||||||
}
|
}
|
||||||
@ -608,7 +617,8 @@ classes_type = {
|
|||||||
converter_type = {
|
converter_type = {
|
||||||
}
|
}
|
||||||
|
|
||||||
primary_classes = ["virDomain", "virNetwork", "virStoragePool", "virStorageVol", "virConnect"]
|
primary_classes = ["virDomain", "virNetwork", "virStoragePool", "virStorageVol",
|
||||||
|
"virConnect", "virNodeDevice" ]
|
||||||
|
|
||||||
classes_ancestor = {
|
classes_ancestor = {
|
||||||
}
|
}
|
||||||
@ -617,6 +627,7 @@ classes_destructors = {
|
|||||||
"virNetwork": "virNetworkFree",
|
"virNetwork": "virNetworkFree",
|
||||||
"virStoragePool": "virStoragePoolFree",
|
"virStoragePool": "virStoragePoolFree",
|
||||||
"virStorageVol": "virStorageVolFree",
|
"virStorageVol": "virStorageVolFree",
|
||||||
|
"virNodeDevice" : "virNodeDeviceFree"
|
||||||
}
|
}
|
||||||
|
|
||||||
functions_noexcept = {
|
functions_noexcept = {
|
||||||
@ -626,6 +637,8 @@ functions_noexcept = {
|
|||||||
'virStoragePoolGetName': True,
|
'virStoragePoolGetName': True,
|
||||||
'virStorageVolGetName': True,
|
'virStorageVolGetName': True,
|
||||||
'virStorageVolGetkey': True,
|
'virStorageVolGetkey': True,
|
||||||
|
'virNodeDeviceGetName': True,
|
||||||
|
'virNodeDeviceGetParent': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
reference_keepers = {
|
reference_keepers = {
|
||||||
@ -706,6 +719,13 @@ def nameFixup(name, classe, type, file):
|
|||||||
elif name[0:13] == "virStorageVol":
|
elif name[0:13] == "virStorageVol":
|
||||||
func = name[13:]
|
func = name[13:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = string.lower(func[0:1]) + func[1:]
|
||||||
|
elif name[0:13] == "virNodeDevice":
|
||||||
|
if name[13:16] == "Get":
|
||||||
|
func = string.lower(name[16]) + name[17:]
|
||||||
|
elif name[13:19] == "Lookup" or name[13:] == "Create":
|
||||||
|
func = string.lower(name[3]) + name[4:]
|
||||||
|
else:
|
||||||
|
func = string.lower(name[13]) + name[14:]
|
||||||
elif name[0:7] == "virNode":
|
elif name[0:7] == "virNode":
|
||||||
func = name[7:]
|
func = name[7:]
|
||||||
func = string.lower(func[0:1]) + func[1:]
|
func = string.lower(func[0:1]) + func[1:]
|
||||||
@ -958,7 +978,7 @@ def buildWrappers():
|
|||||||
else:
|
else:
|
||||||
txt.write("Class %s()\n" % (classname))
|
txt.write("Class %s()\n" % (classname))
|
||||||
classes.write("class %s:\n" % (classname))
|
classes.write("class %s:\n" % (classname))
|
||||||
if classname in [ "virDomain", "virNetwork", "virStoragePool", "virStorageVol" ]:
|
if classname in [ "virDomain", "virNetwork", "virStoragePool", "virStorageVol", "virNodeDevice" ]:
|
||||||
classes.write(" def __init__(self, conn, _obj=None):\n")
|
classes.write(" def __init__(self, conn, _obj=None):\n")
|
||||||
else:
|
else:
|
||||||
classes.write(" def __init__(self, _obj=None):\n")
|
classes.write(" def __init__(self, _obj=None):\n")
|
||||||
@ -966,7 +986,7 @@ def buildWrappers():
|
|||||||
list = reference_keepers[classname]
|
list = reference_keepers[classname]
|
||||||
for ref in list:
|
for ref in list:
|
||||||
classes.write(" self.%s = None\n" % ref[1])
|
classes.write(" self.%s = None\n" % ref[1])
|
||||||
if classname in [ "virDomain", "virNetwork" ]:
|
if classname in [ "virDomain", "virNetwork", "virNodeDevice" ]:
|
||||||
classes.write(" self._conn = conn\n")
|
classes.write(" self._conn = conn\n")
|
||||||
elif classname in [ "virStorageVol", "virStoragePool" ]:
|
elif classname in [ "virStorageVol", "virStoragePool" ]:
|
||||||
classes.write(" self._conn = conn\n" + \
|
classes.write(" self._conn = conn\n" + \
|
||||||
|
@ -1466,6 +1466,90 @@ libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *ar
|
|||||||
return(py_retval);
|
return(py_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
|
PyObject *args) {
|
||||||
|
PyObject *py_retval;
|
||||||
|
char **names = NULL;
|
||||||
|
int c_retval, i;
|
||||||
|
virConnectPtr conn;
|
||||||
|
PyObject *pyobj_conn;
|
||||||
|
char *cap;
|
||||||
|
unsigned int flags;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, (char *)"Ozi:virNodeListDevices",
|
||||||
|
&pyobj_conn, &cap, &flags))
|
||||||
|
return(NULL);
|
||||||
|
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
|
||||||
|
|
||||||
|
c_retval = virNodeNumOfDevices(conn, cap, flags);
|
||||||
|
if (c_retval < 0)
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
|
||||||
|
if (c_retval) {
|
||||||
|
names = malloc(sizeof(*names) * c_retval);
|
||||||
|
if (!names)
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
c_retval = virNodeListDevices(conn, cap, names, c_retval, flags);
|
||||||
|
if (c_retval < 0) {
|
||||||
|
free(names);
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
py_retval = PyList_New(c_retval);
|
||||||
|
|
||||||
|
if (names) {
|
||||||
|
for (i = 0;i < c_retval;i++) {
|
||||||
|
PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
|
||||||
|
free(names[i]);
|
||||||
|
}
|
||||||
|
free(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(py_retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
|
PyObject *args) {
|
||||||
|
PyObject *py_retval;
|
||||||
|
char **names = NULL;
|
||||||
|
int c_retval, i;
|
||||||
|
virNodeDevicePtr dev;
|
||||||
|
PyObject *pyobj_dev;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, (char *)"O:virNodeDeviceListCaps", &pyobj_dev))
|
||||||
|
return(NULL);
|
||||||
|
dev = (virNodeDevicePtr) PyvirNodeDevice_Get(pyobj_dev);
|
||||||
|
|
||||||
|
c_retval = virNodeDeviceNumOfCaps(dev);
|
||||||
|
if (c_retval < 0)
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
|
||||||
|
if (c_retval) {
|
||||||
|
names = malloc(sizeof(*names) * c_retval);
|
||||||
|
if (!names)
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
c_retval = virNodeDeviceListCaps(dev, names, c_retval);
|
||||||
|
if (c_retval < 0) {
|
||||||
|
free(names);
|
||||||
|
return VIR_PY_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
py_retval = PyList_New(c_retval);
|
||||||
|
|
||||||
|
if (names) {
|
||||||
|
for (i = 0;i < c_retval;i++) {
|
||||||
|
PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
|
||||||
|
free(names[i]);
|
||||||
|
}
|
||||||
|
free(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(py_retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
* Helper functions to avoid importing modules
|
* Helper functions to avoid importing modules
|
||||||
* for every callback
|
* for every callback
|
||||||
@ -2044,6 +2128,8 @@ static PyMethodDef libvirtMethods[] = {
|
|||||||
{(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
|
{(char *) "virEventRegisterImpl", libvirt_virEventRegisterImpl, METH_VARARGS, NULL},
|
||||||
{(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
|
{(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
|
||||||
{(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
|
{(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
|
||||||
|
{(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL},
|
||||||
|
{(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,5 +160,17 @@
|
|||||||
<return type='int *' info='the list of information or None in case of error'/>
|
<return type='int *' info='the list of information or None in case of error'/>
|
||||||
<arg name='vol' type='virStorageVolPtr' info='a storage vol object'/>
|
<arg name='vol' type='virStorageVolPtr' info='a storage vol object'/>
|
||||||
</function>
|
</function>
|
||||||
|
<function name='virNodeListDevices' file='python'>
|
||||||
|
<info>list the node devices</info>
|
||||||
|
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
|
||||||
|
<arg name='cap' type='const unsigned char *' info='capability name'/>
|
||||||
|
<arg name='flags' type='unsigned int' info='flags (unused; pass 0)'/>
|
||||||
|
<return type='str *' info='the list of Names or None in case of error'/>
|
||||||
|
</function>
|
||||||
|
<function name='virNodeDeviceListCaps' file='python'>
|
||||||
|
<info>list the node device's capabilities</info>
|
||||||
|
<arg name='dev' type='virNodeDevicePtr' info='pointer to the node device'/>
|
||||||
|
<return type='str *' info='the list of Names or None in case of error'/>
|
||||||
|
</function>
|
||||||
</symbols>
|
</symbols>
|
||||||
</api>
|
</api>
|
||||||
|
@ -65,6 +65,16 @@ typedef struct {
|
|||||||
virStorageVolPtr obj;
|
virStorageVolPtr obj;
|
||||||
} PyvirStorageVol_Object;
|
} PyvirStorageVol_Object;
|
||||||
|
|
||||||
|
|
||||||
|
#define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
|
(((PyvirNodeDevice_Object *)(v))->obj))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
virNodeDevicePtr obj;
|
||||||
|
} PyvirNodeDevice_Object;
|
||||||
|
|
||||||
|
|
||||||
#define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
|
#define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
(((PyvirEventHandleCallback_Object *)(v))->obj))
|
(((PyvirEventHandleCallback_Object *)(v))->obj))
|
||||||
|
|
||||||
@ -89,6 +99,7 @@ typedef struct {
|
|||||||
void* obj;
|
void* obj;
|
||||||
} PyvirVoidPtr_Object;
|
} PyvirVoidPtr_Object;
|
||||||
|
|
||||||
|
|
||||||
PyObject * libvirt_intWrap(int val);
|
PyObject * libvirt_intWrap(int val);
|
||||||
PyObject * libvirt_longWrap(long val);
|
PyObject * libvirt_longWrap(long val);
|
||||||
PyObject * libvirt_ulongWrap(unsigned long val);
|
PyObject * libvirt_ulongWrap(unsigned long val);
|
||||||
@ -105,6 +116,8 @@ PyObject * libvirt_virEventHandleCallbackWrap(virEventHandleCallback node);
|
|||||||
PyObject * libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node);
|
PyObject * libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node);
|
||||||
PyObject * libvirt_virFreeCallbackWrap(virFreeCallback node);
|
PyObject * libvirt_virFreeCallbackWrap(virFreeCallback node);
|
||||||
PyObject * libvirt_virVoidPtrWrap(void* node);
|
PyObject * libvirt_virVoidPtrWrap(void* node);
|
||||||
|
PyObject * libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node);
|
||||||
|
|
||||||
|
|
||||||
/* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
|
/* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
|
||||||
* LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
|
* LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
|
||||||
|
@ -163,6 +163,21 @@ libvirt_virConnectPtrWrap(virConnectPtr node)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
|
||||||
|
{
|
||||||
|
PyObject *ret;
|
||||||
|
|
||||||
|
if (node == NULL) {
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return (Py_None);
|
||||||
|
}
|
||||||
|
ret =
|
||||||
|
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr",
|
||||||
|
NULL);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
|
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user