[ovirt-users] Emergency shutdown script

Simon Vincent sv at srvincent.co.uk
Thu Apr 26 11:19:19 UTC 2018


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 at 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 at 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 at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/users
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20180426/575bb303/attachment.html>


More information about the Users mailing list