Blame SOURCES/bz2003189-fence_aws-add-filter-parameter.patch

3b9c51
From d920421ccb3abb42ecb9ea3ba56948db00fe1c80 Mon Sep 17 00:00:00 2001
3b9c51
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
3b9c51
Date: Tue, 23 Mar 2021 12:14:11 +0100
3b9c51
Subject: [PATCH] fence_aws: add filter parameter to be able to limit which
3b9c51
 nodes are listed
3b9c51
3b9c51
---
3b9c51
 agents/aws/fence_aws.py           | 27 +++++++++++++++++++++------
3b9c51
 tests/data/metadata/fence_aws.xml |  5 +++++
3b9c51
 2 files changed, 26 insertions(+), 6 deletions(-)
3b9c51
3b9c51
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
3b9c51
index 8322df9ed..c947bf29c 100644
3b9c51
--- a/agents/aws/fence_aws.py
3b9c51
+++ b/agents/aws/fence_aws.py
3b9c51
@@ -38,8 +38,15 @@ def get_nodes_list(conn, options):
3b9c51
 	logger.info("Starting monitor operation")
3b9c51
 	result = {}
3b9c51
 	try:
3b9c51
-		for instance in conn.instances.all():
3b9c51
-			result[instance.id] = ("", None)
3b9c51
+		if "--filter" in options:
3b9c51
+			filter_key   = options["--filter"].split("=")[0].strip()
3b9c51
+			filter_value = options["--filter"].split("=")[1].strip()
3b9c51
+			filter = [{ "Name": filter_key, "Values": [filter_value] }]
3b9c51
+			for instance in conn.instances.filter(Filters=filter):
3b9c51
+				result[instance.id] = ("", None)
3b9c51
+		else:
3b9c51
+			for instance in conn.instances.all():
3b9c51
+				result[instance.id] = ("", None)
3b9c51
 	except ClientError:
3b9c51
 		fail_usage("Failed: Incorrect Access Key or Secret Key.")
3b9c51
 	except EndpointConnectionError:
3b9c51
@@ -111,7 +118,7 @@ def define_new_opts():
3b9c51
 	all_opt["region"] = {
3b9c51
 		"getopt" : "r:",
3b9c51
 		"longopt" : "region",
3b9c51
-		"help" : "-r, --region=[region]           Region, e.g. us-east-1",
3b9c51
+		"help" : "-r, --region=[region]          Region, e.g. us-east-1",
3b9c51
 		"shortdesc" : "Region.",
3b9c51
 		"required" : "0",
3b9c51
 		"order" : 2
3b9c51
@@ -132,21 +139,29 @@ def define_new_opts():
3b9c51
 		"required" : "0",
3b9c51
 		"order" : 4
3b9c51
 	}
3b9c51
+	all_opt["filter"] = {
3b9c51
+		"getopt" : ":",
3b9c51
+		"longopt" : "filter",
3b9c51
+		"help" : "--filter=[key=value]           Filter (e.g. vpc-id=[vpc-XXYYZZAA]",
3b9c51
+		"shortdesc": "Filter for list-action",
3b9c51
+		"required": "0",
3b9c51
+		"order": 5
3b9c51
+	}
3b9c51
 	all_opt["boto3_debug"] = {
3b9c51
 		"getopt" : "b:",
3b9c51
 		"longopt" : "boto3_debug",
3b9c51
-		"help" : "-b, --boto3_debug=[option]      Boto3 and Botocore library debug logging",
3b9c51
+		"help" : "-b, --boto3_debug=[option]     Boto3 and Botocore library debug logging",
3b9c51
 		"shortdesc": "Boto Lib debug",
3b9c51
 		"required": "0",
3b9c51
 		"default": "False",
3b9c51
-		"order": 5
3b9c51
+		"order": 6
3b9c51
 	}
3b9c51
 
3b9c51
 # Main agent method
3b9c51
 def main():
3b9c51
 	conn = None
3b9c51
 
3b9c51
-	device_opt = ["port", "no_password", "region", "access_key", "secret_key", "boto3_debug"]
3b9c51
+	device_opt = ["port", "no_password", "region", "access_key", "secret_key", "filter", "boto3_debug"]
3b9c51
 
3b9c51
 	atexit.register(atexit_handler)