Re: [Users] Small help regarding rhevm-shell scripting

Hi Anand, On 09/05/2013 12:07 PM, Anand Nande wrote:
Hi Michael,
The plan is to have a automated backup solution which will daily backup the Vms and stop-export-stop them automatically in RHEVM-3.2's rhevm-shell.
Having said that I am not sure : *How to use conditional statements like if-else/for/while loops* *inside the** **script file* *which is passed with the '-f' or '--file' option to 'rhevm-shell' ?*
Processing shell output is just like any text processing, basically what you need is a simple bash script, that analyses the input produced by something like [1] and invokes another script based on your condition/s something like [2]: [1] list vms --show-all | grep -w 'name\|status' > list_vms ovirt-shell -f list_vms [2] s1="..." s2="..." if [$s1 == $s2] then # invoke relevant script passing relevant parameters fi * in future versions (maybe even at 3.4) i plan adding additional cli capabilities to the shell, like invoking single command and printing the output to stdio what will make possible writing a single bash script that invokes different shell commands, but till then you can achieve the same via dedicated scripts like list_vms/suspend_vms/export_vms (in my view its even better from the code maintenance PoV)
If there is a way to do this, please let me know. I would like to use this to check if : - The VM is already present in the Export-Domain (?) +If yes, remove the VM present in the export-domain and re-initiate the export op on the new VM. +else, Export the VM. - After the above is complete, Check if the Export op is complete: +If yes, Start the VM which is stopped. +else, wait for Export to complete and once done, start the VM.
Having the above in a script, I can have the cron job scheduled to execute the script. Waiting for your feedback.
Thanks $Anand
-- Michael Pasternak RedHat, ENG-Virtualization R&D
participants (1)
-
Michael Pasternak