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

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