Blame SOURCES/bz1810457-fence_aws-improve-parameter-logic.patch

b7eff9
From 1c2f791b6b2be13bcceaa096df52654164b1f6cb Mon Sep 17 00:00:00 2001
b7eff9
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
b7eff9
Date: Thu, 5 Mar 2020 14:10:29 +0100
b7eff9
Subject: [PATCH] fence_aws: improve connect parameter logic, so region can be
b7eff9
 specified as parameter, while using role or keys from ~/.aws/config
b7eff9
b7eff9
---
b7eff9
 agents/aws/fence_aws.py | 27 +++++++++------------------
b7eff9
 1 file changed, 9 insertions(+), 18 deletions(-)
b7eff9
b7eff9
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
b7eff9
index 74321e8e..4a4d9de2 100644
b7eff9
--- a/agents/aws/fence_aws.py
b7eff9
+++ b/agents/aws/fence_aws.py
b7eff9
@@ -107,24 +107,15 @@ def main():
b7eff9
 
b7eff9
 	run_delay(options)
b7eff9
 
b7eff9
-	if "--region" in options and "--access-key" in options and "--secret-key" in options:  
b7eff9
-		region = options["--region"]
b7eff9
-		access_key = options["--access-key"]
b7eff9
-		secret_key = options["--secret-key"]
b7eff9
-		try:
b7eff9
-			conn = boto3.resource('ec2', region_name=region,
b7eff9
-					      aws_access_key_id=access_key,
b7eff9
-					      aws_secret_access_key=secret_key)
b7eff9
-		except Exception as e:
b7eff9
-			fail_usage("Failed: Unable to connect to AWS: " + str(e))
b7eff9
-	else:
b7eff9
-		# If setup with "aws configure" or manually in
b7eff9
-		# ~/.aws/credentials
b7eff9
-		try:
b7eff9
-			conn = boto3.resource('ec2')
b7eff9
-		except Exception as e:
b7eff9
-			# If any of region/access/secret are missing
b7eff9
-			fail_usage("Failed: Unable to connect to AWS: " + str(e))
b7eff9
+	region = options.get("--region")
b7eff9
+	access_key = options.get("--access-key")
b7eff9
+	secret_key = options.get("--secret-key")
b7eff9
+	try:
b7eff9
+		conn = boto3.resource('ec2', region_name=region,
b7eff9
+				      aws_access_key_id=access_key,
b7eff9
+				      aws_secret_access_key=secret_key)
b7eff9
+	except Exception as e:
b7eff9
+		fail_usage("Failed: Unable to connect to AWS: " + str(e))
b7eff9
 
b7eff9
 	# Operate the fencing device
b7eff9
 	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)