[Users] Rest-api to fetch the hosts details ( active vm's , CPU , Physical memory etc.)

Michael Pasternak mpastern at redhat.com
Wed Jan 30 08:20:09 EST 2013


On 01/30/2013 03:09 PM, Romil Gupta wrote:
> thanks for all your guidance , now I m able to fetch the details of a host using 
> the below script :
>  
> hosts=api.hosts.list()
> for host in hosts:
>     print "host name--> %s  id--->> %s \n"%(host.name <http://host.name> , host.id <http://host.id>)
>     clusterid=api.hosts.get(host.name <http://host.name>).cluster.id <http://cluster.id>
>     print clusterid
> 
>     hostname=api.hosts.get(host.name <http://host.name>)
>     statistic=hostname.statistics.list()
>     i=0
>     while i < 14:
>         print statistic[i].name
>         print statistic[i].description
>         print statistic[i].unit
>         print statistic[i].values.value[0].datum
>         i=i+1;
> 
> 
> summary=api.get_summary()
> print summary
>  
> How I can print the summary , its only return the Object?? 

this is summary object structure:

    <summary>
        <vms>
            <total></total>
            <active></active>
        </vms>
        <hosts>
            <total></total>
            <active></active>
        </hosts>
        <users>
            <total></total>
            <active></active>
        </users>
        <storage_domains>
            <total></total>
            <active></active>
        </storage_domains>
    </summary>

you can access properties directly, like this:
summary.hosts.active

> 
> Thanks,
> Romil 
> 
> 
> On Wed, Jan 30, 2013 at 4:52 PM, Michael Pasternak <mpastern at redhat.com <mailto:mpastern at redhat.com>> wrote:
> 
> 
>     Romil,
> 
>     On 01/30/2013 12:18 PM, Romil Gupta wrote:
>     > Hi,
>     >
>     > Is this is a right way to get it ??
>     >
>     >     statistics=params.Host(host.name <http://host.name> <http://host.name>).get_statistic()
> 
>     1. first you need to fetch the host to see it's statistics (by doing params.Host(...) you creating
>        host parameters holder which is needed for adding new host to the system)
> 
>     2. get_x() getters used to access object attributes, while collections are exposed as properties, do
> 
>     1. myhost = api.hosts.get(name="xxx")
>     2. myhost.statistics.list()
>     3. loop over returned collection of statistics to find what you're looking for
> 
>     - note, statistic objects are complex types, you can look for data at:
> 
>     statistics[i].unit // the unit of the holder data
>     statistics[i].values.value[0].datum // actual data
> 
>     >     print statistics
>     >
>     >      summary=params.Host(host.name <http://host.name> <http://host.name>).get_summary()
> 
>     summary() is an api method, do:
> 
>     1. api = API(url='', username='', password='')
>     2. api.get_summary()
> 
> 
>     >      print summary
>     >
>     >
>     > Output is : none
>     >
>     > Thanks
>     > Romil
>     >
>     >
>     > On Wed, Jan 30, 2013 at 2:04 PM, Michael Pasternak <mpastern at redhat.com <mailto:mpastern at redhat.com> <mailto:mpastern at redhat.com <mailto:mpastern at redhat.com>>> wrote:
>     >
>     >
>     >     Hi Romil,
>     >
>     >     On 01/30/2013 10:17 AM, Romil Gupta wrote:
>     >     > Hi all ,
>     >     >
>     >     > how I can get the hosts details like Active VM's ,
>     >
>     >     host doesn't have running vms attribute, instead you
>     >     can see in the guest on which host it's running,
>     >
>     >     general system summary you can see at api.get_summary()
>     >
>     >     Number of CPU's , CPU name , CPU type ,
>     >
>     >     these are host attributes
>     >
>     >     Physical Memory (used , free ) , swap size and other parameters
>     >
>     >     these are host.statistics attributes
>     >
>     >     > using ovirt-engine-sdk-3.2.0.5-1.
>     >     >
>     >     >
>     >     >
>     >     > Regards,
>     >     > Romil
>     >     >
>     >     > --
>     >     > I don't wish to be everything to everyone, but I would like to be something to someone.
>     >
>     >
>     >     --
>     >
>     >     Michael Pasternak
>     >     RedHat, ENG-Virtualization R&D
>     >
>     >
>     >
>     >
>     > --
>     > I don't wish to be everything to everyone, but I would like to be something to someone.
> 
> 
>     --
> 
>     Michael Pasternak
>     RedHat, ENG-Virtualization R&D
> 
> 
> 
> 
> -- 
> I don't wish to be everything to everyone, but I would like to be something to someone.


-- 

Michael Pasternak
RedHat, ENG-Virtualization R&D


More information about the Users mailing list