22import base64
33import calendar
44import collections
5- import configparser
65import datetime
76import ipaddress
87import json
3736from senza .components .elastigroup import ELASTIGROUP_RESOURCE_TYPE
3837from .spotinst .components import elastigroup_api
3938from .arguments import (
40- GLOBAL_OPTIONS ,
4139 json_output_option ,
4240 output_option ,
4341 parameter_file_option ,
4644 watch_option ,
4745 watchrefresh_option ,
4846 field_option ,
47+ get_region
4948)
5049from .aws import (
5150 StackReference ,
@@ -432,27 +431,6 @@ def read_parameter_file(parameter_file):
432431 return tuple (paras )
433432
434433
435- def get_region (region ):
436- if not region :
437- region = GLOBAL_OPTIONS .get ("region" )
438- if not region :
439- config = configparser .ConfigParser ()
440- try :
441- config .read (os .path .expanduser ("~/.aws/config" ))
442- if "default" in config :
443- region = config ["default" ]["region" ]
444- except Exception :
445- pass
446-
447- if not region :
448- raise click .UsageError (
449- "Please specify the AWS region on the "
450- "command line (--region) or in ~/.aws/config"
451- )
452-
453- return region
454-
455-
456434def check_credentials (region ):
457435 iam = BotoClientProxy ("iam" )
458436 return iam .list_account_aliases ()
@@ -523,7 +501,6 @@ def all_with_version(stack_refs: list):
523501def list_stacks (region , stack_ref , all , output , field , w , watch ):
524502 """List Cloud Formation stacks"""
525503
526- region = get_region (region )
527504 check_credentials (region )
528505
529506 stack_refs = get_stack_refs (stack_ref )
@@ -652,7 +629,6 @@ def get_classic_load_balancer_metrics(cloudwatch, lb_name, start, now):
652629def health (region , stack_ref , all , output , field , w , watch ):
653630 """Show stack health (ELB req/s, ..)"""
654631
655- region = get_region (region )
656632 check_credentials (region )
657633
658634 cloudwatch = BotoClientProxy ("cloudwatch" , region )
@@ -753,7 +729,6 @@ def create(
753729):
754730 """Create a new Cloud Formation stack from the given Senza definition file"""
755731
756- region = get_region (region )
757732 data = create_cf_template (
758733 definition , region , version , parameter , force , parameter_file
759734 )
@@ -825,7 +800,6 @@ def update(
825800 """Update an existing Cloud Formation stack from the given Senza
826801 definition file"""
827802
828- region = get_region (region )
829803 data = create_cf_template (
830804 definition , region , version , parameter , force , parameter_file
831805 )
@@ -844,7 +818,6 @@ def update(
844818def print_cfjson (definition , region , version , parameter , output , force , parameter_file ):
845819 """Print the generated Cloud Formation template"""
846820
847- region = get_region (region )
848821 data = create_cf_template (
849822 definition , region , version , parameter , force , parameter_file , pretty = True
850823 )
@@ -953,7 +926,6 @@ def delete(stack_ref, region, dry_run, force, interactive, ignore_non_existent):
953926 """Delete a single Cloud Formation stack"""
954927
955928 stack_refs = get_stack_refs (stack_ref )
956- region = get_region (region )
957929 check_credentials (region )
958930
959931 if not stack_refs :
@@ -1015,7 +987,6 @@ def resources(stack_ref, region, w, watch, output, field):
1015987 """Show all resources of a single Cloud Formation stack"""
1016988
1017989 stack_refs = get_stack_refs (stack_ref )
1018- region = get_region (region )
1019990 check_credentials (region )
1020991 cf = BotoClientProxy ("cloudformation" , region )
1021992
@@ -1063,7 +1034,6 @@ def events(stack_ref, region, w, watch, output, field):
10631034 """Show all Cloud Formation events for a single stack"""
10641035
10651036 stack_refs = get_stack_refs (stack_ref )
1066- region = get_region (region )
10671037 check_credentials (region )
10681038 cf = BotoClientProxy ("cloudformation" , region )
10691039
@@ -1120,7 +1090,6 @@ def events(stack_ref, region, w, watch, output, field):
11201090def init (definition_file , region , template , user_variable ):
11211091 """Initialize a new Senza definition"""
11221092
1123- region = get_region (region )
11241093 check_credentials (region )
11251094 account_info = AccountArguments (region = region )
11261095
@@ -1263,7 +1232,6 @@ def instances(
12631232 """List the stack's EC2 instances"""
12641233
12651234 stack_refs = get_stack_refs (stack_ref )
1266- region = get_region (region )
12671235 check_credentials (region )
12681236
12691237 ec2 = boto3 .resource ("ec2" , region )
@@ -1358,7 +1326,6 @@ def status(stack_ref, region, output, field, w, watch):
13581326 """Show stack status information"""
13591327
13601328 stack_refs = get_stack_refs (stack_ref )
1361- region = get_region (region )
13621329 check_credentials (region )
13631330
13641331 ec2 = boto3 .resource ("ec2" , region )
@@ -1451,7 +1418,6 @@ def domains(stack_ref, region, output, field, w, watch):
14511418 """List the stack's Route53 domains"""
14521419
14531420 stack_refs = get_stack_refs (stack_ref )
1454- region = get_region (region )
14551421 check_credentials (region )
14561422
14571423 cf = boto3 .resource ("cloudformation" , region )
@@ -1560,7 +1526,6 @@ def traffic(stack_name, stack_version, percentage, region, output, timeout, inte
15601526 """Route traffic to a specific stack (weighted DNS record)"""
15611527
15621528 stack_refs = get_stack_refs ([stack_name , stack_version ])
1563- region = get_region (region )
15641529 check_credentials (region )
15651530
15661531 with OutputFormat (output ):
@@ -1593,7 +1558,6 @@ def images(stack_ref, region, output, field, hide_older_than, show_instances):
15931558 """Show all used AMIs and available Taupage AMIs"""
15941559
15951560 stack_refs = get_stack_refs (stack_ref )
1596- region = get_region (region )
15971561 check_credentials (region )
15981562
15991563 ec2 = boto3 .resource ("ec2" , region )
@@ -1730,7 +1694,6 @@ def console(instance_or_stack_ref, limit, region, w, watch):
17301694 # filter out instances not part of any stack
17311695 filters = [{"Name" : "tag-key" , "Values" : ["aws:cloudformation:stack-name" ]}]
17321696
1733- region = get_region (region )
17341697 check_credentials (region )
17351698
17361699 ec2 = boto3 .resource ("ec2" , region )
@@ -1784,7 +1747,6 @@ def dump(stack_ref, region, output):
17841747 """Dump Cloud Formation template of existing stack"""
17851748
17861749 stack_refs = get_stack_refs (stack_ref )
1787- region = get_region (region )
17881750 check_credentials (region )
17891751
17901752 cf = BotoClientProxy ("cloudformation" , region )
@@ -1848,7 +1810,6 @@ def patch(stack_ref, region, image, instance_type, user_data):
18481810 Currently supports patching ASG launch configurations and ElastiGroup groups."""
18491811
18501812 stack_refs = get_stack_refs (stack_ref )
1851- region = get_region (region )
18521813 check_credentials (region )
18531814
18541815 if image in taupage .CHANNELS :
@@ -1948,7 +1909,6 @@ def respawn_instances(stack_ref, inplace, force, batch_size_percentage, batch_pe
19481909 Performs a rolling update to prevent downtimes."""
19491910
19501911 stack_refs = get_stack_refs (stack_ref )
1951- region = get_region (region )
19521912 check_credentials (region )
19531913
19541914 stacks = get_stacks (stack_refs , region )
@@ -1980,7 +1940,6 @@ def scale(stack_ref, region, desired_capacity, min_size, force):
19801940 """Scale Auto Scaling Group to desired capacity"""
19811941
19821942 stack_refs = get_stack_refs (stack_ref )
1983- region = get_region (region )
19841943 check_credentials (region )
19851944
19861945 stacks = get_stacks (stack_refs , region )
@@ -2120,7 +2079,6 @@ def wait(stack_ref, region, deletion, timeout, interval):
21202079 """
21212080
21222081 stack_refs = get_stack_refs (stack_ref )
2123- region = get_region (region )
21242082 cf = BotoClientProxy ("cloudformation" , region )
21252083
21262084 target_status = (
0 commit comments