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

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