Getting error while trying to add VmPool using ovirtsdk4 version of the python api

Hello there, I am trying to add a VmPool to oVirt using the python ovirtSDK4 with following lines: I am omitting the import packages lines and connection lines. system_service = connection.system_service() vm_pools_service = system_service.vm_pools_service() templates_service = system_service.templates_service() clusters_service = system_service.clusters_service() tplist = templates_service.list(search='name=prueba') tpl=None biggest=-1 for t in tplist: ver = t.version if ver.version_number > biggest: biggest = ver.version_number tid = t.id tpl = t c = None for cluster in clusters_service.list(): if cluster.name == 'Pruebacluster': c = cluster pool = ovirtsdk4.types.VmPool(name='PRUEBA',size=1,type =ovirtsdk4.types.VmPoolType('manual'),template=tpl,cluster=c) vm_pools_service.add(pool=pool) I am getting the following error: Fault reason is "Request syntactically incorrect.". Fault detail is "For correct usage, see: https://ovirt.example.com/ovirt-engine/api/v4/model#services/vm-pools/method...". HTTP response code is 400. I am a newbie in using this version of the API, suppose this is quite easy problem. Thanks for all the answers to come, Manuel

On 02/10/2017 01:43 PM, Manuel Luis Aznar wrote:
Hello there,
I am trying to add a VmPool to oVirt using the python ovirtSDK4 with following lines:
I am omitting the import packages lines and connection lines.
system_service = connection.system_service()
vm_pools_service = system_service.vm_pools_service()
templates_service = system_service.templates_service()
clusters_service = system_service.clusters_service()
tplist = templates_service.list(search='name=prueba')
tpl=None biggest=-1 fort intplist: ver = t.version ifver.version_number > biggest: biggest = ver.version_number tid = t.id <http://t.id> tpl = t
c = None forcluster inclusters_service.list(): ifcluster.name <http://cluster.name> == 'Pruebacluster': c = cluster
pool = ovirtsdk4.types.VmPool(name='PRUEBA',size=1,type=ovirtsdk4.types.VmPoolType('manual'),template=tpl,cluster=c) vm_pools_service.add(pool=pool)
I am getting the following error:
Fault reason is "Request syntactically incorrect.". Fault detail is "For correct usage, see: https://ovirt.example.com/ovirt-engine/api/v4/model#services/vm-pools/method...". HTTP response code is 400.
I am a newbie in using this version of the API, suppose this is quite easy problem.
Thanks for all the answers to come, Manuel
This look like this bug, fixed in version 4.1 of the SDK: Importing a VM using the SDK fails https://bugzilla.redhat.com/1408839 However there is a good practice that I recommend you to apply, which will probably avoid the issue. That good practice is avoid sending to the server the complete objects that you got from other requests. For example, in this case you are sending to the server the complethe 'tpl' and 'c' clusters that you got from other requests. Instead of that, try to send only what is required: pool = ovirttsdk4.types.VmPool( name='PRUEBA', size=1, type=ovirtsdk4.types.VmPoolType.MANUAL, template=ovirtsdk4.types.Template(id=tpl.id), cluster=ovirtsdk4.types.Cluster(id=c.id) ) vm_pools_servcie.add(pool=pool) The key point here is creating new 'Template' and 'Cluster' objects that only contain the 'id', as that is all what the server needs. If you send the complete template and cluster you are wasting resources, and exposing yourself to bugs like the mentioned above. Please try that and let us know if it solves your issue.
participants (2)
-
Juan Hernández
-
Manuel Luis Aznar