Blame SOURCES/bz1568589-2-aliyun-vpc-move-ip-fixes.patch

7b144c
From db3df55a6f7097e1da7d77eb361e9e7560f13353 Mon Sep 17 00:00:00 2001
7b144c
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
7b144c
Date: Tue, 24 Jul 2018 13:57:08 +0200
7b144c
Subject: [PATCH] aliyun-vpc-move-ip: fixes
7b144c
7b144c
---
7b144c
 doc/man/Makefile.am          |   1 +
7b144c
 heartbeat/Makefile.am        |   1 +
7b144c
 heartbeat/aliyun-vpc-move-ip | 336 ++++++++++++++++++++++++-------------------
7b144c
 3 files changed, 189 insertions(+), 149 deletions(-)
7b144c
 mode change 100644 => 100755 heartbeat/aliyun-vpc-move-ip
7b144c
7b144c
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
7b144c
index 3ac0569de..fc9a67161 100644
7b144c
--- a/doc/man/Makefile.am
7b144c
+++ b/doc/man/Makefile.am
7b144c
@@ -93,6 +93,7 @@ man_MANS	       = ocf_heartbeat_AoEtarget.7 \
7b144c
                           ocf_heartbeat_WinPopup.7 \
7b144c
                           ocf_heartbeat_Xen.7 \
7b144c
                           ocf_heartbeat_Xinetd.7 \
7b144c
+                          ocf_heartbeat_aliyun-vpc-move-ip.7 \
7b144c
                           ocf_heartbeat_anything.7 \
7b144c
                           ocf_heartbeat_apache.7 \
7b144c
                           ocf_heartbeat_asterisk.7 \
7b144c
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
7b144c
index d4750bf09..6adc6bc3c 100644
7b144c
--- a/heartbeat/Makefile.am
7b144c
+++ b/heartbeat/Makefile.am
7b144c
@@ -90,6 +90,7 @@ ocf_SCRIPTS	     =  AoEtarget		\
7b144c
 			Xen			\
7b144c
 			Xinetd			\
7b144c
 			ZFS			\
7b144c
+			aliyun-vpc-move-ip	\
7b144c
 			anything		\
7b144c
 			apache			\
7b144c
 			asterisk		\
7b144c
diff --git a/heartbeat/aliyun-vpc-move-ip b/heartbeat/aliyun-vpc-move-ip
7b144c
old mode 100644
7b144c
new mode 100755
7b144c
index bc97822a8..108feb247
7b144c
--- a/heartbeat/aliyun-vpc-move-ip
7b144c
+++ b/heartbeat/aliyun-vpc-move-ip
7b144c
@@ -1,30 +1,19 @@
7b144c
-#!/bin/bash
7b144c
+#!/bin/sh
7b144c
 #
7b144c
 # OCF resource agent to move an IP address within a VPC in the Aliyun
7b144c
 # Based on code of Markus Guertler (GitHub AWS-VPC-move-IP)
7b144c
 # Based on code of Adam Gandelman (GitHub ec2-resource-agents/elasticip)
7b144c
 #
7b144c
 
7b144c
-###############################################################################
7b144c
-# For testing purposes delete OCF_ROOT after testing
7b144c
-OCF_ROOT=/usr/lib/ocf/
7b144c
-#
7b144c
-# INIT
7b144c
-#: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
7b144c
-#if [ -f ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs ]; then
7b144c
-#  . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
7b144c
-#fi
7b144c
-
7b144c
 #######################################################################
7b144c
 # Initialization:
7b144c
-
7b144c
-: ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
7b144c
-. ${OCF_FUNCTIONS}
7b144c
-: ${__OCF_ACTION=$1}
7b144c
-export HOME=/root
7b144c
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
7b144c
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
7b144c
 #######################################################################
7b144c
 
7b144c
- 
7b144c
+# aliyuncli doesnt work without HOME parameter
7b144c
+export HOME="/root"
7b144c
+
7b144c
 USAGE="usage: $0 {start|stop|status|meta-data}";
7b144c
 ###############################################################################
7b144c
 
7b144c
@@ -36,8 +25,96 @@ USAGE="usage: $0 {start|stop|status|meta-data}";
7b144c
 ###############################################################################
7b144c
 
7b144c
 
7b144c
-metadata() {
7b144c
-cat <
7b144c
+
7b144c
+ip_get_and_configure() {
7b144c
+	ocf_log debug "function: ip_get_and_configure"
7b144c
+
7b144c
+	ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+
7b144c
+	if [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then
7b144c
+		if [ -n "$ROUTE_TO_INSTANCE" ]; then
7b144c
+			ip_drop
7b144c
+		fi
7b144c
+
7b144c
+		cmd="aliyuncli vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
7b144c
+		ocf_log debug "executing command: $cmd"
7b144c
+		$cmd
7b144c
+		rc=$?
7b144c
+		while [ $rc -ne 0 ]; do
7b144c
+			sleep 1
7b144c
+			cmd="aliyuncli vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
7b144c
+			ocf_log debug "executing command: $cmd"
7b144c
+			$cmd
7b144c
+			rc=$?
7b144c
+		done
7b144c
+		wait_for_started
7b144c
+	fi
7b144c
+
7b144c
+
7b144c
+	# Reconfigure the local ip address
7b144c
+	ip addr add "${OCF_RESKEY_address}/32" dev $OCF_RESKEY_interface
7b144c
+	rc=$?
7b144c
+	if [ $rc -ne 0 ]; then
7b144c
+		ocf_log err "command failed, rc: $rc"
7b144c
+		return $OCF_ERR_GENERIC
7b144c
+	fi
7b144c
+
7b144c
+	ocf_log debug "IP added"
7b144c
+
7b144c
+	return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+ip_drop() {
7b144c
+	ocf_log debug "function: ip_drop"
7b144c
+	cmd="ip addr delete ${OCF_RESKEY_address}/32 dev $OCF_RESKEY_interface"
7b144c
+	ocf_log debug "executing command: $cmd"
7b144c
+	$cmd
7b144c
+	rc=$?
7b144c
+	if [ $rc -ne 0 ] && [ $rc -ne 2 ]; then
7b144c
+		ocf_log err "command failed, rc $rc"
7b144c
+		return $OCF_ERR_GENERIC
7b144c
+	fi
7b144c
+
7b144c
+	cmd="aliyuncli vpc DeleteRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ROUTE_TO_INSTANCE --output text"
7b144c
+	ocf_log debug "executing command: $cmd"
7b144c
+	$cmd
7b144c
+	if [ $? -ne 0 ]; then
7b144c
+		ocf_log err "command failed, rc: $rc"
7b144c
+		return $OCF_ERR_GENERIC
7b144c
+	fi
7b144c
+	wait_for_deleted
7b144c
+
7b144c
+	ocf_log debug "IP dropped"
7b144c
+
7b144c
+	return $OCF_SUCCESS
7b144c
+}
7b144c
+
7b144c
+wait_for_started() {
7b144c
+	cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
+	ocf_log debug "executing command: $cmd"
7b144c
+	ROUTE_TO_INSTANCE="$($cmd | grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+
7b144c
+	while [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; do
7b144c
+		sleep 3
7b144c
+		cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
+		ocf_log debug "executing command: $cmd"
7b144c
+		ROUTE_TO_INSTANCE="$($cmd | grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+	done
7b144c
+}
7b144c
+
7b144c
+wait_for_deleted() {
7b144c
+	ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+
7b144c
+	 while [ ! -z "$ROUTE_TO_INSTANCE" ]; do
7b144c
+		sleep 1
7b144c
+		cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
+		ocf_log debug "executing command: $cmd"
7b144c
+		ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+	 done
7b144c
+}
7b144c
+
7b144c
+ecs_ip_metadata() {
7b144c
+	cat <
7b144c
 
7b144c
 
7b144c
 <resource-agent name="vpc-move-ip">
7b144c
@@ -74,8 +151,8 @@ Name of the network interfacen, i.e. eth0
7b144c
 Valid Aliyun CLI profile name
7b144c
 </longdesc>
7b144c
 <shortdesc lang="en">profile name</shortdesc>
7b144c
-<content type="string" default="default" /> 
7b144c
-</parameter> 
7b144c
+<content type="string" default="default" />
7b144c
+</parameter>
7b144c
 </parameters>
7b144c
 <actions>
7b144c
 <action name="start" timeout="180" />
7b144c
@@ -88,171 +165,132 @@ Valid Aliyun CLI profile name
7b144c
 END
7b144c
 }
7b144c
 
7b144c
-debugger() {
7b144c
-	ocf_log info "DEBUG: $1"
7b144c
-}
7b144c
-
7b144c
 ecs_ip_validate() {
7b144c
-	debugger "function: validate"
7b144c
-	
7b144c
+	ocf_log debug "function: validate"
7b144c
+
7b144c
 	# IP address
7b144c
-	[[ -z "$OCF_RESKEY_address" ]] && ocf_log error "IP address parameter not set $OCF_RESKEY_ADDRESS!" && exit $OCF_ERR_CONFIGURED
7b144c
-	
7b144c
+	if [ -z "$OCF_RESKEY_address" ]; then
7b144c
+		ocf_log err "IP address parameter not set $OCF_RESKEY_ADDRESS!"
7b144c
+		exit $OCF_ERR_CONFIGURED
7b144c
+	fi
7b144c
+
7b144c
 	# Network Interface
7b144c
-	[[ -z "$OCF_RESKEY_interface" ]] && ocf_log error "Network interface parameter not set $OCF_RESKEY_INTERFACE!" && exit $OCF_ERR_CONFIGURED
7b144c
-	
7b144c
+	if [ -z "$OCF_RESKEY_interface" ]; then
7b144c
+		ocf_log err "Network interface parameter not set $OCF_RESKEY_INTERFACE!"
7b144c
+		exit $OCF_ERR_CONFIGURED
7b144c
+	fi
7b144c
+
7b144c
 	# Routing Table
7b144c
-	[[ -z "$OCF_RESKEY_routing_table" ]] && ocf_log error "Routing table parameter not set $OCF_RESKEY_ROUTING_TABLE!" && exit $OCF_ERR_CONFIGURED
7b144c
-	
7b144c
-	ECS_INSTANCE_ID="$(curl -s http://100.100.100.200/latest/meta-data/instance-id)"
7b144c
+	if [ -z "$OCF_RESKEY_routing_table" ]; then
7b144c
+		ocf_log err "Routing table parameter not set $OCF_RESKEY_ROUTING_TABLE!"
7b144c
+		exit $OCF_ERR_CONFIGURED
7b144c
+	fi
7b144c
 
7b144c
 	if [ -z "${ECS_INSTANCE_ID}" ]; then
7b144c
 		ocf_exit_reason "Instance ID not found. Is this a ECS instance?"
7b144c
 		return $OCF_ERR_GENERIC
7b144c
 	fi
7b144c
-	
7b144c
-	return $OCF_SUCCESS
7b144c
-}
7b144c
 
7b144c
-ecs_ip_monitor() {
7b144c
-	ecs_ip_validate
7b144c
-	debugger "function: ecsip_monitor: check routing table"
7b144c
-	cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
-	debugger "executing command: $cmd"
7b144c
-	ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
-	if [ -z "$ROUTE_TO_INSTANCE" ]; then 
7b144c
-		ROUTE_TO_INSTANCE="<unknown>"
7b144c
-	fi
7b144c
-	
7b144c
-	[[ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]] && debugger "not routed to this instance ($ECS_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE" && return $OCF_NOT_RUNNING 
7b144c
-	cmd="ping -W 1 -c 1 $OCF_RESKEY_address"
7b144c
-	debugger "executing command: $cmd"
7b144c
-	$cmd > /dev/null
7b144c
-	[[ $? -gt 0 ]]  && debugger "IP $OCF_RESKEY_address not locally reachable via ping on this system" && return $OCF_NOT_RUNNING
7b144c
-	debugger "routed in VPC and locally reachable"
7b144c
-	return $OCF_SUCCESS	
7b144c
-}
7b144c
-
7b144c
-
7b144c
-ecs_ip_drop() {
7b144c
-	debugger "function: ecsip_drop"
7b144c
-	cmd="ip addr delete ${OCF_RESKEY_address}/32 dev $OCF_RESKEY_interface"
7b144c
-	debugger "executing command: $cmd"
7b144c
-	$cmd
7b144c
-	rc=$?
7b144c
-	[[ $rc -gt 2 ]] && debugger "command failed, rc $rc" && return $OCF_ERR_GENERIC
7b144c
-	debugger "command succeeded"
7b144c
 	return $OCF_SUCCESS
7b144c
 }
7b144c
 
7b144c
-wait_for_deleted() {
7b144c
-  while [ ! -z "$ROUTE_TO_INSTANCE" ]; do
7b144c
-		sleep 1
7b144c
-		cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
-		debugger "executing command: $cmd"
7b144c
-		ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
-  done
7b144c
-	sleep 5
7b144c
-}
7b144c
+ecs_ip_start() {
7b144c
+	ocf_log info "ECS: Moving IP address $OCF_RESKEY_address to this host by adjusting routing table $OCF_RESKEY_routing_table"
7b144c
 
7b144c
-wait_for_started() {
7b144c
-	cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
-	debugger "executing command: $cmd"
7b144c
-	ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
-		
7b144c
-  while [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; do
7b144c
-		sleep 1
7b144c
-		cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
-		debugger "executing command: $cmd"
7b144c
-		ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
-  done
7b144c
-	sleep 5
7b144c
-}
7b144c
+	ecs_ip_monitor
7b144c
+	if [ $? = $OCF_SUCCESS ]; then
7b144c
+		ocf_log info "ECS: $OCF_RESKEY_address already started"
7b144c
+		return $OCF_SUCCESS
7b144c
+	fi
7b144c
 
7b144c
-ecs_ip_get_and_configure() {
7b144c
-	debugger "function: ecsip_get_and_configure"
7b144c
-  
7b144c
- if [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then 
7b144c
- 
7b144c
-     if [ $ROUTE_TO_INSTANCE != "<unknown>" ]; then
7b144c
-      # Adjusting the routing table
7b144c
-        cmd="aliyuncli  vpc DeleteRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ROUTE_TO_INSTANCE --output text"
7b144c
-        debugger "executing command: $cmd"
7b144c
-        $cmd
7b144c
-        rc=$?
7b144c
-        [[ $rc != 0 ]] && debugger "command failed, rc: $rc" && return $OCF_ERR_GENERIC
7b144c
-        #wait_for_deleted
7b144c
-        sleep 3
7b144c
-      fi
7b144c
-      
7b144c
-      cmd="aliyuncli  vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
7b144c
-      debugger "executing command: $cmd"
7b144c
-      $cmd
7b144c
-      rc=$?
7b144c
-      #[[ $rc != 0 ]] && debugger "command failed, rc: $rc" && return $OCF_ERR_GENERIC
7b144c
-		  while [ $rc != 0 ]; do
7b144c
-				sleep 2
7b144c
-				cmd="aliyuncli  vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
7b144c
-				debugger "executing command: $cmd"
7b144c
-				$cmd
7b144c
-				rc=$?
7b144c
-			done
7b144c
-      wait_for_started
7b144c
+	ocf_log info "ECS: Adjusting routing table and locally configuring IP address"
7b144c
+	ip_get_and_configure
7b144c
+	rc=$?
7b144c
+	if [ $rc -ne 0 ]; then
7b144c
+		ocf_log err "Received $rc from 'aliyun cli'"
7b144c
+		return $OCF_ERR_GENERIC
7b144c
 	fi
7b144c
-  
7b144c
-  
7b144c
-	# Reconfigure the local ip address
7b144c
-	ecs_ip_drop
7b144c
-	ip addr add "${OCF_RESKEY_address}/32" dev $OCF_RESKEY_interface
7b144c
+
7b144c
+	ecs_ip_monitor
7b144c
 	rc=$?
7b144c
-	[[ $rc != 0 ]] && debugger "command failed, rc: $rc" && return $OCF_ERR_GENERIC
7b144c
-	debugger "-success"
7b144c
+	if [ $rc -ne $OCF_SUCCESS ]; then
7b144c
+		ocf_log err "IP address couldn't be configured on this host (IP: $OCF_RESKEY_address, Interface: $OCF_RESKEY_interface)"
7b144c
+		return $rc
7b144c
+	fi
7b144c
+
7b144c
 	return $OCF_SUCCESS
7b144c
 }
7b144c
 
7b144c
 ecs_ip_stop() {
7b144c
 	ocf_log info "ECS: Bringing down IP address $OCF_RESKEY_address"
7b144c
-	ecs_ip_validate 
7b144c
+
7b144c
 	ecs_ip_monitor
7b144c
-	[[ $? == $OCF_NOT_RUNNING ]] && ocf_log info "ECS: Address $OCF_RESKEY_address already down" && return $OCF_SUCCESS
7b144c
-	ecs_ip_drop
7b144c
-	[[ $? != $OCF_SUCCESS ]] && return $OCF_ERR_GENERIC
7b144c
+	if [ $? = $OCF_NOT_RUNNING ]; then
7b144c
+		ocf_log info "ECS: Address $OCF_RESKEY_address already down"
7b144c
+		return $OCF_SUCCESS
7b144c
+	fi
7b144c
+
7b144c
+	ip_drop
7b144c
+	if [ $? -ne $OCF_SUCCESS ]; then
7b144c
+		ocf_log err "ECS: Couldn't drop IP address $OCF_RESKEY_address on interface $OCF_RESKEY_interface."
7b144c
+		return $OCF_ERR_GENERIC
7b144c
+	fi
7b144c
+
7b144c
 	ecs_ip_monitor
7b144c
-	[[ $? == $OCF_NOT_RUNNING ]] && ocf_log info "ECS: Successfully brought down $OCF_RESKEY_address" && return $OCF_SUCCESS
7b144c
-	ocf_log error "ECS: Couldn't bring down IP address $OCF_RESKEY_address on interface $OCF_RESKEY_interface." 
7b144c
+	if [ $? = $OCF_NOT_RUNNING ]; then
7b144c
+		ocf_log info "ECS: Successfully brought down $OCF_RESKEY_address"
7b144c
+		return $OCF_SUCCESS
7b144c
+	fi
7b144c
+
7b144c
+	ocf_log err "ECS: Couldn't bring down IP address $OCF_RESKEY_address on interface $OCF_RESKEY_interface."
7b144c
 	return $OCF_ERR_GENERIC
7b144c
 }
7b144c
 
7b144c
-ecs_ip_start() {
7b144c
-	ocf_log info "ECS: Moving IP address $OCF_RESKEY_address to this host by adjusting routing table $OCF_RESKEY_routing_table"
7b144c
-	ecs_ip_validate
7b144c
-	ecs_ip_monitor
7b144c
-	[[ $? == $OCF_SUCCESS ]] && ocf_log info "ECS: $OCF_RESKEY_address already started" && return $OCF_SUCCESS
7b144c
-	ocf_log info "ECS: Adjusting routing table and locally configuring IP address"
7b144c
-	ecs_ip_get_and_configure 
7b144c
-	[[ $? != 0 ]] && ocf_log error "Received $? from 'aliyun cli'" && return $OCF_ERR_GENERIC
7b144c
-  return $OCF_SUCCESS
7b144c
-	ecs_ip_monitor
7b144c
-	[[ $? == $OCF_SUCCESS ]] &&  return $?
7b144c
-	ocf_log error "ECS: IP address couldn't be configured on this host (IP: $OCF_RESKEY_address, Interface: $OCF_RESKEY_interface)"
7b144c
-	return $OCF_ERR_GENERIC
7b144c
+ecs_ip_monitor() {
7b144c
+	ocf_log debug "function: ecsip_monitor: check routing table"
7b144c
+	cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
7b144c
+	ocf_log debug "executing command: $cmd"
7b144c
+
7b144c
+	ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
7b144c
+
7b144c
+	if [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then
7b144c
+		ocf_log debug "not routed to this instance ($ECS_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE"
7b144c
+		return $OCF_NOT_RUNNING
7b144c
+	fi
7b144c
+
7b144c
+	cmd="ping -W 1 -c 1 $OCF_RESKEY_address"
7b144c
+	ocf_log debug "executing command: $cmd"
7b144c
+	$cmd > /dev/null
7b144c
+	if [ $? -ne 0 ]; then
7b144c
+		ocf_log debug "IP $OCF_RESKEY_address not locally reachable via ping on this system"
7b144c
+		return $OCF_NOT_RUNNING
7b144c
+	fi
7b144c
+	ocf_log debug "routed in VPC and locally reachable"
7b144c
+	return $OCF_SUCCESS
7b144c
 }
7b144c
 
7b144c
+
7b144c
 ###############################################################################
7b144c
 #
7b144c
 # MAIN
7b144c
 #
7b144c
 ###############################################################################
7b144c
 
7b144c
-case $__OCF_ACTION in 
7b144c
-	meta-data) metadata
7b144c
+case $__OCF_ACTION in
7b144c
+	meta-data) ecs_ip_metadata
7b144c
 		   exit $OCF_SUCCESS;;
7b144c
-	monitor)
7b144c
-		ecs_ip_monitor;;
7b144c
-	stop)
7b144c
-		ecs_ip_stop;;
7b144c
 	validate-all) ecs_ip_validate;;
7b144c
+esac
7b144c
+
7b144c
+ECS_INSTANCE_ID="$(curl -s http://100.100.100.200/latest/meta-data/instance-id)"
7b144c
+
7b144c
+case $__OCF_ACTION in
7b144c
 	start)
7b144c
+		ecs_ip_validate
7b144c
 		ecs_ip_start;;
7b144c
+	stop)
7b144c
+		ecs_ip_stop;;
7b144c
+	monitor)
7b144c
+		ecs_ip_monitor;;
7b144c
 	*)	exit $OCF_ERR_UNIMPLEMENTED;;
7b144c
-esac
7b144c
\ No newline at end of file
7b144c
+esac