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