HI, I am using ubuntu host machine and KVM is present as guest in that machine.Two virtual machines are there.I am using Python binding to query on the hypervisor and extract the VM related information. Here is my simple code: #!/*usr*/local/bin/*python * import libvirt import sys conn = libvirt.openReadOnly(None) if conn == None: print *'Failed to open connection to the hypervisor' * sys.exit(1) try: domIds = conn.listDomainsID() for id in domIds: dom0 = conn.lookupByID(id) dom0.info() print *"Domain 0: id %d running %s"* % (dom0.ID(), dom0.OSType()) print dom0.info() except: print *'Failed to find the main domain' * sys.exit() The output is : Domain 0: id 2 running hvm [1, 131072L, 131072L, 1, 14921710000000L] Domain 0: id 3 running hvm [1, 131072L, 131072L, 1, 30880000000L] Here I am not able to understand these values are represent what type of information, which value is representing what resource of host machine.Could you please help me to understand how I could find out CPU,VM ,memory related information seperately through python binding?. I didn't find Python binding Reference in the Libvirt site.Could you help me by providing the Reference link for Python binding? Thanks in Advance!! Arpita -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20110209/4240a6ee/attachment.htm>
Igor Serebryany
2011-Feb-09 12:23 UTC
[libvirt-users] How to use Python Binding with Lbivirt.
Arpita, I have used the python bindings extensively, but AFAIK there is no documentation specifically for python. The python bindings closely follow the C API, which is documented here: http://libvirt.org/html/libvirt-libvirt.html The function names in python will closely mirror the names listed in that document. For instance, when you are calling 'dom0.info()' you are really calling 'virDomainGetInfo' -- you leave out the domain pointer because you are calling the function on a domain object, and you leave out the info pointer because in python you can just get that back as a return value. The list you're getting from 'info()' is just this structure here: http://libvirt.org/html/libvirt-libvirt.html#virDomainInfo If you get stuck, I recommend getting a connection or domain object inside a python interpreter and calling dir() or help() on that object. This can reveal other things to play with. >>> import libvirt >>> c = libvirt.open(None) >>> dir(c) >>> d = c.lookupByID(0) >>> help(d) --igor On Wed, Feb 09, 2011 at 04:48:07PM +0530, arpita k wrote:> HI, > > I am using ubuntu host machine and KVM is present as guest in that > machine.Two virtual machines are there.I am using Python binding to query on > the hypervisor and extract the VM related information. > > Here is my simple code: > > > #!/*usr*/local/bin/*python > * > > import libvirt > > import sys > > conn = libvirt.openReadOnly(None) > > if conn == None: > > print *'Failed to open connection to the hypervisor' > * > > sys.exit(1) > > try: > > domIds = conn.listDomainsID() > > for id in domIds: > > dom0 = conn.lookupByID(id) > > dom0.info() > > print *"Domain 0: id %d running %s"* % (dom0.ID(), dom0.OSType()) > > print dom0.info() > > except: > > print *'Failed to find the main domain' > * > > sys.exit() > The output is : > > Domain 0: id 2 running hvm > [1, 131072L, 131072L, 1, 14921710000000L] > Domain 0: id 3 running hvm > [1, 131072L, 131072L, 1, 30880000000L] > > Here I am not able to understand these values are represent what type of > information, which value is representing what resource of host machine.Could > you please help me to understand how I could find out CPU,VM ,memory related > information seperately through python binding?. > I didn't find Python binding Reference in the Libvirt site.Could you help me > by providing the Reference link for Python binding? > > Thanks in Advance!! > > Arpita> _______________________________________________ > libvirt-users mailing list > libvirt-users at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-users-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20110209/ae5fedf5/attachment.sig>
Apparently Analagous Threads
- Libvirt in Windows not working
- How to retrieve Memory stat of the KVM using python binding with Libvirt API
- Not able to capture detailed CPU information of the guest machine using Libvirt API.
- How to use Python Binding with Lbivirt.
- problem with openjdk version