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

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