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

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