Blame SOURCES/nova-compute-wait-NovaEvacuate.patch

811adb
diff --color -uNr a/doc/man/Makefile.am b/doc/man/Makefile.am
811adb
--- a/doc/man/Makefile.am	2021-08-25 09:51:53.037906134 +0200
811adb
+++ b/doc/man/Makefile.am	2021-08-25 09:48:44.578408475 +0200
811adb
@@ -97,6 +97,8 @@
811adb
                           ocf_heartbeat_ManageRAID.7 \
811adb
                           ocf_heartbeat_ManageVE.7 \
811adb
                           ocf_heartbeat_NodeUtilization.7 \
811adb
+                          ocf_heartbeat_nova-compute-wait.7 \
811adb
+                          ocf_heartbeat_NovaEvacuate.7 \
811adb
                           ocf_heartbeat_Pure-FTPd.7 \
811adb
                           ocf_heartbeat_Raid1.7 \
811adb
                           ocf_heartbeat_Route.7 \
811adb
diff --color -uNr a/heartbeat/Makefile.am b/heartbeat/Makefile.am
811adb
--- a/heartbeat/Makefile.am	2021-08-25 09:51:53.038906137 +0200
811adb
+++ b/heartbeat/Makefile.am	2021-08-25 09:48:44.588408501 +0200
811adb
@@ -29,6 +29,8 @@
811adb
 
811adb
 ocfdir		        = $(OCF_RA_DIR_PREFIX)/heartbeat
811adb
 
811adb
+ospdir			= $(OCF_RA_DIR_PREFIX)/openstack
811adb
+
811adb
 dtddir			= $(datadir)/$(PACKAGE_NAME)
811adb
 dtd_DATA		= ra-api-1.dtd metadata.rng
811adb
 
811adb
@@ -50,6 +52,9 @@
811adb
 send_ua_SOURCES         = send_ua.c IPv6addr_utils.c
811adb
 send_ua_LDADD           = $(LIBNETLIBS)
811adb
 
811adb
+osp_SCRIPTS	     =  nova-compute-wait	\
811adb
+			NovaEvacuate
811adb
+
811adb
 ocf_SCRIPTS	      = AoEtarget		\
811adb
 			AudibleAlarm		\
811adb
 			ClusterMon		\
811adb
diff --color -uNr a/heartbeat/nova-compute-wait b/heartbeat/nova-compute-wait
811adb
--- a/heartbeat/nova-compute-wait	1970-01-01 01:00:00.000000000 +0100
811adb
+++ b/heartbeat/nova-compute-wait	2021-08-25 09:50:14.626646141 +0200
811adb
@@ -0,0 +1,345 @@
811adb
+#!/bin/sh
811adb
+#
811adb
+#
811adb
+# nova-compute-wait agent manages compute daemons.
811adb
+#
811adb
+# Copyright (c) 2015
811adb
+#
811adb
+# This program is free software; you can redistribute it and/or modify
811adb
+# it under the terms of version 2 of the GNU General Public License as
811adb
+# published by the Free Software Foundation.
811adb
+#
811adb
+# This program is distributed in the hope that it would be useful, but
811adb
+# WITHOUT ANY WARRANTY; without even the implied warranty of
811adb
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
811adb
+#
811adb
+# Further, this software is distributed without any warranty that it is
811adb
+# free of the rightful claim of any third person regarding infringement
811adb
+# or the like.  Any license provided herein, whether implied or
811adb
+# otherwise, applies only to this software file.  Patent licenses, if
811adb
+# any, provided herein do not apply to combinations of this program with
811adb
+# other software, or any other product whatsoever.
811adb
+#
811adb
+# You should have received a copy of the GNU General Public License
811adb
+# along with this program; if not, write the Free Software Foundation,
811adb
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
811adb
+#
811adb
+
811adb
+#######################################################################
811adb
+# Initialization:
811adb
+
811adb
+
811adb
+###
811adb
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
811adb
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
811adb
+###
811adb
+
811adb
+: ${__OCF_ACTION=$1}
811adb
+
811adb
+#######################################################################
811adb
+
811adb
+meta_data() {
811adb
+	cat <
811adb
+
811adb
+
811adb
+<resource-agent name="nova-compute-wait" version="1.0">
811adb
+<version>1.0</version>
811adb
+
811adb
+<longdesc lang="en">
811adb
+OpenStack Nova Compute Server.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">OpenStack Nova Compute Server</shortdesc>
811adb
+
811adb
+<parameters>
811adb
+
811adb
+<parameter name="auth_url" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="username" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+</parameter>
811adb
+
811adb
+<parameter name="password" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="tenant_name" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="domain" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+DNS domain in which hosts live, useful when the cluster uses short names and nova uses FQDN
811adb
+</longdesc>
811adb
+<shortdesc lang="en">DNS domain</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="endpoint_type" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="no_shared_storage" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Deprecated option not in use
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Deprecated</shortdesc>
811adb
+<content type="boolean" default="0" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="evacuation_delay" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+How long to wait for nova to finish evacuating instances elsewhere
811adb
+before starting nova-compute.  Only used when the agent detects
811adb
+evacuations might be in progress.
811adb
+
811adb
+You may need to increase the start timeout when increasing this value.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Delay to allow evacuations time to complete</shortdesc>
811adb
+<content type="integer" default="120" />
811adb
+</parameter>
811adb
+
811adb
+</parameters>
811adb
+
811adb
+<actions>
811adb
+<action name="start"        timeout="600" />
811adb
+<action name="stop"         timeout="300" />
811adb
+<action name="monitor"      timeout="20" interval="10" depth="0"/>
811adb
+<action name="validate-all" timeout="20" />
811adb
+<action name="meta-data"    timeout="5" />
811adb
+</actions>
811adb
+</resource-agent>
811adb
+END
811adb
+}
811adb
+
811adb
+#######################################################################
811adb
+
811adb
+# don't exit on TERM, to test that lrmd makes sure that we do exit
811adb
+trap sigterm_handler TERM
811adb
+sigterm_handler() {
811adb
+	ocf_log info "They use TERM to bring us down. No such luck."
811adb
+	return
811adb
+}
811adb
+
811adb
+nova_usage() {
811adb
+	cat <
811adb
+usage: $0 {start|stop|monitor|validate-all|meta-data}
811adb
+
811adb
+Expects to have a fully populated OCF RA-compliant environment set.
811adb
+END
811adb
+}
811adb
+
811adb
+nova_start() {
811adb
+    build_unfence_overlay
811adb
+
811adb
+    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
811adb
+    if [ "x$state" = x ]; then
811adb
+	: never been fenced
811adb
+
811adb
+    elif [ "x$state" = xno ]; then
811adb
+	: has been evacuated, however it could have been 1s ago
811adb
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
811adb
+	sleep ${OCF_RESKEY_evacuation_delay}
811adb
+
811adb
+    else
811adb
+	while [ "x$state" != "xno" ]; do
811adb
+	    ocf_log info "Waiting for pending evacuations from ${NOVA_HOST}"
811adb
+	    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
811adb
+	    sleep 5
811adb
+	done
811adb
+
811adb
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
811adb
+	sleep ${OCF_RESKEY_evacuation_delay}
811adb
+    fi
811adb
+
811adb
+    touch "$statefile"
811adb
+
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+nova_stop() {
811adb
+    rm -f "$statefile"
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+nova_monitor() {
811adb
+    if [ ! -f "$statefile" ]; then
811adb
+        return $OCF_NOT_RUNNING
811adb
+    fi
811adb
+
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+nova_notify() {
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+build_unfence_overlay() {
811adb
+    fence_options=""
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
811adb
+	candidates=$(/usr/sbin/stonith_admin -l ${NOVA_HOST})
811adb
+	for candidate in ${candidates}; do
811adb
+	    pcs stonith show $d | grep -q fence_compute
811adb
+	    if [ $? = 0 ]; then
811adb
+		ocf_log info "Unfencing nova based on: $candidate"
811adb
+		fence_auth=$(pcs stonith show $candidate | grep Attributes: | sed -e s/Attributes:// -e s/-/_/g -e 's/[^ ]\+=/OCF_RESKEY_\0/g' -e s/passwd/password/g)
811adb
+		eval "export $fence_auth"
811adb
+		break
811adb
+	    fi
811adb
+	done
811adb
+    fi    
811adb
+
811adb
+    # Copied from NovaEvacuate 
811adb
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
811adb
+        ocf_exit_reason "auth_url not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -k ${OCF_RESKEY_auth_url}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_username}" ]; then
811adb
+        ocf_exit_reason "username not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -l ${OCF_RESKEY_username}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_password}" ]; then
811adb
+        ocf_exit_reason "password not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -p ${OCF_RESKEY_password}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_tenant_name}" ]; then
811adb
+        ocf_exit_reason "tenant_name not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -t ${OCF_RESKEY_tenant_name}"
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_domain}" ]; then
811adb
+        fence_options="${fence_options} -d ${OCF_RESKEY_domain}"
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_region_name}" ]; then
811adb
+        fence_options="${fence_options} \
811adb
+            --region-name ${OCF_RESKEY_region_name}"
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_insecure}" ]; then
811adb
+        if ocf_is_true "${OCF_RESKEY_insecure}"; then
811adb
+            fence_options="${fence_options} --insecure"
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_no_shared_storage}" ]; then
811adb
+        if ocf_is_true "${OCF_RESKEY_no_shared_storage}"; then
811adb
+            fence_options="${fence_options} --no-shared-storage"
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_endpoint_type}" ]; then
811adb
+        case ${OCF_RESKEY_endpoint_type} in
811adb
+            adminURL|publicURL|internalURL)
811adb
+                ;;
811adb
+            *)
811adb
+                ocf_exit_reason "endpoint_type ${OCF_RESKEY_endpoint_type}" \
811adb
+                    "not valid. Use adminURL or publicURL or internalURL"
811adb
+                exit $OCF_ERR_CONFIGURED
811adb
+                ;;
811adb
+        esac
811adb
+        fence_options="${fence_options} -e ${OCF_RESKEY_endpoint_type}"
811adb
+    fi
811adb
+
811adb
+    mkdir -p /run/systemd/system/openstack-nova-compute.service.d
811adb
+    cat<<EOF>/run/systemd/system/openstack-nova-compute.service.d/unfence-20.conf
811adb
+[Service]
811adb
+ExecStartPost=/sbin/fence_compute ${fence_options} -o on -n ${NOVA_HOST}
811adb
+EOF
811adb
+}
811adb
+
811adb
+nova_validate() {
811adb
+    rc=$OCF_SUCCESS
811adb
+
811adb
+    check_binary crudini
811adb
+    check_binary nova-compute
811adb
+    check_binary fence_compute
811adb
+
811adb
+    if [ ! -f /etc/nova/nova.conf ]; then
811adb
+	   ocf_exit_reason "/etc/nova/nova.conf not found"
811adb
+	   exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    # Is the state directory writable?
811adb
+    state_dir=$(dirname $statefile)
811adb
+    touch "$state_dir/$$"
811adb
+    if [ $? != 0 ]; then
811adb
+        ocf_exit_reason "Invalid state directory: $state_dir"
811adb
+        return $OCF_ERR_ARGS
811adb
+    fi
811adb
+    rm -f "$state_dir/$$"
811adb
+
811adb
+    NOVA_HOST=$(crudini --get /etc/nova/nova.conf DEFAULT host 2>/dev/null)
811adb
+    if [ $? = 1 ]; then
811adb
+        short_host=$(uname -n | awk -F. '{print $1}')
811adb
+        if [ "x${OCF_RESKEY_domain}" != x ]; then
811adb
+            NOVA_HOST=${short_host}.${OCF_RESKEY_domain}
811adb
+        else
811adb
+            NOVA_HOST=$(uname -n)
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ $rc != $OCF_SUCCESS ]; then
811adb
+	exit $rc
811adb
+    fi
811adb
+    return $rc
811adb
+}
811adb
+
811adb
+statefile="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.active"
811adb
+
811adb
+: ${OCF_RESKEY_evacuation_delay=120}
811adb
+case $__OCF_ACTION in
811adb
+meta-data)	meta_data
811adb
+		exit $OCF_SUCCESS
811adb
+		;;
811adb
+usage|help)	nova_usage
811adb
+		exit $OCF_SUCCESS
811adb
+		;;
811adb
+esac
811adb
+
811adb
+case $__OCF_ACTION in
811adb
+start)		nova_validate; nova_start;;
811adb
+stop)		nova_stop;;
811adb
+monitor)	nova_validate; nova_monitor;;
811adb
+notify)		nova_notify;;
811adb
+validate-all)	exit $OCF_SUCCESS;;
811adb
+*)		nova_usage
811adb
+		exit $OCF_ERR_UNIMPLEMENTED
811adb
+		;;
811adb
+esac
811adb
+rc=$?
811adb
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
811adb
+exit $rc
811adb
+
811adb
diff --color -uNr a/heartbeat/NovaEvacuate b/heartbeat/NovaEvacuate
811adb
--- a/heartbeat/NovaEvacuate	1970-01-01 01:00:00.000000000 +0100
811adb
+++ b/heartbeat/NovaEvacuate	2021-08-25 09:50:23.780670326 +0200
811adb
@@ -0,0 +1,400 @@
811adb
+#!/bin/bash
811adb
+#
811adb
+# Copyright 2015 Red Hat, Inc.
811adb
+#
811adb
+# Description:  Manages evacuation of nodes running nova-compute
811adb
+#
811adb
+# Authors: Andrew Beekhof
811adb
+#
811adb
+# Support:      openstack@lists.openstack.org
811adb
+# License:      Apache Software License (ASL) 2.0
811adb
+#
811adb
+
811adb
+
811adb
+#######################################################################
811adb
+# Initialization:
811adb
+
811adb
+###
811adb
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
811adb
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
811adb
+###
811adb
+
811adb
+: ${__OCF_ACTION=$1}
811adb
+
811adb
+#######################################################################
811adb
+
811adb
+meta_data() {
811adb
+    cat <
811adb
+
811adb
+
811adb
+<resource-agent name="NovaEvacuate" version="1.0">
811adb
+<version>1.0</version>
811adb
+
811adb
+<longdesc lang="en">
811adb
+Facility for tacking a list of compute nodes and reliably evacuating the ones that fence_evacuate has flagged.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Evacuator for OpenStack Nova Compute Server</shortdesc>
811adb
+
811adb
+<parameters>
811adb
+
811adb
+<parameter name="auth_url" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Authorization URL for connecting to keystone in admin context
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Authorization URL</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="username" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Username for connecting to keystone in admin context
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Username</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="password" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Password for connecting to keystone in admin context
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Password</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="tenant_name" unique="0" required="1">
811adb
+<longdesc lang="en">
811adb
+Tenant name for connecting to keystone in admin context.
811adb
+Note that with Keystone V3 tenant names are only unique within a domain.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Tenant name</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="domain" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+DNS domain in which hosts live, useful when the cluster uses short names and nova uses FQDN
811adb
+</longdesc>
811adb
+<shortdesc lang="en">DNS domain</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="endpoint_type" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Nova API location (internal, public or admin URL)
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Nova API location (internal, public or admin URL)</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="region_name" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Region name for connecting to nova.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Region name</shortdesc>
811adb
+<content type="string" default="" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="insecure" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Explicitly allow client to perform "insecure" TLS (https) requests.
811adb
+The server's certificate will not be verified against any certificate authorities.
811adb
+This option should be used with caution.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Allow insecure TLS requests</shortdesc>
811adb
+<content type="boolean" default="0" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="no_shared_storage" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Indicate that nova storage for instances is not shared across compute
811adb
+nodes. This must match the reality of how nova storage is configured!
811adb
+Otherwise VMs could end up in error state upon evacuation. When
811adb
+storage is non-shared, instances on dead hypervisors will be rebuilt
811adb
+from their original image or volume, so anything on ephemeral storage
811adb
+will be lost.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Disable shared storage recovery for instances</shortdesc>
811adb
+<content type="boolean" default="0" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="verbose" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Enable extra logging from the evacuation process
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Enable debug logging</shortdesc>
811adb
+<content type="boolean" default="0" />
811adb
+</parameter>
811adb
+
811adb
+<parameter name="evacuate_delay" unique="0" required="0">
811adb
+<longdesc lang="en">
811adb
+Allows delaying the nova evacuate API call, e.g. to give a storage array time to clean
811adb
+up eventual locks/leases.
811adb
+</longdesc>
811adb
+<shortdesc lang="en">Nova evacuate delay</shortdesc>
811adb
+<content type="integer" default="0" />
811adb
+</parameter>
811adb
+
811adb
+</parameters>
811adb
+
811adb
+<actions>
811adb
+<action name="start"        timeout="20" />
811adb
+<action name="stop"         timeout="20" />
811adb
+<action name="monitor"      timeout="600" interval="10" depth="0"/>
811adb
+<action name="validate-all" timeout="20" />
811adb
+<action name="meta-data"    timeout="5" />
811adb
+</actions>
811adb
+</resource-agent>
811adb
+END
811adb
+}
811adb
+
811adb
+#######################################################################
811adb
+
811adb
+# don't exit on TERM, to test that lrmd makes sure that we do exit
811adb
+trap sigterm_handler TERM
811adb
+sigterm_handler() {
811adb
+    ocf_log info "They use TERM to bring us down. No such luck."
811adb
+    return
811adb
+}
811adb
+
811adb
+evacuate_usage() {
811adb
+    cat <
811adb
+usage: $0 {start|stop|monitor|validate-all|meta-data}
811adb
+
811adb
+Expects to have a fully populated OCF RA-compliant environment set.
811adb
+END
811adb
+}
811adb
+
811adb
+evacuate_stop() {
811adb
+    rm -f "$statefile"
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+evacuate_start() {
811adb
+    touch "$statefile"
811adb
+    # Do not invole monitor here so that the start timeout can be low
811adb
+    return $?
811adb
+}
811adb
+
811adb
+update_evacuation() {
811adb
+    attrd_updater -p -n evacuate -Q -N ${1} -U ${2}
811adb
+    arc=$?
811adb
+    if [ ${arc} != 0 ]; then
811adb
+        ocf_log warn "Can not set evacuation state of ${1} to ${2}: ${arc}"
811adb
+    fi
811adb
+    return ${arc}
811adb
+}
811adb
+
811adb
+handle_evacuations() {
811adb
+    while [ $# -gt 0 ]; do
811adb
+        node=$1
811adb
+        state=$2
811adb
+        shift; shift;
811adb
+        need_evacuate=0
811adb
+
811adb
+        case $state in
811adb
+            "")
811adb
+                ;;
811adb
+            no)
811adb
+                ocf_log debug "$node is either fine or already handled"
811adb
+                ;;
811adb
+            yes) need_evacuate=1
811adb
+                ;;
811adb
+            *@*)
811adb
+                where=$(echo $state | awk -F@ '{print $1}')
811adb
+                when=$(echo $state | awk -F@ '{print $2}')
811adb
+                now=$(date +%s)
811adb
+
811adb
+                if [ $(($now - $when)) -gt 60 ]; then
811adb
+                    ocf_log info "Processing partial evacuation of $node by" \
811adb
+                        "$where at $when"
811adb
+                    need_evacuate=1
811adb
+                else
811adb
+                    # Give some time for any in-flight evacuations to either
811adb
+                    # complete or fail Nova won't react well if there are two
811adb
+                    # overlapping requests
811adb
+                    ocf_log info "Deferring processing partial evacuation of" \
811adb
+                        "$node by $where at $when"
811adb
+                fi
811adb
+                ;;
811adb
+        esac
811adb
+
811adb
+        if [ $need_evacuate = 1 ]; then
811adb
+            fence_agent="fence_compute"
811adb
+
811adb
+            if have_binary fence_evacuate; then
811adb
+                fence_agent="fence_evacuate"
811adb
+            fi
811adb
+
811adb
+            if [ ${OCF_RESKEY_evacuate_delay} != 0 ]; then
811adb
+                ocf_log info "Delaying nova evacuate by $OCF_RESKEY_evacuate_delay seconds"
811adb
+                sleep ${OCF_RESKEY_evacuate_delay}
811adb
+            fi
811adb
+
811adb
+            ocf_log notice "Initiating evacuation of $node with $fence_agent"
811adb
+            $fence_agent ${fence_options} -o status -n ${node}
811adb
+            if [ $? = 1 ]; then
811adb
+                ocf_log info "Nova does not know about ${node}"
811adb
+                # Dont mark as no because perhaps nova is unavailable right now
811adb
+                continue
811adb
+            fi
811adb
+
811adb
+            update_evacuation ${node} "$(uname -n)@$(date +%s)"
811adb
+            if [ $? != 0 ]; then
811adb
+                return $OCF_SUCCESS
811adb
+            fi
811adb
+
811adb
+            $fence_agent ${fence_options} -o off -n $node
811adb
+            rc=$?
811adb
+
811adb
+            if [ $rc = 0 ]; then
811adb
+                update_evacuation ${node} no
811adb
+                ocf_log notice "Completed evacuation of $node"
811adb
+            else
811adb
+                ocf_log warn "Evacuation of $node failed: $rc"
811adb
+                update_evacuation ${node} yes
811adb
+            fi
811adb
+        fi
811adb
+    done
811adb
+
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+evacuate_monitor() {
811adb
+    if [ ! -f "$statefile" ]; then
811adb
+        return $OCF_NOT_RUNNING
811adb
+    fi
811adb
+
811adb
+    handle_evacuations $(
811adb
+        attrd_updater -n evacuate -A \
811adb
+            2> >(grep -v "attribute does not exist" 1>&2) |
811adb
+            sed 's/ value=""/ value="no"/' |
811adb
+            tr '="' '  ' |
811adb
+            awk '{print $4" "$6}'
811adb
+    )
811adb
+    return $OCF_SUCCESS
811adb
+}
811adb
+
811adb
+evacuate_validate() {
811adb
+    rc=$OCF_SUCCESS
811adb
+    fence_options=""
811adb
+
811adb
+    if ! have_binary fence_evacuate; then
811adb
+       check_binary fence_compute
811adb
+    fi
811adb
+
811adb
+    # Is the state directory writable?
811adb
+    state_dir=$(dirname $statefile)
811adb
+    touch "$state_dir/$$"
811adb
+    if [ $? != 0 ]; then
811adb
+        ocf_exit_reason "Invalid state directory: $state_dir"
811adb
+        return $OCF_ERR_ARGS
811adb
+    fi
811adb
+    rm -f "$state_dir/$$"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
811adb
+        ocf_exit_reason "auth_url not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -k ${OCF_RESKEY_auth_url}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_username}" ]; then
811adb
+        ocf_exit_reason "username not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -l ${OCF_RESKEY_username}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_password}" ]; then
811adb
+        ocf_exit_reason "password not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -p ${OCF_RESKEY_password}"
811adb
+
811adb
+    if [ -z "${OCF_RESKEY_tenant_name}" ]; then
811adb
+        ocf_exit_reason "tenant_name not configured"
811adb
+        exit $OCF_ERR_CONFIGURED
811adb
+    fi
811adb
+
811adb
+    fence_options="${fence_options} -t ${OCF_RESKEY_tenant_name}"
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_domain}" ]; then
811adb
+        fence_options="${fence_options} -d ${OCF_RESKEY_domain}"
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_region_name}" ]; then
811adb
+        fence_options="${fence_options} \
811adb
+            --region-name ${OCF_RESKEY_region_name}"
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_insecure}" ]; then
811adb
+        if ocf_is_true "${OCF_RESKEY_insecure}"; then
811adb
+            fence_options="${fence_options} --insecure"
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_no_shared_storage}" ]; then
811adb
+        if ocf_is_true "${OCF_RESKEY_no_shared_storage}"; then
811adb
+            fence_options="${fence_options} --no-shared-storage"
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_verbose}" ]; then
811adb
+        if ocf_is_true "${OCF_RESKEY_verbose}"; then
811adb
+            fence_options="${fence_options} --verbose"
811adb
+        fi
811adb
+    fi
811adb
+
811adb
+    if [ -n "${OCF_RESKEY_endpoint_type}" ]; then
811adb
+        case ${OCF_RESKEY_endpoint_type} in
811adb
+            adminURL|publicURL|internalURL)
811adb
+                ;;
811adb
+            *)
811adb
+                ocf_exit_reason "endpoint_type ${OCF_RESKEY_endpoint_type}" \
811adb
+                    "not valid. Use adminURL or publicURL or internalURL"
811adb
+                exit $OCF_ERR_CONFIGURED
811adb
+                ;;
811adb
+        esac
811adb
+        fence_options="${fence_options} -e ${OCF_RESKEY_endpoint_type}"
811adb
+    fi
811adb
+
811adb
+    if [ $rc != $OCF_SUCCESS ]; then
811adb
+        exit $rc
811adb
+    fi
811adb
+    return $rc
811adb
+}
811adb
+
811adb
+statefile="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.active"
811adb
+
811adb
+case $__OCF_ACTION in
811adb
+    start)
811adb
+        evacuate_validate
811adb
+        evacuate_start
811adb
+        ;;
811adb
+    stop)
811adb
+        evacuate_stop
811adb
+        ;;
811adb
+    monitor)
811adb
+        evacuate_validate
811adb
+        evacuate_monitor
811adb
+        ;;
811adb
+    meta-data)
811adb
+        meta_data
811adb
+        exit $OCF_SUCCESS
811adb
+        ;;
811adb
+    usage|help)
811adb
+        evacuate_usage
811adb
+        exit $OCF_SUCCESS
811adb
+        ;;
811adb
+    validate-all)
811adb
+        exit $OCF_SUCCESS
811adb
+        ;;
811adb
+    *)
811adb
+        evacuate_usage
811adb
+        exit $OCF_ERR_UNIMPLEMENTED
811adb
+        ;;
811adb
+esac
811adb
+rc=$?
811adb
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
811adb
+exit $rc