1717import logging
1818import json
1919import urllib2
20+ import config_sanity
2021
2122class CfnClusterConfig :
2223
@@ -73,25 +74,11 @@ def __init__(self, args):
7374 except Exception :
7475 pass
7576
76- # Get the EC2 keypair name to be used, exit if not set
77+ # Check if config sanity should be run
7778 try :
78- self .key_name = __config .get (self .__cluster_section , 'key_name' )
79- if not self .key_name :
80- raise Exception
79+ self .__sanity_check = __config .getboolean ('global' , 'sanity_check' )
8180 except ConfigParser .NoOptionError :
82- raise Exception
83- self .parameters .append (('KeyName' , self .key_name ))
84-
85- # Determine which keypair config will be used
86- self .__keypair_section = ('keypair %s' % self .key_name )
87-
88- # Get the location of the keypair file
89- try :
90- self .key_location = __config .get (self .__keypair_section , 'key_location' )
91- if not self .key_location :
92- raise Exception
93- except ConfigParser .NoOptionError :
94- raise Exception
81+ self .__sanity_check = False
9582
9683 # Determine the EC2 region to used used or default to us-east-1
9784 # Order is 1) CLI arg 2) AWS_DEFAULT_REGION env 3) Config file 4) us-east-1
@@ -116,6 +103,18 @@ def __init__(self, args):
116103 except ConfigParser .NoOptionError :
117104 self .aws_secret_access_key = None
118105
106+ # Get the EC2 keypair name to be used, exit if not set
107+ try :
108+ self .key_name = __config .get (self .__cluster_section , 'key_name' )
109+ if not self .key_name :
110+ raise Exception
111+ if self .__sanity_check :
112+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
113+ 'EC2KeyPair' , self .key_name )
114+ except ConfigParser .NoOptionError :
115+ raise Exception
116+ self .parameters .append (('KeyName' , self .key_name ))
117+
119118 # Determine the CloudFormation URL to be used
120119 # Order is 1) CLI arg 2) Config file 3) default for version + region
121120 try :
@@ -126,6 +125,9 @@ def __init__(self, args):
126125 'template_url' )
127126 if not self .template_url :
128127 raise Exception
128+ if self .__sanity_check :
129+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
130+ 'URL' , self .template_url )
129131 except ConfigParser .NoOptionError :
130132 self .template_url = ('https://s3.amazonaws.com/cfncluster-%s/templates/cfncluster-%s.cfn.json' % (self .region , self .version ))
131133 except AttributeError :
@@ -136,38 +138,46 @@ def __init__(self, args):
136138 self .__vpc_section = ('vpc %s' % self .__vpc_settings )
137139
138140 # Dictionary list of all VPC options
139- self .__vpc_options = dict (vpc_id = 'VPCId' , master_subnet_id = 'MasterSubnetId' , compute_subnet_cidr = 'ComputeSubnetCidr' ,
140- compute_subnet_id = 'ComputeSubnetId' , use_public_ips = 'UsePublicIps' , ssh_from = 'SSHFrom' )
141+ self .__vpc_options = dict (vpc_id = ('VPCId' ,'VPC' ), master_subnet_id = ('MasterSubnetId' , 'VPCSubnet' ),
142+ compute_subnet_cidr = ('ComputeSubnetCidr' ,None ),
143+ compute_subnet_id = ('ComputeSubnetId' , 'VPCSubnet' ), use_public_ips = ('UsePublicIps' , None ),
144+ ssh_from = ('SSHFrom' , None ))
141145
142146 # Loop over all VPC options and add define to parameters, raise Exception is defined but null
143147 for key in self .__vpc_options :
144148 try :
145149 __temp__ = __config .get (self .__vpc_section , key )
146150 if not __temp__ :
147151 raise Exception
148- self .parameters .append ((self .__vpc_options .get (key ),__temp__ ))
152+ if self .__sanity_check and self .__vpc_options .get (key )[1 ] is not None :
153+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
154+ self .__vpc_options .get (key )[1 ],__temp__ )
155+ self .parameters .append ((self .__vpc_options .get (key )[0 ],__temp__ ))
149156 except ConfigParser .NoOptionError :
150157 pass
151158
152159 # Dictionary list of all cluster section options
153- self .__cluster_options = dict (cluster_user = 'ClusterUser' , compute_instance_type = 'ComputeInstanceType' ,
154- master_instance_type = 'MasterInstanceType' , initial_queue_size = 'InitialQueueSize' ,
155- max_queue_size = 'MaxQueueSize' , maintain_initial_size = 'MaintainInitialSize' ,
156- scheduler = 'Scheduler' , cluster_type = 'ClusterType' , ephemeral_dir = 'EphemeralDir' ,
157- spot_price = 'SpotPrice' , custom_ami = 'CustomAMI' , pre_install = 'PreInstallScript' ,
158- post_install = 'PostInstallScript' , proxy_server = 'ProxyServer' ,
159- placement = 'Placement' , placement_group = 'PlacementGroup' ,
160- encrypted_ephemeral = 'EncryptedEphemeral' ,pre_install_args = 'PreInstallArgs' ,
161- post_install_args = 'PostInstallArgs' , s3_read_resource = 'S3ReadResource' ,
162- s3_read_write_resource = 'S3ReadWriteResource' )
160+ self .__cluster_options = dict (cluster_user = ( 'ClusterUser' , None ), compute_instance_type = ( 'ComputeInstanceType' , None ) ,
161+ master_instance_type = ( 'MasterInstanceType' , None ), initial_queue_size = ( 'InitialQueueSize' , None ) ,
162+ max_queue_size = ( 'MaxQueueSize' ,None ), maintain_initial_size = ( 'MaintainInitialSize' , None ) ,
163+ scheduler = ( 'Scheduler' ,None ), cluster_type = ( 'ClusterType' ,None ), ephemeral_dir = ( 'EphemeralDir' , None ) ,
164+ spot_price = ( 'SpotPrice' ,None ), custom_ami = ( 'CustomAMI' ,'EC2Ami' ), pre_install = ( 'PreInstallScript' , 'URL' ) ,
165+ post_install = ( 'PostInstallScript' ,'URL' ), proxy_server = ( 'ProxyServer' , None ) ,
166+ placement = ( 'Placement' ,None ), placement_group = ( 'PlacementGroup' , 'EC2PlacementGroup' ) ,
167+ encrypted_ephemeral = ( 'EncryptedEphemeral' ,None ), pre_install_args = ( 'PreInstallArgs' , None ) ,
168+ post_install_args = ( 'PostInstallArgs' ,None ), s3_read_resource = ( 'S3ReadResource' , None ) ,
169+ s3_read_write_resource = ( 'S3ReadWriteResource' , None ) )
163170
164171 # Loop over all the cluster options and add define to parameters, raise Exception if defined but null
165172 for key in self .__cluster_options :
166173 try :
167174 __temp__ = __config .get (self .__cluster_section , key )
168175 if not __temp__ :
169176 raise Exception
170- self .parameters .append ((self .__cluster_options .get (key ),__temp__ ))
177+ if self .__sanity_check and self .__cluster_options .get (key )[1 ] is not None :
178+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
179+ self .__cluster_options .get (key )[1 ],__temp__ )
180+ self .parameters .append ((self .__cluster_options .get (key )[0 ],__temp__ ))
171181 except ConfigParser .NoOptionError :
172182 pass
173183
@@ -181,8 +191,9 @@ def __init__(self, args):
181191 pass
182192
183193 # Dictionary list of all EBS options
184- self .__ebs_options = dict (ebs_snapshot_id = 'EBSSnapshotId' , volume_type = 'VolumeType' , volume_size = 'VolumeSize' ,
185- volume_iops = 'VolumeIOPS' , encrypted = 'EBSEncryption' )
194+ self .__ebs_options = dict (ebs_snapshot_id = ('EBSSnapshotId' ,'EC2Snapshot' ), volume_type = ('VolumeType' ,None ),
195+ volume_size = ('VolumeSize' ,None ),
196+ volume_iops = ('VolumeIOPS' ,None ), encrypted = ('EBSEncryption' ,None ))
186197
187198 try :
188199 if self .__ebs_section :
@@ -191,7 +202,10 @@ def __init__(self, args):
191202 __temp__ = __config .get (self .__ebs_section , key )
192203 if not __temp__ :
193204 raise Exception
194- self .parameters .append ((self .__ebs_options .get (key ),__temp__ ))
205+ if self .__sanity_check and self .__ebs_options .get (key )[1 ] is not None :
206+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
207+ self .__ebs_options .get (key )[1 ],__temp__ )
208+ self .parameters .append ((self .__ebs_options .get (key )[0 ],__temp__ ))
195209 except ConfigParser .NoOptionError :
196210 pass
197211 except AttributeError :
@@ -207,8 +221,10 @@ def __init__(self, args):
207221 pass
208222
209223 # Dictionary list of all scaling options
210- self .__scaling_options = dict (scaling_threshold = 'ScalingThreshold' , scaling_period = 'ScalingPeriod' ,
211- scaling_evaluation_periods = 'ScalingEvaluationPeriods' )
224+ self .__scaling_options = dict (scaling_threshold = ('ScalingThreshold' ,None ), scaling_period = ('ScalingPeriod' ,None ),
225+ scaling_evaluation_periods = ('ScalingEvaluationPeriods' ,None ),
226+ scaling_adjustment = ('ScalingAdjustment' ,None ),scaling_adjustment2 = ('ScalingAdjustment2' ,None ),
227+ scaling_cooldonw = ('ScalingCooldown' ,None ),scaling_threshold2 = ('ScalingThreshold2' ,None ))
212228
213229 try :
214230 if self .__scaling_section :
@@ -217,7 +233,10 @@ def __init__(self, args):
217233 __temp__ = __config .get (self .__scaling_section , key )
218234 if not __temp__ :
219235 raise Exception
220- self .parameters .append ((self .__scaling_options .get (key ),__temp__ ))
236+ if self .__sanity_check and self .__scaling_options .get (key )[1 ] is not None :
237+ config_sanity .check_resource (self .region ,self .aws_access_key_id , self .aws_secret_access_key ,
238+ self .__scaling_options .get (key )[1 ],__temp__ )
239+ self .parameters .append ((self .__scaling_options .get (key )[0 ],__temp__ ))
221240 except ConfigParser .NoOptionError :
222241 pass
223242 except AttributeError :
0 commit comments