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

7b144c
diff -uNr a/doc/man/Makefile.am b/doc/man/Makefile.am
7b144c
--- a/doc/man/Makefile.am	2018-06-27 13:22:31.576628598 +0200
7b144c
+++ b/doc/man/Makefile.am	2018-06-27 13:47:15.902753673 +0200
7b144c
@@ -75,6 +75,8 @@
7b144c
                           ocf_heartbeat_ManageRAID.7 \
7b144c
                           ocf_heartbeat_ManageVE.7 \
7b144c
                           ocf_heartbeat_NodeUtilization.7 \
7b144c
+                          ocf_heartbeat_nova-compute-wait.7 \
7b144c
+                          ocf_heartbeat_NovaEvacuate.7 \
7b144c
                           ocf_heartbeat_Pure-FTPd.7 \
7b144c
                           ocf_heartbeat_Raid1.7 \
7b144c
                           ocf_heartbeat_Route.7 \
7b144c
diff -uNr a/heartbeat/Makefile.am b/heartbeat/Makefile.am
7b144c
--- a/heartbeat/Makefile.am	2018-06-27 13:22:31.574628625 +0200
7b144c
+++ b/heartbeat/Makefile.am	2018-06-27 13:46:23.621453631 +0200
7b144c
@@ -29,6 +29,8 @@
7b144c
 
7b144c
 ocfdir		        = $(OCF_RA_DIR_PREFIX)/heartbeat
7b144c
 
7b144c
+ospdir			= $(OCF_RA_DIR_PREFIX)/openstack
7b144c
+
7b144c
 dtddir			= $(datadir)/$(PACKAGE_NAME)
7b144c
 dtd_DATA		= ra-api-1.dtd metadata.rng
7b144c
 
7b144c
@@ -50,6 +52,9 @@
7b144c
 IPv6addr_LDADD          = -lplumb $(LIBNETLIBS)
7b144c
 send_ua_LDADD           = $(LIBNETLIBS)
7b144c
 
7b144c
+osp_SCRIPTS	     =  nova-compute-wait	\
7b144c
+			NovaEvacuate
7b144c
+
7b144c
 ocf_SCRIPTS	     =  AoEtarget		\
7b144c
 			AudibleAlarm		\
7b144c
 			ClusterMon		\
7b144c
diff -uNr a/heartbeat/nova-compute-wait b/heartbeat/nova-compute-wait
7b144c
--- a/heartbeat/nova-compute-wait	1970-01-01 01:00:00.000000000 +0100
7b144c
+++ b/heartbeat/nova-compute-wait	2018-06-27 13:27:15.166830889 +0200
7b144c
@@ -0,0 +1,317 @@
7b144c
+#!/bin/sh
7b144c
+# Copyright 2015 Red Hat, Inc.
7b144c
+#
7b144c
+# Description:  Manages compute daemons
7b144c
+#
7b144c
+# Authors: Andrew Beekhof
7b144c
+#
7b144c
+# Support:      openstack@lists.openstack.org
7b144c
+# License:      Apache Software License (ASL) 2.0
7b144c
+#
7b144c
+
7b144c
+
7b144c
+#######################################################################
7b144c
+# Initialization:
7b144c
+
7b144c
+###
7b144c
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
7b144c
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
7b144c
+###
7b144c
+
7b144c
+: ${__OCF_ACTION=$1}
7b144c
+
7b144c
+#######################################################################
7b144c
+
7b144c
+meta_data() {
7b144c
+	cat <
7b144c
+
7b144c
+
7b144c
+<resource-agent name="nova-compute-wait" version="1.0">
7b144c
+<version>1.0</version>
7b144c
+
7b144c
+<longdesc lang="en">
7b144c
+OpenStack Nova Compute Server.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">OpenStack Nova Compute Server</shortdesc>
7b144c
+
7b144c
+<parameters>
7b144c
+
7b144c
+<parameter name="auth_url" unique="0" required="1">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="username" unique="0" required="1">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="password" unique="0" required="1">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="tenant_name" unique="0" required="1">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="domain" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+DNS domain in which hosts live, useful when the cluster uses short names and nova uses FQDN
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">DNS domain</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="endpoint_type" unique="0" required="0">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="no_shared_storage" unique="0" required="0">
7b144c
+<longdesc lang="en">Deprecated - do not use anymore.</longdesc>
7b144c
+<shortdesc lang="en">Deprecated - do not use anymore</shortdesc>
7b144c
+<content type="boolean" default="0" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="evacuation_delay" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+How long to wait for nova to finish evacuating instances elsewhere
7b144c
+before starting nova-compute.  Only used when the agent detects
7b144c
+evacuations might be in progress.
7b144c
+
7b144c
+You may need to increase the start timeout when increasing this value.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Delay to allow evacuations time to complete</shortdesc>
7b144c
+<content type="integer" default="120" />
7b144c
+</parameter>
7b144c
+
7b144c
+</parameters>
7b144c
+
7b144c
+<actions>
7b144c
+<action name="start"        timeout="600" />
7b144c
+<action name="stop"         timeout="300" />
7b144c
+<action name="monitor"      timeout="20" interval="10" depth="0"/>
7b144c
+<action name="validate-all" timeout="20" />
7b144c
+<action name="meta-data"    timeout="5" />
7b144c
+</actions>
7b144c
+</resource-agent>
7b144c
+END
7b144c
+}
7b144c
+
7b144c
+#######################################################################
7b144c
+
7b144c
+# don't exit on TERM, to test that lrmd makes sure that we do exit
7b144c
+trap sigterm_handler TERM
7b144c
+sigterm_handler() {
7b144c
+	ocf_log info "They use TERM to bring us down. No such luck."
7b144c
+	return
7b144c
+}
7b144c
+
7b144c
+nova_usage() {
7b144c
+	cat <
7b144c
+usage: $0 {start|stop|monitor|validate-all|meta-data}
7b144c
+
7b144c
+Expects to have a fully populated OCF RA-compliant environment set.
7b144c
+END
7b144c
+}
7b144c
+
7b144c
+nova_start() {
7b144c
+    build_unfence_overlay
7b144c
+
7b144c
+    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
7b144c
+    if [ "x$state" = x ]; then
7b144c
+	: never been fenced
7b144c
+
7b144c
+    elif [ "x$state" = xno ]; then
7b144c
+	: has been evacuated, however it could have been 1s ago
7b144c
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
7b144c
+	sleep ${OCF_RESKEY_evacuation_delay}
7b144c
+
7b144c
+    else
7b144c
+	while [ "x$state" != "xno" ]; do
7b144c
+	    ocf_log info "Waiting for pending evacuations from ${NOVA_HOST}"
7b144c
+	    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
7b144c
+	    sleep 5
7b144c
+	done
7b144c
+
7b144c
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
7b144c
+	sleep ${OCF_RESKEY_evacuation_delay}
7b144c
+    fi
7b144c
+
7b144c
+    touch "$statefile"
7b144c
+
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+nova_stop() {
7b144c
+    rm -f "$statefile"
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+nova_monitor() {
7b144c
+    if [ ! -f "$statefile" ]; then
7b144c
+        return $OCF_NOT_RUNNING
7b144c
+    fi
7b144c
+
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+nova_notify() {
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+build_unfence_overlay() {
7b144c
+    fence_options=""
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
7b144c
+	candidates=$(/usr/sbin/stonith_admin -l ${NOVA_HOST})
7b144c
+	for candidate in ${candidates}; do
7b144c
+	    pcs stonith show $d | grep -q fence_compute
7b144c
+	    if [ $? = 0 ]; then
7b144c
+		ocf_log info "Unfencing nova based on: $candidate"
7b144c
+		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)
7b144c
+		eval "export $fence_auth"
7b144c
+		break
7b144c
+	    fi
7b144c
+	done
7b144c
+    fi    
7b144c
+
7b144c
+    # Copied from NovaEvacuate 
7b144c
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
7b144c
+        ocf_exit_reason "auth_url not configured"
7b144c
+        exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -k ${OCF_RESKEY_auth_url}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_username}" ]; then
7b144c
+        ocf_exit_reason "username not configured"
7b144c
+        exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -l ${OCF_RESKEY_username}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_password}" ]; then
7b144c
+        ocf_exit_reason "password not configured"
7b144c
+        exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -p ${OCF_RESKEY_password}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_tenant_name}" ]; then
7b144c
+        ocf_exit_reason "tenant_name not configured"
7b144c
+        exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -t ${OCF_RESKEY_tenant_name}"
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_domain}" ]; then
7b144c
+        fence_options="${fence_options} -d ${OCF_RESKEY_domain}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_region_name}" ]; then
7b144c
+        fence_options="${fence_options} \
7b144c
+            --region-name ${OCF_RESKEY_region_name}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_insecure}" ]; then
7b144c
+        if ocf_is_true "${OCF_RESKEY_insecure}"; then
7b144c
+            fence_options="${fence_options} --insecure"
7b144c
+        fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_no_shared_storage}" ]; then
7b144c
+        if ocf_is_true "${OCF_RESKEY_no_shared_storage}"; then
7b144c
+            fence_options="${fence_options} --no-shared-storage"
7b144c
+        fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_endpoint_type}" ]; then
7b144c
+        case ${OCF_RESKEY_endpoint_type} in
7b144c
+            adminURL|publicURL|internalURL)
7b144c
+                ;;
7b144c
+            *)
7b144c
+                ocf_exit_reason "endpoint_type ${OCF_RESKEY_endpoint_type}" \
7b144c
+                    "not valid. Use adminURL or publicURL or internalURL"
7b144c
+                exit $OCF_ERR_CONFIGURED
7b144c
+                ;;
7b144c
+        esac
7b144c
+        fence_options="${fence_options} -e ${OCF_RESKEY_endpoint_type}"
7b144c
+    fi
7b144c
+
7b144c
+    mkdir -p /run/systemd/system/openstack-nova-compute.service.d
7b144c
+    cat<<EOF>/run/systemd/system/openstack-nova-compute.service.d/unfence-20.conf
7b144c
+[Service]
7b144c
+ExecStartPost=/sbin/fence_compute ${fence_options} -o on -n ${NOVA_HOST}
7b144c
+EOF
7b144c
+}
7b144c
+
7b144c
+nova_validate() {
7b144c
+    rc=$OCF_SUCCESS
7b144c
+
7b144c
+    check_binary crudini
7b144c
+    check_binary nova-compute
7b144c
+    check_binary fence_compute
7b144c
+
7b144c
+    if [ ! -f /etc/nova/nova.conf ]; then
7b144c
+	   ocf_exit_reason "/etc/nova/nova.conf not found"
7b144c
+	   exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    # Is the state directory writable?
7b144c
+    state_dir=$(dirname $statefile)
7b144c
+    touch "$state_dir/$$"
7b144c
+    if [ $? != 0 ]; then
7b144c
+        ocf_exit_reason "Invalid state directory: $state_dir"
7b144c
+        return $OCF_ERR_ARGS
7b144c
+    fi
7b144c
+    rm -f "$state_dir/$$"
7b144c
+
7b144c
+    NOVA_HOST=$(crudini --get /etc/nova/nova.conf DEFAULT host 2>/dev/null)
7b144c
+    if [ $? = 1 ]; then
7b144c
+        short_host=$(uname -n | awk -F. '{print $1}')
7b144c
+        if [ "x${OCF_RESKEY_domain}" != x ]; then
7b144c
+            NOVA_HOST=${short_host}.${OCF_RESKEY_domain}
7b144c
+        else
7b144c
+            NOVA_HOST=$(uname -n)
7b144c
+        fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ $rc != $OCF_SUCCESS ]; then
7b144c
+	exit $rc
7b144c
+    fi
7b144c
+    return $rc
7b144c
+}
7b144c
+
7b144c
+statefile="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.active"
7b144c
+
7b144c
+: ${OCF_RESKEY_evacuation_delay=120}
7b144c
+case $__OCF_ACTION in
7b144c
+meta-data)	meta_data
7b144c
+		exit $OCF_SUCCESS
7b144c
+		;;
7b144c
+usage|help)	nova_usage
7b144c
+		exit $OCF_SUCCESS
7b144c
+		;;
7b144c
+esac
7b144c
+
7b144c
+case $__OCF_ACTION in
7b144c
+start)		nova_validate; nova_start;;
7b144c
+stop)		nova_stop;;
7b144c
+monitor)	nova_validate; nova_monitor;;
7b144c
+notify)		nova_notify;;
7b144c
+validate-all)	exit $OCF_SUCCESS;;
7b144c
+*)		nova_usage
7b144c
+		exit $OCF_ERR_UNIMPLEMENTED
7b144c
+		;;
7b144c
+esac
7b144c
+rc=$?
7b144c
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
7b144c
+exit $rc
7b144c
+
7b144c
diff -uNr a/heartbeat/NovaEvacuate b/heartbeat/NovaEvacuate
7b144c
--- a/heartbeat/NovaEvacuate	1970-01-01 01:00:00.000000000 +0100
7b144c
+++ b/heartbeat/NovaEvacuate	2018-06-27 13:27:18.835781756 +0200
7b144c
@@ -0,0 +1,388 @@
7b144c
+#!/bin/sh
7b144c
+#
7b144c
+# Copyright 2015 Red Hat, Inc.
7b144c
+#
7b144c
+# Description:  Manages evacuation of nodes running nova-compute
7b144c
+#
7b144c
+# Authors: Andrew Beekhof
7b144c
+#
7b144c
+# Support:      openstack@lists.openstack.org
7b144c
+# License:      Apache Software License (ASL) 2.0
7b144c
+#
7b144c
+
7b144c
+
7b144c
+#######################################################################
7b144c
+# Initialization:
7b144c
+
7b144c
+###
7b144c
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
7b144c
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
7b144c
+###
7b144c
+
7b144c
+: ${__OCF_ACTION=$1}
7b144c
+
7b144c
+#######################################################################
7b144c
+
7b144c
+meta_data() {
7b144c
+	cat <
7b144c
+
7b144c
+
7b144c
+<resource-agent name="NovaEvacuate" version="1.0">
7b144c
+<version>1.0</version>
7b144c
+
7b144c
+<longdesc lang="en">
7b144c
+Facility for tacking a list of compute nodes and reliably evacuating the ones that fence_evacuate has flagged.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Evacuator for OpenStack Nova Compute Server</shortdesc>
7b144c
+
7b144c
+<parameters>
7b144c
+
7b144c
+<parameter name="auth_url" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+Authorization URL for connecting to keystone in admin context
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Authorization URL</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="username" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+Username for connecting to keystone in admin context
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Username</shortdesc>
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="password" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+Password for connecting to keystone in admin context
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Password</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="tenant_name" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+Tenant name for connecting to keystone in admin context.
7b144c
+Note that with Keystone V3 tenant names are only unique within a domain.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Keystone v2 Tenant or v3 Project Name</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="user_domain" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+User's domain name. Used when authenticating to Keystone.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Keystone v3 User Domain</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="project_domain" unique="0" required="1">
7b144c
+<longdesc lang="en">
7b144c
+Domain name containing project. Used when authenticating to Keystone.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Keystone v3 Project Domain</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="endpoint_type" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+Nova API location (internal, public or admin URL)
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Nova API location (internal, public or admin URL)</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="region_name" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+Region name for connecting to nova.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Region name</shortdesc>
7b144c
+<content type="string" default="" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="insecure" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+Explicitly allow client to perform "insecure" TLS (https) requests.
7b144c
+The server's certificate will not be verified against any certificate authorities.
7b144c
+This option should be used with caution.
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Allow insecure TLS requests</shortdesc>
7b144c
+<content type="boolean" default="0" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="no_shared_storage" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+Disable shared storage recovery for instances. Use at your own risk!
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Disable shared storage recovery for instances</shortdesc>
7b144c
+<content type="boolean" default="0" />
7b144c
+</parameter>
7b144c
+
7b144c
+<parameter name="verbose" unique="0" required="0">
7b144c
+<longdesc lang="en">
7b144c
+Enable extra logging from the evacuation process
7b144c
+</longdesc>
7b144c
+<shortdesc lang="en">Enable debug logging</shortdesc>
7b144c
+<content type="boolean" default="0" />
7b144c
+</parameter>
7b144c
+
7b144c
+</parameters>
7b144c
+
7b144c
+<actions>
7b144c
+<action name="start"        timeout="20" />
7b144c
+<action name="stop"         timeout="20" />
7b144c
+<action name="monitor"      timeout="600" interval="10" depth="0"/>
7b144c
+<action name="validate-all" timeout="20" />
7b144c
+<action name="meta-data"    timeout="5" />
7b144c
+</actions>
7b144c
+</resource-agent>
7b144c
+END
7b144c
+}
7b144c
+
7b144c
+#######################################################################
7b144c
+
7b144c
+# don't exit on TERM, to test that lrmd makes sure that we do exit
7b144c
+trap sigterm_handler TERM
7b144c
+sigterm_handler() {
7b144c
+	ocf_log info "They use TERM to bring us down. No such luck."
7b144c
+	return
7b144c
+}
7b144c
+
7b144c
+evacuate_usage() {
7b144c
+	cat <
7b144c
+usage: $0 {start|stop|monitor|validate-all|meta-data}
7b144c
+
7b144c
+Expects to have a fully populated OCF RA-compliant environment set.
7b144c
+END
7b144c
+}
7b144c
+
7b144c
+evacuate_stop() {
7b144c
+    rm -f "$statefile"
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+evacuate_start() {
7b144c
+    touch "$statefile"
7b144c
+    # Do not invole monitor here so that the start timeout can be low
7b144c
+    return $?
7b144c
+}
7b144c
+
7b144c
+update_evacuation() {
7b144c
+    attrd_updater -p -n evacuate -Q -N ${1} -v ${2}
7b144c
+    arc=$?
7b144c
+    if [ ${arc} != 0 ]; then
7b144c
+	ocf_log warn "Can not set evacuation state of ${1} to ${2}: ${arc}"
7b144c
+    fi
7b144c
+    return ${arc}
7b144c
+}
7b144c
+
7b144c
+handle_evacuations() {
7b144c
+    while [ $# -gt 0 ]; do
7b144c
+	node=$1 
7b144c
+	state=$2
7b144c
+	shift; shift;
7b144c
+	need_evacuate=0
7b144c
+
7b144c
+	case $state in
7b144c
+	    "")
7b144c
+	        ;;
7b144c
+	    no)
7b144c
+		ocf_log debug "$node is either fine or already handled"
7b144c
+		;;
7b144c
+	    yes) need_evacuate=1
7b144c
+		;; 
7b144c
+	    *@*)
7b144c
+		where=$(echo $state | awk -F@ '{print $1}')
7b144c
+		when=$(echo $state | awk -F@ '{print $2}')
7b144c
+		now=$(date +%s)
7b144c
+
7b144c
+		if [ $(($now - $when)) -gt 60 ]; then
7b144c
+		    ocf_log info "Processing partial evacuation of $node by $where at $when"
7b144c
+		    need_evacuate=1
7b144c
+		else
7b144c
+		    # Give some time for any in-flight evacuations to either complete or fail
7b144c
+		    # Nova won't react well if there are two overlapping requests 
7b144c
+		    ocf_log info "Deferring processing partial evacuation of $node by $where at $when"
7b144c
+		fi
7b144c
+		;;
7b144c
+	esac
7b144c
+
7b144c
+	if [ $need_evacuate = 1 ]; then
7b144c
+	    fence_agent="fence_compute"
7b144c
+
7b144c
+	    if have_binary fence_evacuate
7b144c
+	    then
7b144c
+		fence_agent="fence_evacuate"
7b144c
+	    fi
7b144c
+
7b144c
+	    ocf_log notice "Initiating evacuation of $node with $fence_agent"
7b144c
+	    $fence_agent ${fence_options} -o status -n ${node}
7b144c
+	    if [ $? = 1 ]; then
7b144c
+		ocf_log info "Nova does not know about ${node}"
7b144c
+		# Dont mark as no because perhaps nova is unavailable right now
7b144c
+		continue
7b144c
+	    fi
7b144c
+
7b144c
+	    update_evacuation ${node} "$(uname -n)@$(date +%s)"
7b144c
+	    if [ $? != 0 ]; then
7b144c
+		return $OCF_SUCCESS
7b144c
+	    fi
7b144c
+
7b144c
+	    $fence_agent ${fence_options} -o off -n $node
7b144c
+	    rc=$?
7b144c
+
7b144c
+	    if [ $rc = 0 ]; then
7b144c
+		update_evacuation ${node} no
7b144c
+		ocf_log notice "Completed evacuation of $node"
7b144c
+	    else
7b144c
+		ocf_log warn "Evacuation of $node failed: $rc"
7b144c
+		update_evacuation ${node} yes
7b144c
+	    fi
7b144c
+	fi
7b144c
+    done
7b144c
+
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+evacuate_monitor() {
7b144c
+    if [ ! -f "$statefile" ]; then
7b144c
+	return $OCF_NOT_RUNNING
7b144c
+    fi
7b144c
+
7b144c
+    handle_evacuations $(
7b144c
+        attrd_updater -n evacuate -A |
7b144c
+            sed 's/ value=""/ value="no"/' |
7b144c
+            tr '="' '  ' |
7b144c
+            awk '{print $4" "$6}'
7b144c
+    )
7b144c
+    return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+evacuate_validate() {
7b144c
+    rc=$OCF_SUCCESS
7b144c
+    fence_options=""
7b144c
+
7b144c
+    
7b144c
+    if ! have_binary fence_evacuate; then
7b144c
+       check_binary fence_compute
7b144c
+    fi
7b144c
+
7b144c
+    # Is the state directory writable? 
7b144c
+    state_dir=$(dirname $statefile)
7b144c
+    touch "$state_dir/$$"
7b144c
+    if [ $? != 0 ]; then
7b144c
+	ocf_exit_reason "Invalid state directory: $state_dir"
7b144c
+	return $OCF_ERR_ARGS
7b144c
+    fi
7b144c
+    rm -f "$state_dir/$$"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
7b144c
+	   ocf_exit_reason "auth_url not configured"
7b144c
+	   exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -k ${OCF_RESKEY_auth_url}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_username}" ]; then
7b144c
+	   ocf_exit_reason "username not configured"
7b144c
+	   exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -l ${OCF_RESKEY_username}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_password}" ]; then
7b144c
+	   ocf_exit_reason "password not configured"
7b144c
+	   exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -p ${OCF_RESKEY_password}"
7b144c
+
7b144c
+    if [ -z "${OCF_RESKEY_tenant_name}" ]; then
7b144c
+	   ocf_exit_reason "tenant_name not configured"
7b144c
+	   exit $OCF_ERR_CONFIGURED
7b144c
+    fi
7b144c
+
7b144c
+    fence_options="${fence_options} -t ${OCF_RESKEY_tenant_name}"
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_user_domain}" ]; then
7b144c
+        fence_options="${fence_options} -u ${OCF_RESKEY_user_domain}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_project_domain}" ]; then
7b144c
+        fence_options="${fence_options} -P ${OCF_RESKEY_project_domain}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_region_name}" ]; then
7b144c
+        fence_options="${fence_options} \
7b144c
+            --region-name ${OCF_RESKEY_region_name}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_insecure}" ]; then
7b144c
+        if ocf_is_true "${OCF_RESKEY_insecure}"; then
7b144c
+            fence_options="${fence_options} --insecure"
7b144c
+        fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_no_shared_storage}" ]; then
7b144c
+	if ocf_is_true "${OCF_RESKEY_no_shared_storage}"; then
7b144c
+	    fence_options="${fence_options} --no-shared-storage"
7b144c
+	fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_verbose}" ]; then
7b144c
+        if ocf_is_true "${OCF_RESKEY_verbose}"; then
7b144c
+            fence_options="${fence_options} --verbose"
7b144c
+        fi
7b144c
+    fi
7b144c
+
7b144c
+    if [ -n "${OCF_RESKEY_endpoint_type}" ]; then
7b144c
+	case ${OCF_RESKEY_endpoint_type} in
7b144c
+	    adminURL|publicURL|internalURL) ;;
7b144c
+	    *)
7b144c
+		ocf_exit_reason "endpoint_type ${OCF_RESKEY_endpoint_type} not valid. Use adminURL or publicURL or internalURL"
7b144c
+		exit $OCF_ERR_CONFIGURED
7b144c
+	    ;;
7b144c
+	esac
7b144c
+	fence_options="${fence_options} -e ${OCF_RESKEY_endpoint_type}"
7b144c
+    fi
7b144c
+
7b144c
+    if [ $rc != $OCF_SUCCESS ]; then
7b144c
+	exit $rc
7b144c
+    fi
7b144c
+    return $rc
7b144c
+}
7b144c
+
7b144c
+statefile="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.active"
7b144c
+
7b144c
+case $__OCF_ACTION in
7b144c
+    start)
7b144c
+	evacuate_validate
7b144c
+	evacuate_start
7b144c
+	;;
7b144c
+    stop)
7b144c
+	evacuate_stop
7b144c
+	;;
7b144c
+    monitor)
7b144c
+	evacuate_validate
7b144c
+	evacuate_monitor
7b144c
+	;;
7b144c
+    meta-data)
7b144c
+	meta_data
7b144c
+	exit $OCF_SUCCESS
7b144c
+	;;
7b144c
+    usage|help)
7b144c
+	evacuate_usage
7b144c
+	exit $OCF_SUCCESS
7b144c
+	;;
7b144c
+    validate-all)
7b144c
+	exit $OCF_SUCCESS
7b144c
+	;;
7b144c
+    *)
7b144c
+	evacuate_usage
7b144c
+	exit $OCF_ERR_UNIMPLEMENTED
7b144c
+	;;
7b144c
+esac
7b144c
+rc=$?
7b144c
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
7b144c
+exit $rc