'''
Created on Oct 5, 2011

@author: mpastern
'''

from org.ovirt.sdk.python.api import API
from org.ovirt.sdk.python.xml import params

#create proxy
api = API(url='http://localhost:8080', username='mpastern@qa.lab.tlv.redhat.com', password='maiklp85')

#list
vms1 = api.vms.list()

#list by query
vms2 = api.vms.list(query = 'name=python_vm')

#search vms by property constraint
vms3 = api.vms.list(memory=1073741824)

#update resource
vm1 = api.vms.get(name = 'python_vm')

mem = vm1.memory
vm1.description = 'updated_desc'
vm2 = vm1.update()
vm3 = api.vms.get(name='python_vm')

#list by constraints
vms4 = api.vms.list(name = 'pythond_sdk_poc2')

#get by name
vm4 = api.vms.get(name = 'pythond_sdk_poc2')


#get by constraints
vm5 = api.vms.get(id = '02f0f4a4-9738-4731-83c4-293f3f734782')

if(vm4 is None):
    
    #add vm
    cluster = params.Cluster(name='Default_iscsi')
    template = params.Template(name='Template2_iscsi')    
    param = params.VM(name='pythond_sdk_poc2', cluster=cluster, template=template, memory=1073741824)
    vm6 = api.vms.add(param)
  
    #add nic to vm
    network = params.Network(name='rhevm')    
    nic = params.NIC(name='eth0', network=network, interface='e1000')     
    vm6.nics.add(nic)
        
    #list vm's nics
    nics1 = vm6.nics.list()
    
    #list vm's nics by constraints
    nics2 = vm6.nics.list(name='eth0')
    nics3 = vm6.nics.list(interface='e1000')
    
    #get sub resource
    nic1 = vm6.nics.get(name='eth0')
        
    #update sub-resource
    nic1.name = 'eth01'
    nic2 = nic1.update()
    nic3 = vm6.nics.get(name='eth01')
    nic4 = vm6.nics.get(name='eth0')

    #result = vm.start()
    
#delete the vm    
result = vm6.delete()
'''
Created on Oct 5, 2011

@author: mpastern
'''

from org.ovirt.sdk.python.api import API
from org.ovirt.sdk.python.xml import params

#create proxy
api = API(url='http://host:port', username='user@domain', password='password')

#list
vms1 = api.vms.list()

#list by query
vms2 = api.vms.list(query = 'name=python_vm')

#search vms by property constraint
vms3 = api.vms.list(memory=1073741824)

#update resource
vm1 = api.vms.get(name = 'python_vm')

mem = vm1.memory
vm1.description = 'updated_desc'
vm2 = vm1.update()
vm3 = api.vms.get(name='python_vm')

#list by constraints
vms4 = api.vms.list(name = 'pythond_sdk_poc2')

#get by name
vm4 = api.vms.get(name = 'pythond_sdk_poc2')


#get by constraints
vm5 = api.vms.get(id = '02f0f4a4-9738-4731-83c4-293f3f734782')

if(vm4 is None):
    
    #add vm
    cluster = params.Cluster(name='Default_iscsi')
    template = params.Template(name='Template2_iscsi')    
    param = params.VM(name='pythond_sdk_poc2', cluster=cluster, template=template, memory=1073741824)
    vm6 = api.vms.add(param)
  
    #add nic to vm
    network = params.Network(name='rhevm')    
    nic = params.NIC(name='eth0', network=network, interface='e1000')     
    vm6.nics.add(nic)
        
    #list vm's nics
    nics1 = vm6.nics.list()
    
    #list vm's nics by constraints
    nics2 = vm6.nics.list(name='eth0')
    nics3 = vm6.nics.list(interface='e1000')
    
    #get sub resource
    nic1 = vm6.nics.get(name='eth0')
        
    #update sub-resource
    nic1.name = 'eth01'
    nic2 = nic1.update()
    nic3 = vm6.nics.get(name='eth01')
    nic4 = vm6.nics.get(name='eth0')

    #result = vm.start()
    
#delete the vm    
result = vm6.delete()
Prepare the example