[libvirt] [PATCHv3] virNodeGetCPUMap: Add python binding

Eric Blake eblake at redhat.com
Thu Oct 25 17:34:18 UTC 2012


On 10/25/2012 08:59 AM, Viktor Mihajlovski wrote:
> Added a method getCPUMap to virConnect.
> It can be used as follows:
> 
> import libvirt
> import sys
> import os
> 
> conn = libvirt.openReadOnly(None)
> if conn == None:
>     print 'Failed to open connection to the hypervisor'
>     sys.exit(1)
> 
> try:
>     (cpus, cpumap, online) = conn.getCPUMap(0)

> +    <function name='virNodeGetCPUMap' file='python'>
> +      <info>Get node CPU information</info>
> +      <return type='str *' info='(cpunum, online, cpumap) on success, None on error'/>

Oops, docs disagree with commit message on tuple ordering.

> +    /* 0: number of CPUs */
> +    if ((pycpunum = PyLong_FromLong(i_retval)) == NULL ||
> +        PyTuple_SetItem(ret, 0, pycpunum) < 0)
> +        goto error;
> +
> +    /* 1: CPU map */

But code matched the commit message, so I'll fix the docs.


> +    /* 2: number of online CPUs */
> +    if((pyonline = PyLong_FromLong(online)) == NULL ||

Style - space after 'if'.

> +       PyTuple_SetItem(ret, 2, pyonline) < 0)
> +        goto error;

Indentation (but that's caused by the earlier spacing after 'if').

> +

ACK and pushed with this squashed in:

diff --git i/python/libvirt-override-api.xml
w/python/libvirt-override-api.xml
index e54701c..a0e0496 100644
--- i/python/libvirt-override-api.xml
+++ w/python/libvirt-override-api.xml
@@ -544,7 +544,7 @@
     </function>
     <function name='virNodeGetCPUMap' file='python'>
       <info>Get node CPU information</info>
-      <return type='str *' info='(cpunum, online, cpumap) on success,
None on error'/>
+      <return type='str *' 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>
diff --git i/python/libvirt-override.c w/python/libvirt-override.c
index 0609803..320f26a 100644
--- i/python/libvirt-override.c
+++ w/python/libvirt-override.c
@@ -6449,8 +6449,8 @@ libvirt_virNodeGetCPUMap(PyObject *self
ATTRIBUTE_UNUSED,
         goto error;

     /* 2: number of online CPUs */
-    if((pyonline = PyLong_FromLong(online)) == NULL ||
-       PyTuple_SetItem(ret, 2, pyonline) < 0)
+    if ((pyonline = PyLong_FromLong(online)) == NULL ||
+        PyTuple_SetItem(ret, 2, pyonline) < 0)
         goto error;

 cleanup:


-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121025/8e850e01/attachment-0001.sig>


More information about the libvir-list mailing list