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

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