On Thu, Jan 11, 2018 at 1:47 PM, Giorgio Biacchi <gior...@di.unimi.it> wrote:
> On 01/11/2018 11:44 AM, Kapetanakis Giannis wrote: > >> On 10/01/18 22:11, Wesley Stewart wrote: >> >>> Marcelo, >>> >>> 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! >>> >> >> I'm using something like this with ovirt-shell >> >> vm_shutdown: >> #!/bin/sh >> LOG=/root/ovirt/vm_shutdown_log >> echo `date` >> $LOG >> /usr/bin/ovirt-shell -f /root/ovirt/vm_shutdown_script >> $LOG >> echo "" >> $LOG >> >> vm_shutdown_script: >> list vms --kwargs status-state=up|grep name | sed s/'name >> :'/'action vm'/ | sed -e 's/$/ shutdown/' > /root/ovirt/new_vm_shutdown_sc >> ript >> file /root/ovirt/new_vm_shutdown_script >> >> new_vm_shutdown_script now lists entries like this: >> action vm vm1 shutdown >> action vm vm2 shutdown >> etc. >> >> G >> >> >> _______________________________________________ >> Users mailing list >> Users@ovirt.org >> http://lists.ovirt.org/mailman/listinfo/users >> >> > You can use python SDK. > > Somthing like this should work > > #!/usr/bin/env python > > import ovirtsdk4 as sdk > > ovaddress = "<fill correct URL here>" > username="admin@internal" > password="*********" > > connection = sdk.Connection( > url=ovaddress, > username=username, > password=password, > ca_file='ca.crt', > insecure=True > ) > > system_service = connection.system_service() > vms_service = system_service.vms_service() > vms = vms_service.list() > I think it's better to do it for all VMs that are in 'Up' state? > > for vm in vms: > vm_service = vms_service.vm_service(vm.id) > vm_service.shutdown() > And here I suggest adding a check (after some time?) that all VMs are actually down, and if not, exit with an error? Y. > connection.close() > > -- > gb > > PGP Key: http://pgp.mit.edu/ > Primary key fingerprint: C510 0765 943E EBED A4F2 69D3 16CC DC90 B9CB 0F34 > > _______________________________________________ > Users mailing list > Users@ovirt.org > http://lists.ovirt.org/mailman/listinfo/users >
_______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users