Re: [ovirt-users] Shutdown all VM's command line

2018-01-16 Thread Yaniv Kaul
On Thu, Jan 11, 2018 at 1:47 PM, Giorgio Biacchi 
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 = ""
> 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


Re: [ovirt-users] Shutdown all VM's command line

2018-01-16 Thread Giulio Casella

Il 16/01/2018 02:02, Wesley Stewart ha scritto:
I am using the default certificates.   Took me a second to find out 
where they are stored, but after pointing directly to it, everything is 
working like a champ.


If I remember correctly, if you use option "insecure=True", you can omit 
ca_file option:


connection = sdk.Connection(
  url=ovaddress,
  username=username,
  password=password,
  insecure=True
)


Cheers,
gc
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Shutdown all VM's command line

2018-01-15 Thread Wesley Stewart
Hey,  thanks for sending this to me.  Works like a charm.  I have this tied
in with a UPS script that monitors the UPS on another system, and fires off
your script before a shutdown command.  Works pretty well so far!

I am using the default certificates.   Took me a second to find out where
they are stored, but after pointing directly to it, everything is working
like a champ.

Thanks!


On Thu, Jan 11, 2018 at 6:47 AM, Giorgio Biacchi 
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 = ""
> 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()
>
> for vm in vms:
> vm_service = vms_service.vm_service(vm.id)
> vm_service.shutdown()
>
> 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


Re: [ovirt-users] Shutdown all VM's command line

2018-01-11 Thread Giorgio Biacchi

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_script
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 = ""
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()

for vm in vms:
vm_service = vms_service.vm_service(vm.id)
vm_service.shutdown()

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


Re: [ovirt-users] Shutdown all VM's command line

2018-01-11 Thread Kapetanakis Giannis
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_script
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


Re: [ovirt-users] Shutdown all VM's command line

2018-01-10 Thread Wesley Stewart
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!



On Tue, Jan 9, 2018 at 6:55 PM, Marcelo Leandro 
wrote:

> Do you can do this with python sdk, do you can build a list and shutdown
> all vms. If you want I can make a script to you tomorrow.
>
>
> Marcelo Leandro
>
> Em 09/01/2018 8:30 PM, "Wesley Stewart"  escreveu:
>
>> Is there an easy way to do this?
>>
>> I have a UPS connected to my freenas box, and using NUT and UPSC I can
>> monitor the battery level on my centos 7 host.
>>
>> In the case of an emergency, and my UPS goes below, lets say 40% battery,
>> I would like to make a script to shutdown all running VMs, and then reboot
>> the host.
>>
>> Otherwise I am afraid of sending a straight reboot command to the host
>> without taking care of the virtual machines first.
>>
>> Thanks!
>>
>> ___
>> 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


Re: [ovirt-users] Shutdown all VM's command line

2018-01-09 Thread Yaniv Kaul
On Jan 10, 2018 1:56 AM, "Marcelo Leandro"  wrote:

Do you can do this with python sdk, do you can build a list and shutdown
all vms. If you want I can make a script to you tomorrow.


Or with Ansible.
But in 4.2, I believe the VMs are registered with libvirt and will be shut
down nicely with the host.
Y.



Marcelo Leandro

Em 09/01/2018 8:30 PM, "Wesley Stewart"  escreveu:

> Is there an easy way to do this?
>
> I have a UPS connected to my freenas box, and using NUT and UPSC I can
> monitor the battery level on my centos 7 host.
>
> In the case of an emergency, and my UPS goes below, lets say 40% battery,
> I would like to make a script to shutdown all running VMs, and then reboot
> the host.
>
> Otherwise I am afraid of sending a straight reboot command to the host
> without taking care of the virtual machines first.
>
> Thanks!
>
> ___
> 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
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [ovirt-users] Shutdown all VM's command line

2018-01-09 Thread Marcelo Leandro
Do you can do this with python sdk, do you can build a list and shutdown
all vms. If you want I can make a script to you tomorrow.


Marcelo Leandro

Em 09/01/2018 8:30 PM, "Wesley Stewart"  escreveu:

> Is there an easy way to do this?
>
> I have a UPS connected to my freenas box, and using NUT and UPSC I can
> monitor the battery level on my centos 7 host.
>
> In the case of an emergency, and my UPS goes below, lets say 40% battery,
> I would like to make a script to shutdown all running VMs, and then reboot
> the host.
>
> Otherwise I am afraid of sending a straight reboot command to the host
> without taking care of the virtual machines first.
>
> Thanks!
>
> ___
> 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