
Does anyone have a way of shutting down oVirt automatically in the case of a power outage? Ideally I would like a script that can be automatically run when the UPS reaches a certain level. I had a look at the python SDK but I could only find functions for shutting down VMs and not hosts. Also I suspect this wont let me shutdown the hosted engine VM. Any ideas? Regards

On 23-4-2018 20:13, Simon Vincent wrote:
Does anyone have a way of shutting down oVirt automatically in the case of a power outage?
Ideally I would like a script that can be automatically run when the UPS reaches a certain level. I had a look at the python SDK but I could only find functions for shutting down VMs and not hosts. Also I suspect this wont let me shutdown the hosted engine VM.
I have posted in the past a script which you might be able to use as a starting point. I've got a, most of the time, a single server setup using hosted-engine for development/testing work and shutdown my server when needed. Recently found out that using 'sanlock client shutdown -f 1 -w 1' will allow me to shutdown my server cleanly. I'll dig up the script when I'm booted into CentOS instead of Windows :-) Nudge me if I forget to post the script :-) Regards, Joop

I've plugged this into our monitoring. When the UPS' are at 50%, it puts the general cluster into global maintenance & then triggers a shutdown action on all of the VMs in the cluster's service group via the monitoring agent (you could use an SNMP trap if you use agentless monitoring). Once all of the VMs are down, it then continues with the hosts. At 20%, it does the same with our "core" cluster. This method means that the HE can be shutdown, and it works whether the HE is up or not. For emergencies when the monitoring is offline, I've also hacked up a bash script which parses the output of vdsClient & uses a loop to send a shutdown signal to all of the VMs on each host. Doug On Mon, 23 Apr 2018, 14:14 Simon Vincent, <sv@srvincent.co.uk> wrote:
Does anyone have a way of shutting down oVirt automatically in the case of a power outage?
Ideally I would like a script that can be automatically run when the UPS reaches a certain level. I had a look at the python SDK but I could only find functions for shutting down VMs and not hosts. Also I suspect this wont let me shutdown the hosted engine VM.
Any ideas?
Regards _______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users

I have created a python script using the oVirt SDK but I can't find an API to shutdown the hosted engine and hosts. I am guessing this isn't possible using the API as if you shutdown the hosted engine the API will stop working. I guess the only way to stop the hosted engine and shutdown hosts is via SSH or some kind of agent? #!/usr/bin/env python
import ovirtsdk4 as sdk
from ovirtsdk4 import types
import time
MINUTES_TO_WAIT=5
# must be run from infrastructure vlan
ovaddress = "removed"
username="removed"
password="removed"
connection = sdk.Connection(
url=ovaddress,
username=username,
password=password,
insecure=True
)
system_service = connection.system_service()
vms_service = system_service.vms_service()
# Shutdown VMs and put into global maintenance
vms = vms_service.list(search='status=up')
for vm in vms:
vm_service = vms_service.vm_service(vm.id)
if "HostedEngine" in vm.name:
vm_service.maintenance(maintenance_enabled=True)
print "Global maintenance enabled"
else:
vm_service.shutdown()
print ("%s shutdown" % (vm.name))
# Wait for VMs to shutdown
for x in range(0, MINUTES_TO_WAIT):
time.sleep(60)
vms = vms_service.list(search='status=up')
if len(vms) == 1:
# Just the Hosted Engine left
break
for vm in vms:
vm_service = vms_service.vm_service(vm.id)
print ("waiting for %s to shutdown" % (vm.name))
# Put hosts in local maintenance
hosts_service = connection.system_service().hosts_service()
hosts = hosts_service.list(search='status=up')
for host in hosts:
host_service = hosts_service.host_service(host.id)
if host.status != types.HostStatus.MAINTENANCE:
host_service.deactivate()
print ("%s put into maintenance mode" %(host.name))
# Shutdown Hosted Engine?
# Shutdown hosts?
connection.close()
On 24 April 2018 at 02:06, Doug Ingham <dougti@gmail.com> wrote:
I've plugged this into our monitoring.
When the UPS' are at 50%, it puts the general cluster into global maintenance & then triggers a shutdown action on all of the VMs in the cluster's service group via the monitoring agent (you could use an SNMP trap if you use agentless monitoring). Once all of the VMs are down, it then continues with the hosts.
At 20%, it does the same with our "core" cluster.
This method means that the HE can be shutdown, and it works whether the HE is up or not.
For emergencies when the monitoring is offline, I've also hacked up a bash script which parses the output of vdsClient & uses a loop to send a shutdown signal to all of the VMs on each host.
Doug
On Mon, 23 Apr 2018, 14:14 Simon Vincent, <sv@srvincent.co.uk> wrote:
Does anyone have a way of shutting down oVirt automatically in the case of a power outage?
Ideally I would like a script that can be automatically run when the UPS reaches a certain level. I had a look at the python SDK but I could only find functions for shutting down VMs and not hosts. Also I suspect this wont let me shutdown the hosted engine VM.
Any ideas?
Regards _______________________________________________ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users
participants (3)
-
Doug Ingham
-
Joop
-
Simon Vincent