@@ -42,7 +42,7 @@ def launchInstance():
42
42
43
43
print ("Create Instance with instanceID : {}, type : t2.micro, key-name : {}, security-group : {} ?" .format (imageID , keyname , securityGroup ))
44
44
create = input ("Enter Y to confirm : " )
45
- if create == 'Y' :
45
+ if create == 'Y' or create == 'y' :
46
46
errorInstance = subprocess .call (
47
47
"aws ec2 run-instances --image-id {} --count 1 --instance-type t2.micro --key-name {} --security-groups {} --profile {}" .format (imageID , keyname , securityGroup , profile ))
48
48
if errorInstance == 0 :
@@ -168,19 +168,27 @@ def awsConfigure():
168
168
169
169
def awsMenu ():
170
170
print ('\n ' )
171
- os .system ('aws --version' )
172
-
171
+ error = os .system ('aws --version' )
172
+ print (error )
173
+ if error != 0 :
174
+ print ("No version of AWS CLI found. Would you like to install AWS CLIv2 ? (Press Y to confirm)" )
175
+ install = input ("> " )
176
+ if install == 'y' or install == 'Y' :
177
+ subprocess .call ("msiexec /i https://awscli.amazonaws.com/AWSCLIV2.msi" )
178
+ return
179
+ else :
180
+ return
173
181
while True :
174
182
if not loginAWS :
175
183
awsConfigure ()
176
184
else :
177
185
print ("\n AWS MENU\
178
186
\n --------" )
179
- print ("\n 1. Launch instance \t 2. Show Key-Pairs \t 3. Delete Key-Pair\
180
- \n 4. Show Security-Groups\t 5. Delete Security-Group\t 6. Add Inbound Rules\
181
- \n 7. Show Instances \t 8. Start Instance \t 9. Stop Instance\
182
- \n 10.AWS Configure \t 11.List Profiles \t \
183
- \n \n Press Q to exit" )
187
+ print ("\n 1. Launch instance \t 2. Show Key-Pairs \t 3. Delete Key-Pair\
188
+ \n 4. Show Security-Groups \t 5. Delete Security-Group\t 6. Add Inbound Rules\
189
+ \n 7. Show Instances \t 8. Start Instance \t 9. Stop Instance\
190
+ \n 10.Terminate Instance \t 11.AWS Configure \t 12.List Profiles \
191
+ \n \n Press Q to exit" )
184
192
choice = input ("> " )
185
193
if choice == '1' :
186
194
launchInstance ()
@@ -189,17 +197,19 @@ def awsMenu():
189
197
"aws ec2 describe-key-pairs --profile {}" .format (profile ))
190
198
elif choice == '3' :
191
199
keypair = input ("\n Enter name of key-pair to delete : " )
192
- os .system (
200
+ error = os .system (
193
201
"aws ec2 delete-key-pair --key-name {} --profile {}" .format (keypair , profile ))
194
- print ("Key-Pair : {} deleted." .format (keypair ))
202
+ if error == 0 :
203
+ print ("Key-Pair : {} deleted." .format (keypair ))
195
204
elif choice == '4' :
196
205
os .system (
197
206
"aws ec2 describe-security-groups --profile {}" .format (profile ))
198
207
elif choice == '5' :
199
208
sg = input ("\n Enter name of security-group to delete : " )
200
- os .system (
209
+ error = os .system (
201
210
"aws ec2 delete-security-group --group-name {} --profile {}" .format (sg , profile ))
202
- print ("Security-Group : {} deleted." .format (sg ))
211
+ if error == 0 :
212
+ print ("Security-Group : {} deleted." .format (sg ))
203
213
elif choice == '6' :
204
214
inboundRules ()
205
215
elif choice == '7' :
@@ -208,25 +218,32 @@ def awsMenu():
208
218
instance_id = input ("\n Enter instance-id : " )
209
219
error = subprocess .call ("aws ec2 start-instances --instance-ids {} \
210
220
--profile {}" .format (instance_id , profile ))
211
- if error == '0' :
221
+ if error == 0 :
212
222
print ("Instance started successfully." )
213
223
print ("rc : {}" .format (error ))
214
224
elif choice == '9' :
215
225
instance_id = input ("\n Enter instance-id : " )
216
226
error = subprocess .call ("aws ec2 stop-instances --instance-ids {} \
217
227
--profile {}" .format (instance_id , profile ))
218
- if error == '0' :
228
+ if error == 0 :
219
229
print ("Instance stopped successfully." )
220
230
print ("rc : {}" .format (error ))
221
231
elif choice == '10' :
222
- awsConfigure ()
232
+ instance_id = input ("\n Enter instance-id : " )
233
+ error = subprocess .call ("aws ec2 terminate-instances --instance-ids {} \
234
+ --profile {}" .format (instance_id , profile ))
235
+ if error == 0 :
236
+ print ("Instance termination processed. Instance will be deleted in some time." )
237
+ print ("rc : {}" .format (error ))
223
238
elif choice == '11' :
239
+ awsConfigure ()
240
+ elif choice == '12' :
224
241
os .system ("aws configure list-profiles" )
225
242
elif choice == 'Q' or choice == 'q' :
226
243
print ("Exiting...\n " )
227
244
break
228
245
else :
229
- print ("Invalid choice!!! Choose from 1-11 or Q to exit.\n " )
246
+ print ("Invalid choice!!! Choose from 1-12 or Q to exit.\n " )
230
247
return
231
248
232
249
0 commit comments