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

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