[Engine-devel] ovirt engine sdk

Michael Pasternak mpastern at redhat.com
Wed Jan 23 12:45:24 UTC 2013


Hi Navin,

On 01/23/2013 01:54 PM, navin p wrote:
> Hi,
>     I've written the following python program after configuring ovirt.
> 
> 
> from ovirtsdk.xml import params
> from ovirtsdk.api import API
> 
> 
> 
> api=API(url='http://XYZ:80',username='ABC',password='123')
> 
> print "\n**********************VMS************************\n"
> 
> vmlist = api.vms.list()
> hostlist = api.hosts.list()
> evenlist = api.events.list();
> 
> 
> for vm in vmlist:
>     print vm.name <http://vm.name>,vm.memory,vm.id <http://vm.id>,vm.os.kernel,vm.cluster.id <http://vm.cluster.id>,vm.start_time
>   
> print "\n**********************HOSTS ********************\n"
> 
> for host in hostlist:
>     print host.name <http://host.name>
> 
> #print "\n**********************EVENTS ********************\n"
> 
> #for evt in evenlist:
>  #   print evt.description
> 
> It prints the output as 
> 
> *********************VMS************************
> 
> fedora18 2147483648 3e4634b7-82a9-4c4f-8599-0f9092a9258e None 99408929-82cf-4dc7-a532-9d998063fa95 None
> testdtop1 536870912 c256a1d9-2e3f-42e8-9020-6d08d21d2d73 None 99408929-82cf-4dc7-a532-9d998063fa95 2013-01-23T09:59:36.726Z
> testvm1 268435456 f6b2a97d-34b2-4a62-adae-ac0504b96558 None 99408929-82cf-4dc7-a532-9d998063fa95 2013-01-23T09:55:06.727Z
> testvmfedora18 536870912 25c14ee6-65dd-4785-af0c-a8df3f87573f None 99408929-82cf-4dc7-a532-9d998063fa95 None
> 
> **********************HOSTS ********************
> 
> omwin.ind.hp.com <http://omwin.ind.hp.com>
> 
> Now i want to get the statistics for each vm like the memory used and memory installed etc in python. How do i go about getting them ? 

vm object has statistics sub-collection, you can access it by: vm.statistics.list(),

> Do we have something like a header
> file in C or C++ where i can see the member variables and then get the statistics ?

in python, you can see object's attributes by accessing __dict__/__getattr__/dir(object)/etc.,
vm.__dict__ will do the job for you, however i'd suggest you using some IDE (i'm using Eclipse + PyDev plugin),
this way you'll be able accessing object attributes simply by Ctrl+SPACE auto-completion.

> 
> 
> Regards,
> Navin
> 
> 
> 
> _______________________________________________
> Engine-devel mailing list
> Engine-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/engine-devel


-- 

Michael Pasternak
RedHat, ENG-Virtualization R&D



More information about the Engine-devel mailing list