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