Blame SOURCES/bz1697559-aws-vpc-move-ip-1-multi-route-table-support.patch

b4b3ce
--- a/heartbeat/aws-vpc-move-ip	2019-05-20 10:54:01.527329668 +0200
b4b3ce
+++ b/heartbeat/aws-vpc-move-ip	2019-05-20 11:33:35.386089091 +0200
b4b3ce
@@ -93,11 +93,19 @@
b4b3ce
 <content type="string" default="" />
b4b3ce
 </parameter>
b4b3ce
 
b4b3ce
+<parameter name="address">
b4b3ce
+<longdesc lang="en">
b4b3ce
+Deprecated IP address param. Use the ip param instead.
b4b3ce
+</longdesc>
b4b3ce
+<shortdesc lang="en">Deprecated VPC private IP Address</shortdesc>
b4b3ce
+<content type="string" default="" />
b4b3ce
+</parameter>
b4b3ce
+
b4b3ce
 <parameter name="routing_table" required="1">
b4b3ce
 <longdesc lang="en">
b4b3ce
-Name of the routing table, where the route for the IP address should be changed, i.e. rtb-...
b4b3ce
+Name of the routing table(s), where the route for the IP address should be changed. If declaring multiple routing tables they should be separated by comma. Example: rtb-XXXXXXXX,rtb-YYYYYYYYY
b4b3ce
 </longdesc>
b4b3ce
-<shortdesc lang="en">routing table name</shortdesc>
b4b3ce
+<shortdesc lang="en">routing table name(s)</shortdesc>
b4b3ce
 <content type="string" default="" />
b4b3ce
 </parameter>
b4b3ce
 
b4b3ce
@@ -129,6 +137,13 @@
b4b3ce
 END
b4b3ce
 }
b4b3ce
 
b4b3ce
+ec2ip_set_address_param_compat(){
b4b3ce
+	# Include backward compatibility for the deprecated address parameter
b4b3ce
+	if [ -z  "$OCF_RESKEY_ip" ] && [ -n "$OCF_RESKEY_address" ]; then
b4b3ce
+		OCF_RESKEY_ip="$OCF_RESKEY_address"
b4b3ce
+	fi
b4b3ce
+}
b4b3ce
+
b4b3ce
 ec2ip_validate() {
b4b3ce
 	for cmd in aws ip curl; do
b4b3ce
 		check_binary "$cmd"
b4b3ce
@@ -150,20 +165,29 @@
b4b3ce
 }
b4b3ce
 
b4b3ce
 ec2ip_monitor() {
b4b3ce
-	if ocf_is_true ${OCF_RESKEY_monapi} || [ "$__OCF_ACTION" = "start" ]; then
b4b3ce
-		ocf_log info "monitor: check routing table (API call)"
b4b3ce
-		cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 describe-route-tables --route-table-ids $OCF_RESKEY_routing_table --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].InstanceId"
b4b3ce
-		ocf_log debug "executing command: $cmd"
b4b3ce
-		ROUTE_TO_INSTANCE=$($cmd)
b4b3ce
-		ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}"
b4b3ce
-		if [ -z "$ROUTE_TO_INSTANCE" ]; then
b4b3ce
-			ROUTE_TO_INSTANCE="<unknown>"
b4b3ce
-		fi
b4b3ce
+        MON_RES=""
b4b3ce
+	if ocf_is_true ${OCF_RESKEY_monapi} || [ "$__OCF_ACTION" = "start" ] || ocf_is_probe; then
b4b3ce
+		for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
b4b3ce
+			ocf_log info "monitor: check routing table (API call) - $rtb"
b4b3ce
+			cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].InstanceId"
b4b3ce
+			ocf_log debug "executing command: $cmd"
b4b3ce
+			ROUTE_TO_INSTANCE="$($cmd)"
b4b3ce
+			ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}"
b4b3ce
+			if [ -z "$ROUTE_TO_INSTANCE" ]; then
b4b3ce
+				ROUTE_TO_INSTANCE="<unknown>"
b4b3ce
+			fi
b4b3ce
+
b4b3ce
+			if [ "$EC2_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then 
b4b3ce
+				ocf_log warn "not routed to this instance ($EC2_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE on $rtb"
b4b3ce
+				MON_RES="$MON_RES $rtb"
b4b3ce
+			fi
b4b3ce
+			sleep 1
b4b3ce
+		done
b4b3ce
 
b4b3ce
-		if [ "$EC2_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ];then 
b4b3ce
-			ocf_log warn "not routed to this instance ($EC2_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE"
b4b3ce
+		if [ ! -z "$MON_RES" ]; then
b4b3ce
 			return $OCF_NOT_RUNNING
b4b3ce
 		fi
b4b3ce
+
b4b3ce
 	else
b4b3ce
 		ocf_log debug "monitor: Enhanced Monitoring disabled - omitting API call"
b4b3ce
 	fi
b4b3ce
@@ -195,19 +219,23 @@
b4b3ce
 }
b4b3ce
 
b4b3ce
 ec2ip_get_and_configure() {
b4b3ce
-	# Adjusting the routing table
b4b3ce
-	cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile ec2 replace-route --route-table-id $OCF_RESKEY_routing_table --destination-cidr-block ${OCF_RESKEY_ip}/32 --instance-id $EC2_INSTANCE_ID"
b4b3ce
-	ocf_log debug "executing command: $cmd"
b4b3ce
-	$cmd
b4b3ce
-	rc=$?
b4b3ce
-	if [ "$rc" != 0 ]; then
b4b3ce
-		ocf_log warn "command failed, rc: $rc"
b4b3ce
-		return $OCF_ERR_GENERIC
b4b3ce
-	fi
b4b3ce
+	for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
b4b3ce
+		cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --instance-id $EC2_INSTANCE_ID"
b4b3ce
+		ocf_log debug "executing command: $cmd"
b4b3ce
+		$cmd
b4b3ce
+		rc=$?
b4b3ce
+		if [ "$rc" != 0 ]; then
b4b3ce
+			ocf_log warn "command failed, rc: $rc"
b4b3ce
+			return $OCF_ERR_GENERIC
b4b3ce
+		fi
b4b3ce
+		sleep 1
b4b3ce
+	done
b4b3ce
 
b4b3ce
 	# Reconfigure the local ip address
b4b3ce
 	ec2ip_drop
b4b3ce
-	ip addr add "${OCF_RESKEY_ip}/32" dev $OCF_RESKEY_interface
b4b3ce
+	cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
b4b3ce
+	ocf_log debug "executing command: $cmd"
b4b3ce
+	$cmd
b4b3ce
 	rc=$?
b4b3ce
 	if [ $rc != 0 ]; then
b4b3ce
 		ocf_log warn "command failed, rc: $rc"
b4b3ce
@@ -289,6 +317,8 @@
b4b3ce
 	exit $OCF_ERR_PERM
b4b3ce
 fi
b4b3ce
 
b4b3ce
+ec2ip_set_address_param_compat
b4b3ce
+
b4b3ce
 ec2ip_validate
b4b3ce
 
b4b3ce
 case $__OCF_ACTION in