[Users] Fwd: API Query on --> api.vms.list

Michael Pasternak mpastern at redhat.com
Wed Jun 6 15:08:52 UTC 2012


Hi Anil,

> -------- Original Message --------
> Subject:     [Users] API Query on --> api.vms.list
> Date:     Wed, 6 Jun 2012 18:32:51 +0530
> From:     Anil Vettathu <anilv.in at gmail.com>
> To:     users at ovirt.org
> 
> 
> 
> Hi
> 
> I am writing a small python script to get the name of all the VMs that
> matches a string.
> 
> ==========
> import sys
> import getopt
> import optparse
> import os
> import time
> from ovirtsdk.api import API
> from ovirtsdk.xml import params
> 
> URL='https://192.168.1.1:8443/api' #RHEVM API ACCESS URL
> USERNAME='admin at internal'
> PASSWORD='ovirt'
> 
> 
> api=API(url=URL, username=USERNAME, password=PASSWORD)
> 
> vmnames = api.vms.list(query = 'name=a')

in this example you have used equals, i.e ovirt engine was guided to find
vm with name 'a', to find vms where name starting with 'a', use "name=a*" query,
to find all vms contains "a" in their names, use "name=*a*" query, for more examples
please see SearchText section of [1].

[1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Virtualization_for_Servers/2.2/html/API_Guide/sect-API_Guide-Using_Functions_and_Scripts-RHEVM-Search_Engine.html

> print vmnames
> ==========
> 
> Print output is,
> 
> <ovirtsdk.infrastructure.brokers.VM object at 0x1d4e790>
> 
> I was expecting a list of VMs which contains "a" in their names.
> 
> Am I doing it correct? Can someone guide me with a small example?
> My reference is
> http://www.ovirt.org/wiki/SDK#Querying_collection_with_oVirt_search_engine_query_.26_custom_constraint
> 
> Thanks,
> Anil


-- 

Michael Pasternak
RedHat, ENG-Virtualization R&D



More information about the Users mailing list