1414import sys
1515import inspect
1616import pkg_resources
17- import logging
1817import json
1918import urllib2
2019import config_sanity
20+ import boto .cloudformation
21+
22+ def getStackTemplate (region , aws_access_key_id , aws_secret_access_key , stack ):
23+
24+ cfn_conn = boto .cloudformation .connect_to_region (region ,aws_access_key_id = aws_access_key_id ,
25+ aws_secret_access_key = aws_secret_access_key )
26+ __stack_name = ('cfncluster-' + stack )
27+ __stack = cfn_conn .describe_stacks (stack_name_or_id = __stack_name )[0 ]
28+ __cli_template = [p .value for p in __stack .parameters if p .key == 'CLITemplate' ][0 ]
29+
30+ return __cli_template
2131
2232class CfnClusterConfig :
2333
@@ -26,6 +36,7 @@ def __init__(self, args):
2636 self .parameters = []
2737 self .version = pkg_resources .get_distribution ("cfncluster" ).version
2838 self .__DEFAULT_CONFIG = False
39+ __args_func = self .args .func .func_name
2940
3041 # Determine config file name based on args or default
3142 if args .config_file is not None :
@@ -50,12 +61,39 @@ def __init__(self, args):
5061 __config = ConfigParser .ConfigParser ()
5162 __config .read (self .__config_file )
5263
64+ # Determine the EC2 region to used used or default to us-east-1
65+ # Order is 1) CLI arg 2) AWS_DEFAULT_REGION env 3) Config file 4) us-east-1
66+ if args .region :
67+ self .region = args .region
68+ else :
69+ if os .environ .get ('AWS_DEFAULT_REGION' ):
70+ self .region = os .environ .get ('AWS_DEFAULT_REGION' )
71+ else :
72+ try :
73+ self .region = __config .get ('aws' , 'aws_region_name' )
74+ except ConfigParser .NoOptionError :
75+ self .region = 'us-east-1'
76+
77+ # Check if credentials have been provided in config
78+ try :
79+ self .aws_access_key_id = __config .get ('aws' , 'aws_access_key_id' )
80+ except ConfigParser .NoOptionError :
81+ self .aws_access_key_id = None
82+ try :
83+ self .aws_secret_access_key = __config .get ('aws' , 'aws_secret_access_key' )
84+ except ConfigParser .NoOptionError :
85+ self .aws_secret_access_key = None
86+
5387 # Determine which cluster template will be used
5488 try :
5589 if args .cluster_template is not None :
5690 self .__cluster_template = args .cluster_template
5791 else :
58- self .__cluster_template = __config .get ('global' , 'cluster_template' )
92+ if __args_func == 'update' :
93+ self .__cluster_template = getStackTemplate (self .region ,self .aws_access_key_id ,
94+ self .aws_secret_access_key , self .args .cluster_name )
95+ else :
96+ self .__cluster_template = __config .get ('global' , 'cluster_template' )
5997 except AttributeError :
6098 self .__cluster_template = __config .get ('global' , 'cluster_template' )
6199 self .__cluster_section = ('cluster %s' % self .__cluster_template )
@@ -82,34 +120,11 @@ def __init__(self, args):
82120 self .__sanity_check = False
83121 # Only check config on calls that mutate it
84122 __args_func = self .args .func .func_name
85- if (__args_func == 'create' or __args_func == 'update' ) and self .__sanity_check is True :
123+ if (__args_func == 'create' or __args_func == 'update' or __args_func == 'configure' ) and self .__sanity_check is True :
86124 pass
87125 else :
88126 self .__sanity_check = False
89127
90- # Determine the EC2 region to used used or default to us-east-1
91- # Order is 1) CLI arg 2) AWS_DEFAULT_REGION env 3) Config file 4) us-east-1
92- if args .region :
93- self .region = args .region
94- else :
95- if os .environ .get ('AWS_DEFAULT_REGION' ):
96- self .region = os .environ .get ('AWS_DEFAULT_REGION' )
97- else :
98- try :
99- self .region = __config .get ('aws' , 'aws_region_name' )
100- except ConfigParser .NoOptionError :
101- self .region = 'us-east-1'
102-
103- # Check if credentials have been provided in config
104- try :
105- self .aws_access_key_id = __config .get ('aws' , 'aws_access_key_id' )
106- except ConfigParser .NoOptionError :
107- self .aws_access_key_id = None
108- try :
109- self .aws_secret_access_key = __config .get ('aws' , 'aws_secret_access_key' )
110- except ConfigParser .NoOptionError :
111- self .aws_secret_access_key = None
112-
113128 # Get the EC2 keypair name to be used, exit if not set
114129 try :
115130 self .key_name = __config .get (self .__cluster_section , 'key_name' )
0 commit comments