Bug 748742

Summary: Expose 'virNodeGetMemoryStats' and 'virNodeGetCPUStats' APIs in python binding
Product: Red Hat Enterprise Linux 6 Reporter: Alex Jia <ajia>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact:
Priority: high    
Version: 6.2CC: acathrow, dallan, dyuan, gsun, mzhan, rwu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-0.9.9-1.el6 Doc Type: Bug Fix
Doc Text:
No Documentation needed
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 06:36:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Alex Jia 2011-10-25 08:47:52 UTC
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.

Comment 2 Peter Krempa 2011-12-05 11:52:52 UTC
Requested functions were exported with upstream commits:
commit 17c7795561f408814a6925966d5ef57aaf17f7f2
Author: Peter Krempa <pkrempa>
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>
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}

Comment 4 Wayne Sun 2012-01-10 10:05:08 UTC
# 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.

Comment 5 Wayne Sun 2012-01-10 10:20:21 UTC
(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

Comment 6 Peter Krempa 2012-05-02 09:51:37 UTC
    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

Comment 8 errata-xmlrpc 2012-06-20 06:36:02 UTC
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