For example: >>> dom.memoryStats() libvir: QEMU Driver error : Requested operation is not valid:\ domain is not running There are six such python API functions like so. The root reason is that generator.py script checks the type of return value of a python stub function defined in libvirt-api.xml or libvirt-override-api.xml to see whether adding the raise clause or not in python wrapper code in libvirt.py. The type of return value is supposed to be C types. For those stub functions which return python non-integer data type like string, list, tuple, dictionary, the existing type in functions varies from each other which leads problem like this. Currently, in generator.py, it maintains a buggy whitelist for stub functions returning a list type. I think it is easy to forget adding new function name in the whitelist. This patch makes the value of type consistent with C type "char *" in libvirt-override-api.xml. For python, any of types could be printed as string, so I choose "char *"in this case. And the comment in xml could explain it when adding new function definition. <function name='virNodeGetCPUStats' file='python'> ... - <return type='virNodeCPUStats' info='...'/> + <return type='char *' info='...'/> ... </function> --- python/generator.py | 10 ++-- python/libvirt-override-api.xml | 116 +++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/python/generator.py b/python/generator.py index 8236bd2..bebc644 100755 --- a/python/generator.py +++ b/python/generator.py @@ -1008,11 +1008,9 @@ functions_list_exception_test = { } functions_list_default_test = "%s is None" -def is_list_type (name): - whitelist = [ "virDomainBlockStats", - "virDomainInterfaceStats" ] +def is_python_noninteger_type (name): - return name[-1:] == "*" or name in whitelist + return name[-1:] == "*" def nameFixup(name, classe, type, file): # avoid a desastrous clash @@ -1386,7 +1384,7 @@ def buildWrappers(module): ("ret", name)) classes.write(" return ret\n") - elif is_list_type (ret[0]): + elif is_python_noninteger_type (ret[0]): if not functions_noexcept.has_key (name): if functions_list_exception_test.has_key (name): test = functions_list_exception_test[name] @@ -1656,7 +1654,7 @@ def buildWrappers(module): classes.write (" return ret\n") - elif is_list_type (ret[0]): + elif is_python_noninteger_type (ret[0]): if not functions_noexcept.has_key (name): if functions_list_exception_test.has_key (name): test = functions_list_exception_test[name] diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml index 5976fb2..6087f86 100644 --- a/python/libvirt-override-api.xml +++ b/python/libvirt-override-api.xml @@ -1,5 +1,13 @@ <?xml version="1.0"?> <api name='libvir-python'> + <!-- This file lists libvirt API functions whose Python stubs are written by hand + in libvirt-override.c, but the Python-level code are still automatically generated + by generator.py script. + + The type of return value is supposed to be C types. If a function's stub will return + a python non-integer data type like string, list, tuple, dictionary, etc, + please using "char *" as the type of its return value. + --> <symbols> <function name="virConnectGetVersion" file='python'> <info>Returns the running hypervisor version of the connection host</info> @@ -14,34 +22,34 @@ <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'/> - <return type='int *' info="the list of ID or None in case of error"/> + <return type='char *' info="the list of ID or None in case of error"/> </function> <function name='virConnectListDefinedDomains' file='python'> <info>list the defined domains, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virConnectListAllDomains' file='python'> <info>returns list of all defined domains</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='domain *' info='the list of domains or None in case of error'/> + <return type='char *' info='the list of domains or None in case of error'/> </function> <function name='virConnectListNetworks' file='python'> <info>list the networks, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virConnectListDefinedNetworks' file='python'> <info>list the defined networks, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virConnectListAllNetworks' file='python'> <info>returns list of all networks</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='network *' info='the list of networks or None in case of error'/> + <return type='char *' info='the list of networks or None in case of error'/> </function> <function name='virDomainLookupByUUID' file='python'> <info>Try to lookup a domain on the given hypervisor based on its UUID.</info> @@ -57,54 +65,54 @@ </function> <function name='virDomainGetInfo' file='python'> <info>Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> </function> <function name='virDomainGetState' file='python'> <info>Extract domain state.</info> - <return type='int *' info='the list containing state and reason or None in case of error'/> + <return type='char *' info='the list containing state and reason or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='flags' type='unsigned int' info='additional flags'/> </function> <function name='virDomainGetControlInfo' file='python'> <info>Extract details about current state of control interface to a domain.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='flags' type='unsigned int' info='additional flags'/> </function> <function name='virDomainGetBlockInfo' file='python'> <info>Extract information about a domain block device size</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='path' type='const char *' info='path to the block device or file'/> <arg name='flags' type='unsigned int' info='currently unused'/> </function> <function name='virDomainGetJobInfo' file='python'> <info>Extract information about an active job being processed for a domain.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> </function> <function name='virDomainGetJobStats' file='python'> <info>Extract information about an active job being processed for a domain.</info> - <return type='virDomainJobStats' info='dictionary mapping field names to values or None in case of error'/> + <return type='char *' info='dictionary mapping field names to values or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='flags' type='unsigned int' info='flags, currently unused, pass 0.'/> </function> <function name='virNodeGetInfo' file='python'> <info>Extract hardware information about the Node.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> </function> <function name='virNodeGetCPUStats' file='python'> <info>Extract node's CPU statistics.</info> - <return type='virNodeCPUStats' info='dictionary mapping field names to values or None in case of error'/> + <return type='char *' info='dictionary mapping field names to values or None in case of error'/> <arg name='conn' type='virConnectPtr' info='pointer to hypervisor connection'/> <arg name='cpuNum' type='int' info='number of node cpu. (VIR_NODE_CPU_STATS_ALL_CPUS means total cpu statistics)'/> <arg name='flags' type='unsigned int' info='additional flags'/> </function> <function name='virNodeGetMemoryStats' file='python'> <info>Extract node's memory statistics.</info> - <return type='virNodeMemoryStats' info='dictionary mapping field names to values or None in case of error'/> + <return type='char *' info='dictionary mapping field names to values or None in case of error'/> <arg name='conn' type='virConnectPtr' info='pointer to hypervisor connection'/> <arg name='cellNum' type='int' info='number of node cell. (VIR_NODE_MEMORY_STATS_ALL_CELLS means total cell statistics)'/> <arg name='flags' type='unsigned int' info='additional flags'/> @@ -156,13 +164,13 @@ </function> <function name='virDomainBlockStats' file='python'> <info>Extracts block device statistics for a domain</info> - <return type='virDomainBlockStats' info='a tuple of statistics'/> + <return type='char *' info='a tuple of statistics'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='path' type='char *' info='the path for the block device'/> </function> <function name='virDomainBlockStatsFlags' file='python'> <info>Extracts block device statistics parameters of a running domain</info> - <return type='str *' info='None in case of error, returns a dictionary of params'/> + <return type='char *' info='None in case of error, returns a dictionary of params'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='path' type='char *' info='the path for the block device'/> <arg name='flags' type='int' info='flags (unused; pass 0)'/> @@ -175,20 +183,20 @@ [{cpu_time:xxx}, {cpu_time:xxx}, ...] If it is True or 1, it returns total domain CPU statistics in the format of [{cpu_time:xxx, user_time:xxx, system_time:xxx}]</info> - <return type='str *' info='returns a list of dictionary in case of success, None in case of error'/> + <return type='char *' info='returns a list of dictionary in case of success, None in case of error'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='total' type='bool' info='on true, return total domain CPU statistics, false return per-cpu info'/> <arg name='flags' type='int' info='flags (unused; pass 0)'/> </function> <function name='virDomainInterfaceStats' file='python'> <info>Extracts interface device statistics for a domain</info> - <return type='virDomainInterfaceStats' info='a tuple of statistics'/> + <return type='char *' info='a tuple of statistics'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='path' type='char *' info='the path for the interface device'/> </function> <function name='virDomainMemoryStats' file='python'> <info>Extracts memory statistics for a domain</info> - <return type='virDomainMemoryStats' info='a dictionary of statistics'/> + <return type='char *' info='a dictionary of statistics'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> </function> <function name="virNodeGetCellsFreeMemory" file='python'> @@ -196,16 +204,16 @@ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='startCell' type='int' info='first cell in the list'/> <arg name='maxCells' type='int' info='number of cell in the list'/> - <return type='int *' info="the list available memory in the cells"/> + <return type='char *' info="the list available memory in the cells"/> </function> <function name='virDomainGetSchedulerParameters' file='python'> <info>Get the scheduler parameters, the @params array will be filled with the values.</info> - <return type='str *' info='None in case of error, returns a dictionary of params.'/> + <return type='char *' info='None in case of error, returns a dictionary of params.'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> </function> <function name='virDomainGetSchedulerParametersFlags' file='python'> <info>Get the scheduler parameters</info> - <return type='str *' info='None in case of error, returns a dictionary of params'/> + <return type='char *' info='None in case of error, returns a dictionary of params'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> @@ -236,7 +244,7 @@ </function> <function name='virDomainGetVcpuPinInfo' file='python'> <info>Query the CPU affinity setting of all virtual CPUs of domain</info> - <return type='unsigned char *' info='the array of cpumap'/> + <return type='char *' info='the array of cpumap'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object, or NULL for Domain0'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> @@ -262,7 +270,7 @@ </function> <function name='virDomainGetBlkioParameters' file='python'> <info>Get the blkio parameters</info> - <return type='str *' info='None in case of error, returns a dictionary of params'/> + <return type='char *' info='None in case of error, returns a dictionary of params'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> @@ -275,7 +283,7 @@ </function> <function name='virDomainGetMemoryParameters' file='python'> <info>Get the memory parameters</info> - <return type='str *' info='None in case of error, returns a dictionary of params'/> + <return type='char *' info='None in case of error, returns a dictionary of params'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> @@ -288,7 +296,7 @@ </function> <function name='virDomainGetNumaParameters' file='python'> <info>Get the NUMA parameters</info> - <return type='str *' info='returns a dictionary of params in case of success, None in case of error'/> + <return type='char *' info='returns a dictionary of params in case of success, None in case of error'/> <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> @@ -305,44 +313,44 @@ <arg name='dom' type='virDomainPtr' info='pointer to the domain'/> <arg name='device' type='const char *' info='interface name'/> <arg name='flags' type='unsigned int' info='an OR'ed set of virDomainModificationImpact'/> - <return type='str *' info='the bandwidth tunables value or None in case of error'/> + <return type='char *' info='the bandwidth tunables value or None in case of error'/> </function> <function name='virConnectListStoragePools' file='python'> <info>list the storage pools, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names of None in case of error'/> + <return type='char *' info='the list of Names of None in case of error'/> </function> <function name='virConnectListDefinedStoragePools' file='python'> <info>list the defined storage pool, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names of None in case of error'/> + <return type='char *' info='the list of Names of None in case of error'/> </function> <function name='virConnectListAllStoragePools' file='python'> <info>returns list of all storage pools</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='pool *' info='the list of pools or None in case of error'/> + <return type='char *' info='the list of pools or None in case of error'/> </function> <function name='virStoragePoolListVolumes' file='python'> <info>list the storage volumes, stores the pointers to the names in @names</info> <arg name='pool' type='virStoragePoolPtr' info='pointer to the storage pool'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virStoragePoolListAllVolumes' file='python'> <info>return list of storage volume objects</info> <arg name='pool' type='virStoragePoolPtr' info='pointer to the storage pool'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='volume *' info='the list of volumes or None in case of error'/> + <return type='char *' info='the list of volumes or None in case of error'/> </function> <function name='virStoragePoolGetInfo' file='python'> <info>Extract information about a storage pool. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='pool' type='virStoragePoolPtr' info='a storage pool object'/> </function> <function name='virStorageVolGetInfo' file='python'> <info>Extract information about a storage volume. Note that if the connection used to get the domain is limited only a partial set of the information can be extracted.</info> - <return type='int *' info='the list of information or None in case of error'/> + <return type='char *' info='the list of information or None in case of error'/> <arg name='vol' type='virStorageVolPtr' info='a storage vol object'/> </function> <function name='virNodeListDevices' file='python'> @@ -350,18 +358,18 @@ <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'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virConnectListAllNodeDevices' file='python'> <info>returns list of all host node devices</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='device *' info='the list of host node device or None in case of error'/> + <return type='char *' info='the list of host node device 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'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virSecretGetValue' file='libvirt' module='libvirt'> <info>Fetches the value associated with a secret.</info> @@ -372,13 +380,13 @@ <function name='virConnectListSecrets' file='libvirt' module='libvirt'> <info>List the defined secret IDs</info> <arg name='conn' type='virConnectPtr' info='virConnect connection'/> - <return type='str *' info='the list of secret IDs or None in case of error'/> + <return type='char *' info='the list of secret IDs or None in case of error'/> </function> <function name='virConnectListAllSecrets' file='python'> <info>returns list of all interfaces</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='secret *' info='the list of secrets or None in case of error'/> + <return type='char *' info='the list of secrets or None in case of error'/> </function> <function name='virSecretSetValue' file='libvirt' module='libvirt'> <info>Associates a value with a secret.</info> @@ -406,13 +414,13 @@ <function name='virConnectListNWFilters' file='libvirt' module='libvirt'> <info>List the defined network filters</info> <arg name='conn' type='virConnectPtr' info='virConnect connection'/> - <return type='str *' info='the list of network filter IDs or None in case of error'/> + <return type='char *' info='the list of network filter IDs or None in case of error'/> </function> <function name='virConnectListAllNWFilters' file='python'> <info>returns list of all network fitlers</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='nwfilter *' info='the list of network filters or None in case of error'/> + <return type='char *' info='the list of network filters or None in case of error'/> </function> <function name='virNWFilterLookupByUUID' file='python'> <info>Try to lookup a network filter on the given hypervisor based on its UUID.</info> @@ -433,18 +441,18 @@ <function name='virConnectListInterfaces' file='python'> <info>list the running interfaces, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names of None in case of error'/> + <return type='char *' info='the list of Names of None in case of error'/> </function> <function name='virConnectListDefinedInterfaces' file='python'> <info>list the defined interfaces, stores the pointers to the names in @names</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> - <return type='str *' info='the list of Names of None in case of error'/> + <return type='char *' info='the list of Names of None in case of error'/> </function> <function name='virConnectListAllInterfaces' file='python'> <info>returns list of all interfaces</info> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='unsigned int' info='optional flags'/> - <return type='interface *' info='the list of interfaces or None in case of error'/> + <return type='char *' info='the list of interfaces or None in case of error'/> </function> <function name='virConnectBaselineCPU' file='python'> <info>Computes the most feature-rich CPU which is compatible with all given host CPUs.</info> @@ -457,25 +465,25 @@ <info>collect the list of snapshot names for the given domain</info> <arg name='dom' type='virDomainPtr' info='pointer to the domain'/> <arg name='flags' type='unsigned int' info='flags'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virDomainListAllSnapshots' file='python'> <info>returns the list of snapshots for the given domain</info> <arg name='dom' type='virDomainPtr' info='pointer to the domain'/> <arg name='flags' type='unsigned int' info='flags'/> - <return type='snapshot *' info='the list of snapshots or None in case of error'/> + <return type='char *' info='the list of snapshots or None in case of error'/> </function> <function name='virDomainSnapshotListChildrenNames' file='python'> <info>collect the list of child snapshot names for the given snapshot</info> <arg name='snapshot' type='virDomainSnapshotPtr' info='pointer to the snapshot'/> <arg name='flags' type='unsigned int' info='flags'/> - <return type='str *' info='the list of Names or None in case of error'/> + <return type='char *' info='the list of Names or None in case of error'/> </function> <function name='virDomainSnapshotListAllChildren' file='python'> <info>returns the list of child snapshots for the given snapshot</info> <arg name='snapshot' type='virDomainSnapshotPtr' info='pointer to the snapshot'/> <arg name='flags' type='unsigned int' info='flags'/> - <return type='snapshot *' info='the list of snapshots or None in case of error'/> + <return type='char *' info='the list of snapshots or None in case of error'/> </function> <function name='virDomainRevertToSnapshot' file='python'> <info>revert the domain to the given snapshot</info> @@ -489,7 +497,7 @@ <arg name='dom' type='virDomainPtr' info='pointer to the domain'/> <arg name='path' type='const char *' info='Fully-qualified filename of disk'/> <arg name='flags' type='unsigned int' info='fine-tuning flags, currently unused, pass 0.'/> - <return type='virDomainBlockJobInfo' info='A dictionary containing job information.' /> + <return type='char *' info='A dictionary containing job information.' /> </function> <function name='virDomainMigrateGetCompressionCache' file='python'> <info>Get current size of the cache (in bytes) used for compressing @@ -517,7 +525,7 @@ <arg name='dom' type='virDomainPtr' info='pointer to the domain'/> <arg name='disk' type='const char *' info='disk name'/> <arg name='flags' type='unsigned int' info='an OR'ed set of virDomainModificationImpact'/> - <return type='str *' info='the I/O tunables value or None in case of error'/> + <return type='char *' info='the I/O tunables value or None in case of error'/> </function> <function name='virDomainBlockPeek' file='python'> <info>Read the contents of domain's disk device</info> @@ -538,7 +546,7 @@ </function> <function name='virDomainGetDiskErrors' file='python'> <info>Extract errors on disk devices.</info> - <return type='virDomainDiskErrorPtr' info='dictionary of disks and their errors or None in case of error'/> + <return type='char *' info='dictionary of disks and their errors or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='flags' type='unsigned int' info='unused, always pass 0'/> </function> @@ -551,13 +559,13 @@ </function> <function name='virNodeGetMemoryParameters' file='python'> <info>Get the node memory parameters</info> - <return type='str *' info='None in case of error, returns a dictionary of params'/> + <return type='char *' info='None in case of error, returns a dictionary of params'/> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='int' info='unused, always pass 0'/> </function> <function name='virNodeGetCPUMap' file='python'> <info>Get node CPU information</info> - <return type='str *' info='(cpunum, cpumap, online) on success, None on error'/> + <return type='char *' info='(cpunum, cpumap, online) on success, None on error'/> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='int' info='unused, pass 0'/> </function> -- 1.7.11.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list