API OVA export - getting job id/job status

hi, I tryed this with API 4.2 and 4.3. purpose of the following script is, to export a given list of vm as OVA one after another. To reach that i need to monitor the job status and pause the script till the actual export is done. The script works fine, but not the restriction of the returned jobs to the one spcificaly job i need to monitor. Therefor the script pauses on *any* running job. the working script: #!/usr/bin/python import logging import time import ovirtsdk4 as sdk import ovirtsdk4.types as types connection = sdk.Connection( url='https://ovirtman12/ovirt-engine/api', username='admin@internal', password='***', ca_file='/etc/pki/ovirt-engine/ca-ovirtman12.pem', ) hosts_service = connection.system_service().hosts_service() hosts = hosts_service.list()[0] vms_service = connection.system_service().vms_service() vms = vms_service.list(search='name=blxlic954') for vm in vms: # print("%s (%s)" % (vm.name, vm.id)) vm_service = vms_service.vm_service(vm.id) start_time = (time.strftime('%Y%m%d_%H%M%S', time.localtime(int(time.time())))) vm_service.export_to_path_on_host( host=types.Host(id=hosts.id), directory='/nfs_c3/export', filename=('%s_backup_%s.ova' % (vm.name, start_time)), wait=True, ) # time.sleep(5) jobs_service = connection.system_service().jobs_service() jobs = jobs_service.list(search='') for job in jobs: print(job.id, job.description) # job = jobs_service.job_service(job.id).get() while job.status == types.JobStatus.STARTED: time.sleep(10) job = jobs_service.job_service(job.id).get() print('job-status: %s' % (job.status)) connection.close() The line jobs = jobs_service.list(search='') works fine as long as the search pattern is empty. if i try to restrict the results returned like this: jobs = jobs_service.list(search='description=*blxlic954*') i get an error: bad sql grammar [select * from (select * from job where ( job id in (select distinct job.job id from job where ( ) )) order by start time asc) as t1 offset (1 -1) limit 2147483647]; nested exception is org.postgresql.util.psqlexception: error: syntax error at or near ")" looks like the 'where' clause is not filled correctly. Am i wrong with my syntax or ist that a bug? Is there another way to get the correct job id/status?

Hi Lars, you might find this email thread interesting: https://lists.ovirt.org/archives/list/users@ovirt.org/thread/PXYAQ7YEBQCUWCA... Jayme is trying to solve pretty much the same problem as you - although he's using the Ansible approach instead of SDK. Feel free to join that conversation. At this point it seems like he might have found a good solution, but he needs to test it. Jan On Fri, Jan 24, 2020 at 8:33 AM <lars.stolpe@bvg.de> wrote:
hi,
I tryed this with API 4.2 and 4.3. purpose of the following script is, to export a given list of vm as OVA one after another. To reach that i need to monitor the job status and pause the script till the actual export is done. The script works fine, but not the restriction of the returned jobs to the one spcificaly job i need to monitor. Therefor the script pauses on *any* running job. the working script:
#!/usr/bin/python
import logging import time
import ovirtsdk4 as sdk import ovirtsdk4.types as types
connection = sdk.Connection( url='https://ovirtman12/ovirt-engine/api', username='admin@internal', password='***', ca_file='/etc/pki/ovirt-engine/ca-ovirtman12.pem', )
hosts_service = connection.system_service().hosts_service() hosts = hosts_service.list()[0]
vms_service = connection.system_service().vms_service() vms = vms_service.list(search='name=blxlic954')
for vm in vms: # print("%s (%s)" % (vm.name, vm.id)) vm_service = vms_service.vm_service(vm.id) start_time = (time.strftime('%Y%m%d_%H%M%S', time.localtime(int(time.time())))) vm_service.export_to_path_on_host( host=types.Host(id=hosts.id), directory='/nfs_c3/export', filename=('%s_backup_%s.ova' % (vm.name, start_time)), wait=True, ) # time.sleep(5) jobs_service = connection.system_service().jobs_service() jobs = jobs_service.list(search='') for job in jobs: print(job.id, job.description) # job = jobs_service.job_service(job.id).get() while job.status == types.JobStatus.STARTED: time.sleep(10) job = jobs_service.job_service(job.id).get() print('job-status: %s' % (job.status))
connection.close()
The line jobs = jobs_service.list(search='') works fine as long as the search pattern is empty.
if i try to restrict the results returned like this: jobs = jobs_service.list(search='description=*blxlic954*') i get an error:
bad sql grammar [select * from (select * from job where ( job id in (select distinct job.job id from job where ( ) )) order by start time asc) as t1 offset (1 -1) limit 2147483647]; nested exception is org.postgresql.util.psqlexception: error: syntax error at or near ")"
looks like the 'where' clause is not filled correctly.
Am i wrong with my syntax or ist that a bug? Is there another way to get the correct job id/status? _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/ZVFUE32ORCMN7E...
-- Jan Zmeskal Quality Engineer, RHV Core System Red Hat <https://www.redhat.com> <https://www.redhat.com>

Indeed. A felt like there was need for a simple way to backup ovirt vms. Ansible may just be the answer. After some more testing of the playbook I plan to publish a blog post/guide on the subject so others can use it. On Fri, Jan 24, 2020 at 4:42 AM Jan Zmeskal <jzmeskal@redhat.com> wrote:
Hi Lars, you might find this email thread interesting: https://lists.ovirt.org/archives/list/users@ovirt.org/thread/PXYAQ7YEBQCUWCA...
Jayme is trying to solve pretty much the same problem as you - although he's using the Ansible approach instead of SDK. Feel free to join that conversation. At this point it seems like he might have found a good solution, but he needs to test it.
Jan
On Fri, Jan 24, 2020 at 8:33 AM <lars.stolpe@bvg.de> wrote:
hi,
I tryed this with API 4.2 and 4.3. purpose of the following script is, to export a given list of vm as OVA one after another. To reach that i need to monitor the job status and pause the script till the actual export is done. The script works fine, but not the restriction of the returned jobs to the one spcificaly job i need to monitor. Therefor the script pauses on *any* running job. the working script:
#!/usr/bin/python
import logging import time
import ovirtsdk4 as sdk import ovirtsdk4.types as types
connection = sdk.Connection( url='https://ovirtman12/ovirt-engine/api', username='admin@internal', password='***', ca_file='/etc/pki/ovirt-engine/ca-ovirtman12.pem', )
hosts_service = connection.system_service().hosts_service() hosts = hosts_service.list()[0]
vms_service = connection.system_service().vms_service() vms = vms_service.list(search='name=blxlic954')
for vm in vms: # print("%s (%s)" % (vm.name, vm.id)) vm_service = vms_service.vm_service(vm.id) start_time = (time.strftime('%Y%m%d_%H%M%S', time.localtime(int(time.time())))) vm_service.export_to_path_on_host( host=types.Host(id=hosts.id), directory='/nfs_c3/export', filename=('%s_backup_%s.ova' % (vm.name, start_time)), wait=True, ) # time.sleep(5) jobs_service = connection.system_service().jobs_service() jobs = jobs_service.list(search='') for job in jobs: print(job.id, job.description) # job = jobs_service.job_service(job.id).get() while job.status == types.JobStatus.STARTED: time.sleep(10) job = jobs_service.job_service(job.id).get() print('job-status: %s' % (job.status))
connection.close()
The line jobs = jobs_service.list(search='') works fine as long as the search pattern is empty.
if i try to restrict the results returned like this: jobs = jobs_service.list(search='description=*blxlic954*') i get an error:
bad sql grammar [select * from (select * from job where ( job id in (select distinct job.job id from job where ( ) )) order by start time asc) as t1 offset (1 -1) limit 2147483647]; nested exception is org.postgresql.util.psqlexception: error: syntax error at or near ")"
looks like the 'where' clause is not filled correctly.
Am i wrong with my syntax or ist that a bug? Is there another way to get the correct job id/status? _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/ZVFUE32ORCMN7E...
--
Jan Zmeskal
Quality Engineer, RHV Core System

How do you go with big virtual disk's? I run a file server with a 2TB virtual disk, but don't want a 2TB data log to back up every time I run it. Same goes with a heap of VMs with 100Gb disks, I don't really want to take up another 100gb of space every day I back up, that's why my current solution is vProtect as I can do weekly full and daily incrementals but always keen to see other implementations especially for large disks. On 24 January 2020 9:23:27 pm Jayme <jaymef@gmail.com> wrote:
Indeed. A felt like there was need for a simple way to backup ovirt vms. Ansible may just be the answer. After some more testing of the playbook I plan to publish a blog post/guide on the subject so others can use it.
On Fri, Jan 24, 2020 at 4:42 AM Jan Zmeskal <jzmeskal@redhat.com> wrote: Hi Lars, you might find this email thread interesting: https://lists.ovirt.org/archives/list/users@ovirt.org/thread/PXYAQ7YEBQCUWCA...
Jayme is trying to solve pretty much the same problem as you - although he's using the Ansible approach instead of SDK. Feel free to join that conversation. At this point it seems like he might have found a good solution, but he needs to test it.
Jan
On Fri, Jan 24, 2020 at 8:33 AM <lars.stolpe@bvg.de> wrote: hi,
I tryed this with API 4.2 and 4.3. purpose of the following script is, to export a given list of vm as OVA one after another. To reach that i need to monitor the job status and pause the script till the actual export is done. The script works fine, but not the restriction of the returned jobs to the one spcificaly job i need to monitor. Therefor the script pauses on *any* running job. the working script:
#!/usr/bin/python
import logging import time
import ovirtsdk4 as sdk import ovirtsdk4.types as types
connection = sdk.Connection( url='https://ovirtman12/ovirt-engine/api', username='admin@internal', password='***', ca_file='/etc/pki/ovirt-engine/ca-ovirtman12.pem', )
hosts_service = connection.system_service().hosts_service() hosts = hosts_service.list()[0]
vms_service = connection.system_service().vms_service() vms = vms_service.list(search='name=blxlic954')
for vm in vms: # print("%s (%s)" % (vm.name, vm.id)) vm_service = vms_service.vm_service(vm.id) start_time = (time.strftime('%Y%m%d_%H%M%S', time.localtime(int(time.time())))) vm_service.export_to_path_on_host( host=types.Host(id=hosts.id), directory='/nfs_c3/export', filename=('%s_backup_%s.ova' % (vm.name, start_time)), wait=True, ) # time.sleep(5) jobs_service = connection.system_service().jobs_service() jobs = jobs_service.list(search='') for job in jobs: print(job.id, job.description) # job = jobs_service.job_service(job.id).get() while job.status == types.JobStatus.STARTED: time.sleep(10) job = jobs_service.job_service(job.id).get() print('job-status: %s' % (job.status))
connection.close()
The line jobs = jobs_service.list(search='') works fine as long as the search pattern is empty.
if i try to restrict the results returned like this: jobs = jobs_service.list(search='description=*blxlic954*') i get an error:
bad sql grammar [select * from (select * from job where ( job id in (select distinct job.job id from job where ( ) )) order by start time asc) as t1 offset (1 -1) limit 2147483647]; nested exception is org.postgresql.util.psqlexception: error: syntax error at or near ")"
looks like the 'where' clause is not filled correctly.
Am i wrong with my syntax or ist that a bug? Is there another way to get the correct job id/status? _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/ZVFUE32ORCMN7E...
--
JanZmeskal Quality Engineer, RHV Core System Red Hat
_______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/YRKMLOYWOY24WV...

Hi Joseph, that "Image Level" backup as OVA file is a monthly backup as a basic for us, to have a complete virtual machine. There are also weekly full and daily incremental backups on filesystem level using a backup agent and remote backup. Our biggest V-disk is 300GB which is exported in 29 minutes (lucky one, since the 30 min timeout ist still a problem) Having bigger disks I would separate system and data disks so you maybe can export your VM including only the system disk, and backup the data disk as filesystem incremental. have a nice weekend, Lars

Hi Jan, i've seen this post too, but i've absolutely no idea of dealing with ansible, so i can't say much in this topic. The hope was, that i made a mistake in my script :) Lars

Ansible can be daunting simply because of how powerful it is, but it’s actually quite easy to run a simple playbook like the one I’m writing for backups, especially if ran from ovirt hosted engine as it already has ansible and all the needed dependencies installed. I’m working on throwing together a guide with more detailed info very soon and will post it to this group when done. On Fri, Jan 24, 2020 at 7:31 AM <lars.stolpe@bvg.de> wrote:
Hi Jan,
i've seen this post too, but i've absolutely no idea of dealing with ansible, so i can't say much in this topic. The hope was, that i made a mistake in my script :)
Lars _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/EOPA5GFDIAAHS5...
participants (4)
-
Jan Zmeskal
-
Jayme
-
Joseph Goldman
-
lars.stolpe@bvg.de