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