2727logger = logging .getLogger ('cfncluster.cfncluster' )
2828unsupported_regions = ['ap-northeast-3' , 'cn-north-1' , 'cn-northwest-1' ]
2929
30- def prompt (prompt , default_value = None , hidden = False , options = None ):
30+ def prompt (prompt , default_value = None , hidden = False , options = None , check_validity = False ):
3131 if hidden and default_value is not None :
3232 user_prompt = prompt + ' [*******' + default_value [- 4 :] + ']: '
3333 else :
@@ -42,12 +42,17 @@ def prompt(prompt, default_value=None, hidden=False, options=None):
4242 for o in options :
4343 print (' %s' % o )
4444
45- var = input (user_prompt )
45+ var = input (user_prompt ). strip ()
4646
4747 if var == '' :
4848 return default_value
4949 else :
50- return var .strip ()
50+ if check_validity and options is not None and var not in options :
51+ print ('ERROR: The value (%s) is not valid ' % var )
52+ print ('Please select one of the Acceptable Values listed above.' )
53+ sys .exit (1 )
54+ else :
55+ return var
5156
5257def get_regions ():
5358 ec2 = boto3 .client ('ec2' )
@@ -130,13 +135,13 @@ def configure(args):
130135 aws_secret_access_key = prompt ('AWS Secret Access Key ID' , config .get ('aws' , 'aws_secret_access_key' ) if config .has_option ('aws' , 'aws_secret_access_key' ) else None , True )
131136
132137 # Use built in boto regions as an available option
133- aws_region_name = prompt ('AWS Region ID' , config .get ('aws' , 'aws_region_name' ) if config .has_option ('aws' , 'aws_region_name' ) else None , options = get_regions ())
138+ aws_region_name = prompt ('AWS Region ID' , config .get ('aws' , 'aws_region_name' ) if config .has_option ('aws' , 'aws_region_name' ) else None , options = get_regions (), check_validity = True )
134139 vpcname = prompt ('VPC Name' , config .get ('cluster ' + cluster_template , 'vpc_settings' ) if config .has_option ('cluster ' + cluster_template , 'vpc_settings' ) else 'public' )
135140
136141 # Query EC2 for available keys as options
137- key_name = prompt ('Key Name' , config .get ('cluster ' + cluster_template , 'key_name' ) if config .has_option ('cluster ' + cluster_template , 'key_name' ) else None , options = list_keys (aws_access_key_id , aws_secret_access_key , aws_region_name ))
138- vpc_id = prompt ('VPC ID' , config .get ('vpc ' + vpcname , 'vpc_id' ) if config .has_option ('vpc ' + vpcname , 'vpc_id' ) else None , options = list_vpcs (aws_access_key_id , aws_secret_access_key , aws_region_name ))
139- master_subnet_id = prompt ('Master Subnet ID' , config .get ('vpc ' + vpcname , 'master_subnet_id' ) if config .has_option ('vpc ' + vpcname , 'master_subnet_id' ) else None , options = list_subnets (aws_access_key_id , aws_secret_access_key , aws_region_name , vpc_id ))
142+ key_name = prompt ('Key Name' , config .get ('cluster ' + cluster_template , 'key_name' ) if config .has_option ('cluster ' + cluster_template , 'key_name' ) else None , options = list_keys (aws_access_key_id , aws_secret_access_key , aws_region_name ), check_validity = True )
143+ vpc_id = prompt ('VPC ID' , config .get ('vpc ' + vpcname , 'vpc_id' ) if config .has_option ('vpc ' + vpcname , 'vpc_id' ) else None , options = list_vpcs (aws_access_key_id , aws_secret_access_key , aws_region_name ), check_validity = True )
144+ master_subnet_id = prompt ('Master Subnet ID' , config .get ('vpc ' + vpcname , 'master_subnet_id' ) if config .has_option ('vpc ' + vpcname , 'master_subnet_id' ) else None , options = list_subnets (aws_access_key_id , aws_secret_access_key , aws_region_name , vpc_id ), check_validity = True )
140145
141146 # Dictionary of values we want to set
142147 s_global = { '__name__' : 'global' , 'cluster_template' : cluster_template , 'update_check' : 'true' , 'sanity_check' : 'true' }
0 commit comments