Red Hat Bugzilla – Bug 748742
Expose 'virNodeGetMemoryStats' and 'virNodeGetCPUStats' APIs in python binding
Last modified: 2012-06-20 02:36:02 EDT
Description of problem: Virsh nodecpustats and nodememstats are find, need to expose 'virNodeGetMemoryStats' and 'virNodeGetCPUStats' APIs in python binding. Version-Release number of selected component (if applicable): libvirt-python-0.9.4-19.el6.x86_64 How reproducible: always Steps to Reproduce: # python Python 2.6.6 (r266:84292, Apr 11 2011, 15:50:32) [GCC 4.4.4 20100726 (Red Hat 4.4.4-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import libvirt >>> con = libvirt.open(None) >>> con.getCPUStats(-1, None, 0, 0) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 2173, in getCPUStats ret = libvirtmod.virNodeGetCPUStats(self._o, cpuNum, params, nparams, flags) AttributeError: 'module' object has no attribute 'virNodeGetCPUStats' >>> con.getMemoryStats(-1, None, 0, 0) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 2245, in getMemoryStats ret = libvirtmod.virNodeGetMemoryStats(self._o, cellNum, params, nparams, flags) AttributeError: 'module' object has no attribute 'virNodeGetMemoryStats' Actual results: 'module' object has no attribute 'virNodeGetCPUStats' and'virNodeGetMemoryStats'. Expected results: expose them in python binding. Additional info: # nm -a -D /usr/lib64/python2.6/site-packages/libvirtmod.so |grep virNodeGetCPUStats # nm -a -D /usr/lib64/python2.6/site-packages/libvirtmod.so |grep virNodeGetMemoryStats Notes, nothing return.
Requested functions were exported with upstream commits: commit 17c7795561f408814a6925966d5ef57aaf17f7f2 Author: Peter Krempa <pkrempa@redhat.com> Date: Mon Nov 28 18:19:28 2011 +0100 python: Expose binding for virNodeGetMemoryStats() This patch adds binding for virNodeGetMemoryStats method of libvirtd. Return value is represented as a python dictionary mapping field names to values. commit 49556023f28d7960c3a27b4a30270dcac08c5e52 Author: Peter Krempa <pkrempa@redhat.com> Date: Mon Nov 28 18:19:27 2011 +0100 python: Expose binding for virNodeGetCPUStats() This patch adds binding for virNodeGetCPUStats method of libvirtd. Return value is represented as a python dictionary mapping field names to values. Tested with code: import libvirt conn = libvirt.open('qemu:///system') mem = conn.getMemoryStats(libvirt.VIR_NODE_MEMORY_STATS_ALL_CELLS, 0) cpu = conn.getCPUStats(libvirt.VIR_NODE_CPU_STATS_ALL_CPUS, 0) print mem print cpu Result: {'cached': 809104L, 'total': 2027708L, 'buffers': 70756L, 'free': 553156L} {'kernel': 191770000000L, 'idle': 3176360000000L, 'user': 711340000000L, 'iowait': 92490000000L}
# python Python 2.6.6 (r266:84292, Sep 12 2011, 14:03:14) [GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import libvirt >>> conn = libvirt.open(None) >>> conn.getCPUStats(libvirt.VIR_NODE_CPU_STATS_ALL_CPUS, 0) {'kernel': 1155780000000L, 'idle': 161385760000000L, 'user': 1524500000000L, 'iowait': 319040000000L} >>> conn.getMemoryStats(libvirt.VIR_NODE_MEMORY_STATS_ALL_CELLS, 0) {'cached': 493128L, 'total': 3856644L, 'buffers': 140576L, 'free': 3000864L} >>> so, this is fixed.
(In reply to comment #4) > # python > Python 2.6.6 (r266:84292, Sep 12 2011, 14:03:14) > [GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import libvirt > >>> conn = libvirt.open(None) > >>> conn.getCPUStats(libvirt.VIR_NODE_CPU_STATS_ALL_CPUS, 0) > {'kernel': 1155780000000L, 'idle': 161385760000000L, 'user': 1524500000000L, > 'iowait': 319040000000L} > >>> conn.getMemoryStats(libvirt.VIR_NODE_MEMORY_STATS_ALL_CELLS, 0) > {'cached': 493128L, 'total': 3856644L, 'buffers': 140576L, 'free': 3000864L} > >>> > > > so, this is fixed. # rpm -q libvirt libvirt-python libvirt-0.9.9-1.el6.x86_64 libvirt-python-0.9.9-1.el6.x86_64
Technical note added. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. New Contents: No Documentation needed
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHSA-2012-0748.html