<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 11, 2018 at 1:47 PM, Giorgio Biacchi <span dir="ltr"><<a href="mailto:giorgio@di.unimi.it" target="_blank">giorgio@di.unimi.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 01/11/2018 11:44 AM, Kapetanakis Giannis wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 10/01/18 22:11, Wesley Stewart wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Marcelo,<br>
<br>
I would greatly appreciate seeing a script! It would be an excellent chance for me to learn a bit about using ovirt from the command line as well!<br>
</blockquote>
<br>
I'm using something like this with ovirt-shell<br>
<br>
vm_shutdown:<br>
#!/bin/sh<br>
LOG=/root/ovirt/vm_shutdown_lo<wbr>g<br>
echo `date` >> $LOG<br>
/usr/bin/ovirt-shell -f /root/ovirt/vm_shutdown_script >> $LOG<br>
echo "" >> $LOG<br>
<br>
vm_shutdown_script:<br>
list vms --kwargs status-state=up|grep name | sed s/'name :'/'action vm'/ | sed -e 's/$/ shutdown/' > /root/ovirt/new_vm_shutdown_sc<wbr>ript<br>
file /root/ovirt/new_vm_shutdown_sc<wbr>ript<br>
<br>
new_vm_shutdown_script now lists entries like this:<br>
action vm vm1 shutdown<br>
action vm vm2 shutdown<br>
etc.<br>
<br>
G<br>
<br>
<br>
______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/users</a><br>
<br>
</blockquote>
<br></div></div>
You can use python SDK.<br>
<br>
Somthing like this should work<br>
<br>
#!/usr/bin/env python<br>
<br>
import ovirtsdk4 as sdk<br>
<br>
ovaddress = "<fill correct URL here>"<br>
username="admin@internal"<br>
password="*********"<br>
<br>
connection = sdk.Connection(<br>
url=ovaddress,<br>
username=username,<br>
password=password,<br>
ca_file='ca.crt',<br>
insecure=True<br>
)<br>
<br>
system_service = connection.system_service()<br>
vms_service = system_service.vms_service()<br>
vms = vms_service.list()<br></blockquote><div><br></div><div>I think it's better to do it for all VMs that are in 'Up' state?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
for vm in vms:<br>
vm_service = vms_service.vm_service(<a href="http://vm.id" rel="noreferrer" target="_blank">vm.id</a>)<br>
vm_service.shutdown()<br></blockquote><div><br></div><div> And here I suggest adding a check (after some time?) that all VMs are actually down, and if not, exit with an error?</div><div>Y.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
connection.close()<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
gb<br>
<br>
PGP Key: <a href="http://pgp.mit.edu/" rel="noreferrer" target="_blank">http://pgp.mit.edu/</a><br>
Primary key fingerprint: C510 0765 943E EBED A4F2 69D3 16CC DC90 B9CB 0F34</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@ovirt.org" target="_blank">Users@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/users</a><br>
</div></div></blockquote></div><br></div></div>