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

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