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

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