Blame SOURCES/bz2093214-aws-vpc-move-ip-add-interface-label-support.patch

f065e8
From 4420ef84f3172c67fc7b8b6ae41ea173de017bf4 Mon Sep 17 00:00:00 2001
f065e8
From: Petr Pavlu <petr.pavlu@suse.com>
f065e8
Date: Wed, 25 May 2022 15:12:33 +0200
f065e8
Subject: [PATCH] aws-vpc-move-ip: Allow to set the interface label
f065e8
f065e8
Add a parameter to specify an interface label to distinguish the IP
f065e8
address managed by aws-vpc-move-ip, similarly as can be done with
f065e8
IPaddr2. This allows to easily recognize the address from other
f065e8
addresses assigned to a given interface.
f065e8
---
f065e8
 heartbeat/aws-vpc-move-ip | 30 +++++++++++++++++++++++++++++-
f065e8
 1 file changed, 29 insertions(+), 1 deletion(-)
f065e8
f065e8
diff --git a/heartbeat/aws-vpc-move-ip b/heartbeat/aws-vpc-move-ip
f065e8
index 5d5204080..dee040300 100755
f065e8
--- a/heartbeat/aws-vpc-move-ip
f065e8
+++ b/heartbeat/aws-vpc-move-ip
f065e8
@@ -43,6 +43,7 @@ OCF_RESKEY_address_default=""
f065e8
 OCF_RESKEY_routing_table_default=""
f065e8
 OCF_RESKEY_routing_table_role_default=""
f065e8
 OCF_RESKEY_interface_default="eth0"
f065e8
+OCF_RESKEY_iflabel_default=""
f065e8
 OCF_RESKEY_monapi_default="false"
f065e8
 OCF_RESKEY_lookup_type_default="InstanceId"
f065e8
 
f065e8
@@ -54,6 +55,7 @@ OCF_RESKEY_lookup_type_default="InstanceId"
f065e8
 : ${OCF_RESKEY_routing_table=${OCF_RESKEY_routing_table_default}}
f065e8
 : ${OCF_RESKEY_routing_table_role=${OCF_RESKEY_routing_table_role_default}}
f065e8
 : ${OCF_RESKEY_interface=${OCF_RESKEY_interface_default}}
f065e8
+: ${OCF_RESKEY_iflabel=${OCF_RESKEY_iflabel_default}}
f065e8
 : ${OCF_RESKEY_monapi=${OCF_RESKEY_monapi_default}}
f065e8
 : ${OCF_RESKEY_lookup_type=${OCF_RESKEY_lookup_type_default}}
f065e8
 
f065e8
@@ -149,6 +151,18 @@ Name of the network interface, i.e. eth0
f065e8
 <content type="string" default="${OCF_RESKEY_interface_default}" />
f065e8
 </parameter>
f065e8
 
f065e8
+<parameter name="iflabel">
f065e8
+<longdesc lang="en">
f065e8
+You can specify an additional label for your IP address here.
f065e8
+This label is appended to your interface name.
f065e8
+
f065e8
+The kernel allows alphanumeric labels up to a maximum length of 15
f065e8
+characters including the interface name and colon (e.g. eth0:foobar1234)
f065e8
+</longdesc>
f065e8
+<shortdesc lang="en">Interface label</shortdesc>
f065e8
+<content type="string" default="${OCF_RESKEY_iflabel_default}"/>
f065e8
+</parameter>
f065e8
+
f065e8
 <parameter name="monapi">
f065e8
 <longdesc lang="en">
f065e8
 Enable enhanced monitoring using AWS API calls to check route table entry
f065e8
@@ -215,6 +229,14 @@ ec2ip_validate() {
f065e8
 		return $OCF_ERR_CONFIGURED
f065e8
 	fi
f065e8
 
f065e8
+	if [ -n "$OCF_RESKEY_iflabel" ]; then
f065e8
+		label=${OCF_RESKEY_interface}:${OFC_RESKEY_iflabel}
f065e8
+		if [ ${#label} -gt 15 ]; then
f065e8
+			ocf_exit_reason "Interface label [$label] exceeds maximum character limit of 15"
f065e8
+			exit $OCF_ERR_CONFIGURED
f065e8
+		fi
f065e8
+	fi
f065e8
+
f065e8
 	TOKEN=$(curl -sX PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
f065e8
 	EC2_INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id -H "X-aws-ec2-metadata-token: $TOKEN")
f065e8
 
f065e8
@@ -363,7 +385,13 @@ ec2ip_get_and_configure() {
f065e8
 
f065e8
 	# Reconfigure the local ip address
f065e8
 	ec2ip_drop
f065e8
-	cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
f065e8
+
f065e8
+	extra_opts=""
f065e8
+	if [ -n "$OCF_RESKEY_iflabel" ]; then
f065e8
+		extra_opts="$extra_opts label $OCF_RESKEY_interface:$OCF_RESKEY_iflabel"
f065e8
+	fi
f065e8
+
f065e8
+	cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface $extra_opts"
f065e8
 	ocf_log debug "executing command: $cmd"
f065e8
 	$cmd
f065e8
 	rc=$?