Blame SOURCES/bz1939282-aws-vpc-move-ip-add-ENI-lookup.patch

f315e6
From b727fe4e2a0f4c88fca0ed9f90f57e570253c961 Mon Sep 17 00:00:00 2001
f315e6
From: Costas Tyfoxylos <costas.tyf@gmail.com>
f315e6
Date: Wed, 26 Aug 2020 15:18:00 +0300
f315e6
Subject: [PATCH 1/2] aws-vpc-move-ip: Implemented optional eni lookup instead
f315e6
 of the default instance id.
f315e6
f315e6
In a shared network pattern where the cluster resides in shared subnets the instance ids of the nodes are not retrievable but the eni ids are and this optional feature gives transparent support in that situation.
f315e6
---
f315e6
 heartbeat/aws-vpc-move-ip | 41 +++++++++++++++++++++++++++++++--------
f315e6
 1 file changed, 33 insertions(+), 8 deletions(-)
f315e6
f315e6
diff --git a/heartbeat/aws-vpc-move-ip b/heartbeat/aws-vpc-move-ip
f315e6
index 1b540caec..bc82428e5 100755
f315e6
--- a/heartbeat/aws-vpc-move-ip
f315e6
+++ b/heartbeat/aws-vpc-move-ip
f315e6
@@ -44,6 +44,7 @@ OCF_RESKEY_routing_table_default=""
f315e6
 OCF_RESKEY_routing_table_role_default=""
f315e6
 OCF_RESKEY_interface_default="eth0"
f315e6
 OCF_RESKEY_monapi_default="false"
f315e6
+OCF_RESKEY_lookup_type_default="InstanceId"
f315e6
 
f315e6
 : ${OCF_RESKEY_awscli=${OCF_RESKEY_awscli_default}}
f315e6
 : ${OCF_RESKEY_profile=${OCF_RESKEY_profile_default}}
f315e6
@@ -54,6 +55,7 @@ OCF_RESKEY_monapi_default="false"
f315e6
 : ${OCF_RESKEY_profile=${OCF_RESKEY_profile_default}}
f315e6
 : ${OCF_RESKEY_routing_table_role=${OCF_RESKEY_routing_table_role_default}}
f315e6
 : ${OCF_RESKEY_monapi=${OCF_RESKEY_monapi_default}}
f315e6
+: ${OCF_RESKEY_lookup_type=${OCF_RESKEY_lookup_type_default}}
f315e6
 #######################################################################
f315e6
 
f315e6
 #######################################################################
f315e6
@@ -154,6 +156,17 @@ Enable enhanced monitoring using AWS API calls to check route table entry
f315e6
 <shortdesc lang="en">Enhanced Monitoring</shortdesc>
f315e6
 <content type="boolean" default="${OCF_RESKEY_monapi_default}" />
f315e6
 </parameter>
f315e6
+
f315e6
+<parameter name="lookup_type" required="0">
f315e6
+<longdesc lang="en">
f315e6
+Name of resource type to lookup in route table.
f315e6
+"InstanceId"         : EC2 instance ID. (default)
f315e6
+"NetworkInterfaceId" : ENI ID. (useful in shared VPC setups).
f315e6
+</longdesc>
f315e6
+<shortdesc lang="en">lookup type for route table resource</shortdesc>
f315e6
+<content type="string" default="${OCF_RESKEY_lookup_type_default}" />
f315e6
+</parameter>
f315e6
+
f315e6
 </parameters>
f315e6
 
f315e6
 <actions>
f315e6
@@ -187,7 +200,7 @@ execute_cmd_as_role(){
f315e6
 
f315e6
 ec2ip_set_address_param_compat(){
f315e6
 	# Include backward compatibility for the deprecated address parameter
f315e6
-	if [ -z  "$OCF_RESKEY_ip" ] && [ -n "$OCF_RESKEY_address" ]; then
f315e6
+	if [ -z "$OCF_RESKEY_ip" ] && [ -n "$OCF_RESKEY_address" ]; then
f315e6
 		OCF_RESKEY_ip="$OCF_RESKEY_address"
f315e6
 	fi
f315e6
 }
f315e6
@@ -213,16 +226,24 @@ ec2ip_validate() {
f315e6
 }
f315e6
 
f315e6
 ec2ip_monitor() {
f315e6
-        MON_RES=""
f315e6
+	MON_RES=""
f315e6
+	if [ "${OCF_RESKEY_lookup_type}" = "NetworkInterfaceId" ]; then
f315e6
+		EC2_ID="$(ec2ip_get_instance_eni)"
f315e6
+		RESOURCE_TYPE="interface"
f315e6
+	else
f315e6
+		EC2_ID="$EC2_INSTANCE_ID"
f315e6
+		RESOURCE_TYPE="instance"
f315e6
+	fi
f315e6
+
f315e6
 	if ocf_is_true ${OCF_RESKEY_monapi} || [ "$__OCF_ACTION" = "start" ] || ocf_is_probe; then
f315e6
 		for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
f315e6
 			ocf_log info "monitor: check routing table (API call) - $rtb"
f315e6
 			if [[ -z "${OCF_RESKEY_routing_table_role}" ]]; then
f315e6
-				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"
f315e6
+				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'].$OCF_RESKEY_lookup_type"
f315e6
 				ocf_log debug "executing command: $cmd"
f315e6
 				ROUTE_TO_INSTANCE="$($cmd)"
f315e6
 			else
f315e6
-				cmd="$OCF_RESKEY_awscli --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].InstanceId"
f315e6
+				cmd="$OCF_RESKEY_awscli --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
f315e6
 				ROUTE_TO_INSTANCE="$(execute_cmd_as_role "$cmd" $OCF_RESKEY_routing_table_role)"
f315e6
 			fi
f315e6
 			ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}"
f315e6
@@ -230,8 +251,8 @@ ec2ip_monitor() {
f315e6
 				ROUTE_TO_INSTANCE="<unknown>"
f315e6
 			fi
f315e6
 
f315e6
-			if [ "$EC2_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then 
f315e6
-				ocf_log warn "not routed to this instance ($EC2_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE on $rtb"
f315e6
+			if [ "$EC2_ID" != "$ROUTE_TO_INSTANCE" ]; then
f315e6
+				ocf_log warn "not routed to this $RESOURCE_TYPE ($EC2_ID) but to $RESOURCE_TYPE $ROUTE_TO_INSTANCE on $rtb"
f315e6
 				MON_RES="$MON_RES $rtb"
f315e6
 			fi
f315e6
 			sleep 1
f315e6
@@ -275,7 +296,7 @@ ec2ip_drop() {
f315e6
 	return $OCF_SUCCESS
f315e6
 }
f315e6
 
f315e6
-ec2ip_get_and_configure() {
f315e6
+ec2ip_get_instance_eni() {
f315e6
 	MAC_FILE="/sys/class/net/${OCF_RESKEY_interface}/address"
f315e6
 	if [ -f $MAC_FILE ]; then
f315e6
 		cmd="cat ${MAC_FILE}"
f315e6
@@ -300,7 +321,11 @@ ec2ip_get_and_configure() {
f315e6
 		return $OCF_ERR_GENERIC
f315e6
 	fi
f315e6
 	ocf_log debug "network interface id associated MAC address ${MAC_ADDR}: ${EC2_NETWORK_INTERFACE_ID}"
f315e6
+	echo $EC2_NETWORK_INTERFACE_ID
f315e6
+}
f315e6
 
f315e6
+ec2ip_get_and_configure() {
f315e6
+	EC2_NETWORK_INTERFACE_ID="$(ec2ip_get_instance_eni)"
f315e6
 	for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
f315e6
 		if [ -z "${OCF_RESKEY_routing_table_role}" ]; then
f315e6
 			cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
f315e6
@@ -417,7 +442,7 @@ case $__OCF_ACTION in
f315e6
 		ec2ip_monitor;;
f315e6
 	validate-all)
f315e6
 		exit $?;;
f315e6
-	*)	
f315e6
+	*)
f315e6
 		echo $USAGE
f315e6
 		exit $OCF_ERR_UNIMPLEMENTED
f315e6
 		;;
f315e6
f315e6
From f4c8daae098dd33bdd5136ca4846eb505110e006 Mon Sep 17 00:00:00 2001
f315e6
From: Sander Botman <sbotman@schubergphilis.com>
f315e6
Date: Fri, 28 Aug 2020 22:01:03 +0200
f315e6
Subject: [PATCH 2/2] aws-vpc-move-ip: Fix the region option
f315e6
f315e6
---
f315e6
 heartbeat/aws-vpc-move-ip | 4 ++--
f315e6
 1 file changed, 2 insertions(+), 2 deletions(-)
f315e6
f315e6
diff --git a/heartbeat/aws-vpc-move-ip b/heartbeat/aws-vpc-move-ip
f315e6
index bc82428e5..a5b28ad92 100755
f315e6
--- a/heartbeat/aws-vpc-move-ip
f315e6
+++ b/heartbeat/aws-vpc-move-ip
f315e6
@@ -243,7 +243,7 @@ ec2ip_monitor() {
f315e6
 				ocf_log debug "executing command: $cmd"
f315e6
 				ROUTE_TO_INSTANCE="$($cmd)"
f315e6
 			else
f315e6
-				cmd="$OCF_RESKEY_awscli --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
f315e6
+				cmd="$OCF_RESKEY_awscli --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
f315e6
 				ROUTE_TO_INSTANCE="$(execute_cmd_as_role "$cmd" $OCF_RESKEY_routing_table_role)"
f315e6
 			fi
f315e6
 			ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}"
f315e6
@@ -332,7 +332,7 @@ ec2ip_get_and_configure() {
f315e6
 			ocf_log debug "executing command: $cmd"
f315e6
 			$cmd
f315e6
 		else
f315e6
-			cmd="$OCF_RESKEY_awscli --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
f315e6
+			cmd="$OCF_RESKEY_awscli --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
f315e6
 			update_response="$(execute_cmd_as_role "$cmd" $OCF_RESKEY_routing_table_role)"
f315e6
 		fi
f315e6
 		rc=$?