-
Notifications
You must be signed in to change notification settings - Fork 0
/
myaws.15m.py
executable file
·671 lines (560 loc) · 37.3 KB
/
myaws.15m.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /opt/local/bin/python
# -*- coding: utf-8 -*-
#
# <xbar.title>MyAWS</xbar.title>
# <xbar.version>v4.0</xbar.version>
# <xbar.author>pvdabeel@mac.com</xbar.author>
# <xbar.author.github>pvdabeel</xbar.author.github>
# <xbar.desc>Create, connect to and terminate Amazon EC2 virtual machines from the OS X menubar</xbar.desc>
# <xbar.dependencies>python</xbar.dependencies>
#
# Licence: GPL v3
# Installation instructions:
# --------------------------
# Ensure you have the Amazon EC2 CLI installed (see Readme for link)
# Run 'sudo easy_install tinydb awspricing' in Terminal.app
# Ensure you have xbar installed https://github.com/matryer/xbar-plugins
# Copy this file to your xbar plugins folder and chmod +x the file from your terminal in that folder
# Run xbar
import warnings
warnings.filterwarnings("ignore")
aws_owner_id = '615416975922'
aws_key_name = 'pvdabeel@mac.com'
aws_security = 'sg-bce547d1'
aws_command = '/usr/local/bin/aws' # Full path needed
aws_region = 'eu-central-1'
aws_ostype = 'Linux'
vm_cheap = 1
vm_expensive = 2
preferred_currency = 'EUR' # or 'USD' (or any currency supported by currencyconvertor)
aws_vmtypes = [#('t2', [ ('.micro', '( 1 vcpu, 1Gb vram )\t'),
# ('.small', '( 1 vcpu, 2Gb vram )\t'),
# ('.medium', '( 2 vcpu, 4Gb vram )\t'),
# ('.large', '( 2 vcpu, 8Gb vram )\t'),
# ('.xlarge', '( 4 vcpu, 16Gb vram )\t'),
# ('.2xlarge', '( 8 vcpu, 32Gb vram )\t') ]),
#('t3', [ ('.micro', '( 2 vcpu, 1Gb vram )\t'),
# ('.small', '( 2 vcpu, 2Gb vram )\t'),
# ('.medium', '( 2 vcpu, 4Gb vram )\t'),
# ('.large', '( 2 vcpu, 8Gb vram )\t'),
# ('.xlarge', '( 4 vcpu, 16Gb vram )\t'),
# ('.2xlarge', '( 8 vcpu, 32Gb vram )\t') ]),
#('m4', [ ('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
# ('.16xlarge','( 64 vcpu, 256Gb vram )\t') ]),
('m5', [ ('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
('.24xlarge','( 96 vcpu, 384Gb vram )\t') ]),
# ('.metal', '( 96 vcpu, 384Gb vram )\t') ]),
#('m5d',[ ('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
# ('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
# ('.24xlarge','( 96 vcpu, 384Gb vram )\t'),
# ('.metal', '( 96 vcpu, 384Gb vram )\t') ]),
#('m5zn',[('.large', '( 2 vcpu, 8Gb vram )\t'),
# ('.xlarge', '( 4 vcpu, 16Gb vram )\t'),
# ('.2xlarge', '( 8 vcpu, 32Gb vram )\t'),
# ('.3xlarge', '( 12 vcpu, 48Gb vram )\t'),
# ('.6xlarge', '( 24 vcpu, 96Gb vram )\t'),
# ('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
# ('.metal', '( 48 vcpu, 192Gb vram )\t') ]),
('m6i',[ ('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
('.24xlarge','( 96 vcpu, 384Gb vram )\t'),
('.32xlarge','( 128 vcpu, 512Gb vram )\t') ]),
# ('.metal', '( 128 vcpu, 512Gb vram )\t') ]),
#('m6id',[('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
# ('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
# ('.24xlarge','( 96 vcpu, 384Gb vram )\t'),
# ('.32xlarge','( 128 vcpu, 512Gb vram )\t'),
# ('.metal', '( 128 vcpu, 512Gb vram )\t') ]),
('m7i',[ ('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
('.24xlarge','( 96 vcpu, 384Gb vram )\t'),
('.48xlarge','( 192 vcpu, 768Gb vram )\t') ]),
#('m7id',[('.4xlarge', '( 16 vcpu, 64Gb vram )\t'),
# ('.12xlarge','( 48 vcpu, 192Gb vram )\t'),
# ('.24xlarge','( 96 vcpu, 384Gb vram )\t'),
# ('.32xlarge','( 128 vcpu, 512Gb vram )\t'),
# ('.metal', '( 128 vcpu, 512Gb vram )\t') ]),
('c5', [ ('.4xlarge', '( 16 vcpu, 32Gb vram )\t'),
('.9xlarge', '( 36 vcpu, 72Gb vram )\t'),
('.18xlarge','( 72 vcpu, 144Gb vram )\t'),
('.24xlarge','( 96 vcpu, 192Gb vram )\t') ]),
# ('.metal', '( 96 vcpu, 192Gb vram )\t') ]),
#('c5d',[ ('.4xlarge', '( 16 vcpu, 32Gb vram )\t'),
# ('.9xlarge', '( 36 vcpu, 72Gb vram )\t'),
# ('.18xlarge','( 72 vcpu, 144Gb vram )\t'),
# ('.24xlarge','( 96 vcpu, 192Gb vram )\t'),
# ('.metal', '( 96 vcpu, 192Gb vram )\t') ]),
#('c5n',[ ('.4xlarge', '( 16 vcpu, 42Gb vram )\t'),
# ('.9xlarge', '( 36 vcpu, 96Gb vram )\t'),
# ('.18xlarge','( 72 vcpu, 192Gb vram )\t'),
# ('.metal', '( 72 vcpu, 192Gb vram )\t') ]),
('c6i',[ ('.4xlarge', '( 16 vcpu, 32Gb vram )\t'),
('.12xlarge','( 48 vcpu, 96Gb vram )\t'),
('.24xlarge','( 96 vcpu, 192Gb vram )\t'),
('.32xlarge','( 128 vcpu, 256Gb vram )\t') ]),
# ('.metal', '( 128 vcpu, 256Gb vram )\t') ]),
('c7i',[ ('.4xlarge', '( 16 vcpu, 32Gb vram )\t'),
('.12xlarge','( 48 vcpu, 96Gb vram )\t'),
('.24xlarge','( 96 vcpu, 192Gb vram )\t'),
('.48xlarge','( 192 vcpu, 384Gb vram )\t') ]) ]
# ('.metal', '( 128 vcpu, 256Gb vram )\t') ]) ]
#('p3', [ ('.2xlarge', '( 8 vcpu, 61Gb vram )\t'),
# ('.8xlarge', '( 32 vcpu, 244Gb vram )'),
# ('.16xlarge','( 64 vcpu, 488Gb vram )') ]),
#('x1', [ ('.16xlarge','( 64 vcpu, 976Gb vram )\t'),
# ('.32xlarge','( 128 vcpu, 1952Gb vram )') ]),
#('x1e',[ ('.16xlarge','( 64 vcpu, 1952Gb vram )'),
# ('.32xlarge','( 128 vcpu, 3904Gb vram )') ]),
#('u-6tb1',[('.metal', '( 448 vcpu, 6144Gb vram )') ]),
#('z1d',[ ('.2xlarge', '( 8 vcpu, 64Gb vram )\t'),
# ('.3xlarge', '( 12 vcpu, 96Gb vram )\t'),
# ('.6xlarge', '( 24 vcpu, 192Gb vram )\t'),
# ('.12xlarge','( 48 vcpu, 384Gb vram )\t'),
# ('.metal', '( 48 vcpu, 384Gb vram )\t') ]),
#('i3', [ ('.metal', '( 72 core, 512Gb ram )\t') ]),
#('mac1',[('.metal', '( 12 core, 32Gb ram )\t') ]),
#('mac2',[('.metal', '( 8 core, 16Gb ram )\t') ]),
#('mac2-m2',[('.metal', '( 8 core, 24Gb ram )\t') ]) ]
#('mac2-m2pro',[('.metal', '( 12 core, 32Gb ram )\t') ]) ]
aws_default_vmtype_update = 'm7i.12xlarge'
aws_default_vmtype_rebuild = 'm7i.48xlarge'
# Command to be called inside instance to update it
cmd_update = 'update'
cmd_rebuild = 'fullupdate'
# aws ec2 describe-images --owners 615416975922 --query 'Images[*].{ID:ImageId}'
# aws ec2 run-instances --image-id ami-089fc69c2ca496809 --count 1 --ebs-optimized --instance-type t2.micro --key-name gentoo --security-group-ids sg-bce547d1
# aws ec2 describe-instances --query 'Reservations[*].Instances[*].{ID:PublicDnsName,State:State}'
# aws ec2 terminate-instances --instance-ids i-0de69865f64ebd6ad
# aws ec2 stop-instances --instance-ids --force
# aws ec2 describe-instances --instance-id i-0c27fcf159ec94d0d --query 'Reservations[*].Instances[*].LaunchTime'
# aws ec2 get-console-output --instance-id i-0ed95956c74a187ac --output text
# aws ce get-cost-and-usage --time-period Start=2018-09-01,End=2018-09-23 --granularity MONTHLY --metrics BlendedCost UnblendedCost UsageQuantity --group-by Type=DIMENSION,Key=SERVICE
import ast
import json
import sys
import datetime
import calendar
import base64
import math
import time
import os
import subprocess
import requests
import decimal
import awspricing
import six
from datetime import date
from tinydb import TinyDB, Query
from currency_converter import CurrencyConverter
from os.path import expanduser
# Location where to store state files
home = expanduser("~")
state_dir = home+'/.state/myaws'
if not os.path.exists(state_dir):
os.makedirs(state_dir)
# The full path to this file
cmd_path = os.path.realpath(__file__)
# Tiny DB to store pricing
database = TinyDB(state_dir+'/myawspricing.json')
# Cost convertor
converter = CurrencyConverter()
# Nice ANSI colors
CEND = '\33[0m'
CRED = '\33[31m'
CGREEN = '\33[32m'
CYELLOW = '\33[33m'
CBLUE = '\33[36m'
CGRAY = '\33[37m'
CDGRAY = '\33[37m'
# ANSI styles
CBOLD = '\033[01m'
CNORMAL = '\033[00m'
# Support for OS X Dark Mode
DARK_MODE=True if os.getenv('XBARDarkMode','false') == 'true' else False
# Logo for both dark mode and regular mode
def app_print_logo():
print ('|image=iVBORw0KGgoAAAANSUhEUgAAABwAAAAgCAYAAAABtRhCAAAMSmlDQ1BJQ0MgUHJvZmlsZQAASImVVwdUU9nWPrekktACEZASehOkSJcSQosgIFWwEZJAQokhIYjYHYZRcOwiAjZ0VETRsQAyVtSxDoLdsQwWVJRxsGBD5Z0UGM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FxJlR0qSDU21hPRnIFRU7bSxajEVNmi5pPWRgMYEl+BxybLmA0XIDY2UF4ob5XlYgbpp4WYH471NeIFYonqsQ51k6a/iFmjYvEB+m1IQotVA7wb+V36HAD9W2uIZ5gSG1QQq9HzyWK8QsvtJD/pNlBzVs3gqTyeRHEsf5lhhsSwFy8njs/WIducKmpqYFPGwzer2ejhOplaCAUsDU6yBsH3W2zwEnJyd/dnd3X8XuLBgKhaTWgk57gtNFcM6Ygy+ydJBjaxKvrq5+gO2Iw+12R9hXzwOyfX199OL2+Pi4HZ0fmc3mV2traxaqms5LSqAQlEDol8bYxy0tLfP52saC/QM1vti13cK+811ra+u1g4MD2NraAmyAc9rEUxAg6BmCfAi68JsuCOTqcR01S0tL9za/bH7wz/tNHR0d4HA4aH2kG0EeTMiLIHlzcOxZmzOlZ1/yb5xG2rrLs7OzNqwugP3pfey0961Wqwft+8HBwZxWkONUs36/P6efVU34Xwj9AcA/SJ7ZICi/AAAAAElFTkSuQmCC')
print('---')
# Pretty printing
def color_state(state):
if state == 'running':
return CGREEN + justify(state,14) + CEND
if state == 'stopped':
return CRED + justify(state,14) + CEND
if state == 'pending':
return CGREEN + justify('starting',16) + CEND
if state == 'terminated':
return justify('deleted',14)
if state == 'shutting-down':
return CRED + justify('stopping',14) + CEND
if state == 'stopping':
return CRED + justify('stopping',14) + CEND
else:
return state
def color_cost(unconverted_cost,desc,rate):
if preferred_currency == 'USD':
short_rate = '$'
elif preferred_currency == 'EUR':
short_rate = u"€"
else:
short_rate = '$'
if unconverted_cost == 'n/a':
return 'Per hour: '+CGRAY + ' n/a ' + CEND
cost = converter.convert(unconverted_cost,rate,preferred_currency)
if desc == 'Tax':
return CRED + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + '\t ' + CEND + ' - ' + desc
elif desc == 'Total':
return CGREEN + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + '\t ' + CEND + ' - ' + desc
elif desc == 'Hourly':
if (float(cost) < vm_cheap):
return 'Per hour: '+CGREEN + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + ' ' + CEND
if (float(cost) >= vm_cheap) and (float(cost) <= vm_expensive):
return 'Per hour: '+CYELLOW + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + ' ' + CEND
if (float(cost) > vm_expensive ):
return 'Per hour: '+CRED + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + ' ' + CEND
elif desc == '':
return CGREEN + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + '\t ' + CEND
else:
return CBLUE + short_rate + ' ' + justify(str(cost_format(round(float(cost),4))),8) + '\t ' + CEND + ' - ' + desc
def cost_format(x):
digits = 4
temp = str(decimal.Decimal(str(x) + '0' * digits))
return temp[:temp.find('.') + digits + 1]
def justify(string):
return justify(string,10)
def justify(string,number):
length = len(string)
quot = (number - length ) // 4
rem = (number - length ) % 4
return string.ljust(length+rem,' ').ljust(length+rem+quot,'\t')
def important(string):
return CRED + string + CEND
# The init function: Called to store your AWS access keys
def init():
print ('Please run \'aws configure\'')
# The update-pricing function: Retrieve EC2 pricing
def update_pricing():
# Purge existing database
database.purge()
# Get an EC2 price list from amazon
ec2_offer = awspricing.offer('AmazonEC2')
# Retrieve latest pricing for vm and insert in database
for (aws_vmgroup,aws_vmtypelist) in aws_vmtypes:
for (aws_vmtype,aws_vmdesc) in aws_vmtypelist:
try:
# DB format change (bug in awspricing) aws_pricing = ec2_offer.ondemand_hourly(aws_vmgroup+aws_vmtype,operating_system=aws_ostype,region=aws_region)
# Ondemand makes a distinction between Used, ReservationBox, ...
sku = ec2_offer.search_skus(instance_type=aws_vmgroup+aws_vmtype,operating_system=aws_ostype,tenancy='Shared',location='EU (Frankfurt)',licenseModel='No License required', preInstalledSw='NA',capacitystatus='Used').pop()
print (ec2_offer._offer_data[sku]['terms']['OnDemand'])
aws_pricing = next(six.itervalues(next(six.itervalues(ec2_offer._offer_data[sku]['terms']['OnDemand']))['priceDimensions']))['pricePerUnit']['USD']
print (aws_pricing)
except:
aws_pricing = 'n/a'
pass
database.insert({'type':aws_vmgroup+aws_vmtype,'pricing':aws_pricing})
# Store timestamp
database.insert({'timestamp':str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M'))})
# The update-image function: Update an EC2 image
def update_image(cmd=cmd_update):
if (len(sys.argv) != 4):
print ('Please provide an ami name and ami snapshot id as argument')
return
ami_to_update = sys.argv[2]
ami_snap_id = sys.argv[3]
print ('')
print (CYELLOW+CBOLD+'>>> Updating image: '+CNORMAL+CGREEN+ami_to_update+CEND)
print ('')
if (cmd == cmd_update):
aws_default_vmtype = aws_default_vmtype_update
else:
aws_default_vmtype = aws_default_vmtype_rebuild
# for the given AMI image, spawn an instance
print ('--- Deploying instance: '+CGREEN+aws_default_vmtype+CEND)
try:
instance_id = json.loads(subprocess.check_output(aws_command+" ec2 run-instances --image-id "+ami_to_update+" --instance-type "+aws_default_vmtype+" --ebs-optimized --key-name "+aws_key_name+" --security-group-ids "+aws_security, shell=True))['Instances'][0]['InstanceId']
except:
print (CRED+'!!! Failed to deploy instance'+CEND)
return
print ('--- Instance deployed: '+CGREEN+instance_id+CEND)
# wait until instance is up and running
print ('--- Checking instance: ', end=""),
try:
subprocess.check_output(aws_command+" ec2 wait instance-running --instance-ids "+instance_id, shell=True)
print (CGREEN+'running'+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Instance failed to reach running state'+CEND)
# Destroy instance
json.loads(subprocess.check_output(aws_command+" ec2 terminate-instances --instance-ids "+instance_id, shell=True))
return
print ('--- Instance dnsname: ', end=""),
try:
instance_dns = json.loads(subprocess.check_output(aws_command+" ec2 describe-instances --instance-ids "+instance_id+" --query 'Reservations[*].Instances[*].{PublicDnsName:PublicDnsName,State:State}'", shell=True))[0][0]['PublicDnsName']
print (CGREEN+instance_dns+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Failed to get instance dnsname'+CEND)
# Destroy instance
json.loads(subprocess.check_output(aws_command+" ec2 terminate-instances --instance-ids "+instance_id, shell=True))
return
# execute update
print ('--- Updating instance:', end="")
print ('')
try:
updateoutcome = subprocess.call("sleep 60 && ssh -q -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/amazon-vms root@"+instance_dns+ " \"bash -icl "+cmd+"\"", shell=True)
print ('')
except:
print (CRED+'!!! Failed to update instance'+CEND)
# Destroy instance
json.loads(subprocess.check_output(aws_command+" ec2 terminate-instances --instance-ids "+instance_id, shell=True))
print ('')
return
if (updateoutcome):
print (CRED+'!!! Failed to update instance'+CEND)
json.loads(subprocess.check_output(aws_command+" ec2 terminate-instances --instance-ids "+instance_id, shell=True))
print ('')
return
# create new image
print ('--- Creating new image: ', end="")
try:
updated_ami = json.loads(subprocess.check_output(aws_command+" ec2 create-image --instance-id "+instance_id+" --name Linux-"+time.strftime("%Y%m%d-%Hh%M"), shell=True))
print (CGREEN+'ok'+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Failed to create image'+CEND)
# wait until image is available
print ('--- Checking new image: ', end="")
try:
subprocess.check_output(aws_command+" ec2 wait image-available --owners self", shell=True)
print (CGREEN+'available'+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Image failed to reach available state'+CEND)
return
# Cleanup instance
print ('--- Cleanup instance: ', end="")
try:
json.loads(subprocess.check_output(aws_command+" ec2 terminate-instances --instance-ids "+instance_id, shell=True))
print (CGREEN+'ok'+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Instance cleanup failed'+CEND)
# Cleanup old image
print ('--- Cleanup old image: ', end="")
try:
subprocess.check_output(aws_command+" ec2 deregister-image --image-id "+ami_to_update+" && "+aws_command+" ec2 delete-snapshot --snapshot-id "+ami_snap_id, shell=True)
print (CGREEN+'ok'+CEND)
except:
print (CRED+'failed'+CEND)
print (CRED+'!!! Image cleanup failed'+CEND)
print ('')
print (CYELLOW+CBOLD+'>>> New image created'+CNORMAL+CEND)
print ('')
return
# The main function
def main(argv):
# CASE 1a: init was called
if 'init' in argv:
init()
return
# CASE 1b: update_pricing was called
if 'update_pricing' in argv:
update_pricing()
return
# CASE 1c: update-image was called
if 'update_image' in argv:
update_image(cmd_update)
return
# CASE 1d:
if 'rebuild_image' in argv:
update_image(cmd_rebuild)
return
# CASE 2: nor init nor update were called, AWS not available
if bool(DARK_MODE):
color = '#FFFFFE'
info_color = '#C0C0C0'
else:
color = '#00000E'
info_color = '#616161'
# CASE 3a: no internet connection
try:
requests.get('http://www.google.com',timeout=2)
except:
app_print_logo()
print ('No internet connection | refresh=true terminal=false shell="%s" param1="%s" color=%s' % (cmd_path, 'true', color))
return
try:
todayDate = datetime.date.today()
monthDate = todayDate.replace(day=1)
if (todayDate == monthDate):
monthDate = monthDate - datetime.timedelta(days=1)
monthDate = monthDate.replace(day=1)
images = json.loads(subprocess.check_output(aws_command+" ec2 describe-images --owners "+aws_owner_id+" --query 'Images[*].{ImageId:ImageId,Name:Name,SnapshotId:BlockDeviceMappings[0].Ebs.SnapshotId}'", shell=True))
instances = json.loads(subprocess.check_output(aws_command+" ec2 describe-instances --query 'Reservations[*].Instances[*].{PublicDnsName:PublicDnsName,State:State,InstanceType:InstanceType,PublicIpAddress:PublicIpAddress,InstanceId:InstanceId,ImageId:ImageId,LaunchTime:LaunchTime}'", shell=True))
volumes = json.loads(subprocess.check_output(aws_command+" ec2 describe-volumes --query 'Volumes[*].{Size:Size}'", shell=True))
snapshots = json.loads(subprocess.check_output(aws_command+" ec2 describe-snapshots --owner-ids "+aws_owner_id+" --query 'Snapshots[*].{Size:VolumeSize}'", shell=True))
try:
with open(state_dir+'/myaws-costs-monthly'+todayDate.strftime("%Y%m%d")+'.json') as json_file:
monthly_cost = json.load(json_file)
json_file.close()
except:
with open(state_dir+'/myaws-costs-monthly'+todayDate.strftime("%Y%m%d")+'.json','w') as json_file:
monthly_cost = json.loads(subprocess.check_output(aws_command+" ce get-cost-and-usage --time-period Start="+monthDate.strftime("%Y-%m-%d")+",End="+todayDate.strftime("%Y-%m-%d")+" --granularity MONTHLY --metrics BlendedCost --group-by Type=DIMENSION,Key=SERVICE", shell=True))
json.dump(monthly_cost,json_file)
json_file.close()
try:
with open(state_dir+'/myaws-costs-daily'+todayDate.strftime("%Y%m%d")+'.json') as json_file:
daily_cost = json.load(json_file)
json_file.close()
except:
with open(state_dir+'/myaws-costs-daily'+todayDate.strftime("%Y%m%d")+'.json','w') as json_file:
daily_cost = json.loads(subprocess.check_output(aws_command+" ce get-cost-and-usage --time-period Start="+monthDate.strftime("%Y-%m-%d")+",End="+todayDate.strftime("%Y-%m-%d")+" --granularity DAILY --metrics BlendedCost --group-by Type=DIMENSION,Key=SERVICE", shell=True))
json.dump(daily_cost,json_file)
json_file.close()
except:
app_print_logo()
print ('Failed to get data from EC2 | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (cmd_path, 'init', color))
return
# CASE 3b: all ok, all other cases
app_print_logo()
prefix = ''
# -------------------
# image menu
# -------------------
# loop through images, list all instances and print menu for creating new vm from image
for image in images:
current_image_id = image['ImageId']
current_image_snapshot_id = image['SnapshotId']
# create a submenu for every AMI which whose underlying storage is ready
if (current_image_snapshot_id):
print ('%sImage :\t\t\t\t %s | color=%s' % (prefix, image['Name'], color))
prefix = '--'
else:
print ('%sImage :\t\t\t\t %s | color=%s' % (prefix, image['Name'], info_color))
continue
# print menu with relevant info and actions
print ('%sDeploy new Virtual Machine | color=%s' % (prefix, color))
aws_pricing = 'n/a'
for (aws_vmgroup,aws_vmtypelist) in aws_vmtypes:
for (aws_vmtype,aws_vmdesc) in aws_vmtypelist:
Q = Query()
try:
aws_pricing = database.search(Q.type==aws_vmgroup+aws_vmtype)[0]['pricing']
except:
aws_pricing = 'n/a'
pass
print ('%s--%16s\t%30s\t%s | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, justify(aws_vmgroup+aws_vmtype,17), justify(aws_vmdesc,30), color_cost(aws_pricing,'Hourly','USD'), aws_command, "ec2 run-instances --image-id "+current_image_id+" --instance-type "+aws_vmgroup+aws_vmtype+" --ebs-optimized --key-name "+aws_key_name+" --security-group-ids "+aws_security, color))
print ('%s-----' % prefix)
db_last_updated = False
try:
Q = Query()
db_last_updated = database.search(Q.timestamp != 'null')[0]['timestamp']
print ('%s--Last updated:\t\t %s | color=%s' % (prefix, db_last_updated, color))
print ('%s----%s | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, 'Update AWS pricing',cmd_path, "update_pricing", color))
except:
print ('%s--%s | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, important('Update AWS pricing'),cmd_path, "update_pricing", color))
print ('%s---' % prefix)
# loop through instances,
image_instance_list = []
for instance in instances:
instance_json=instance[0]
current_instance_id = instance_json['InstanceId']
if instance_json['ImageId'] == current_image_id:
image_instance_list.append(current_instance_id)
state = instance_json['State']['Name']
dnsname = instance_json['PublicDnsName']
vmtype = instance_json['InstanceType']
ipaddress = instance_json['PublicIpAddress']
launchtime = datetime.datetime.strptime(instance_json['LaunchTime'][:19],'%Y-%m-%dT%H:%M:%S')
uptime = datetime.datetime.utcnow() - launchtime
uptime_d = divmod(uptime.total_seconds(),86400)
uptime_h = divmod(uptime_d[1], 3600)
uptime_m = divmod(uptime_h[1], 60)
print ('%s%14s %02dd : %02dh : %02dm\t%s ip: %s ' % (prefix, color_state(state), int(uptime_d[0]),int(uptime_h[0]),int(uptime_m[0]), justify(vmtype,24), ipaddress ))
if state == 'running':
print ('%s--Connect | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, "ssh", "-q -o StrictHostKeyChecking=no -o UserKnownHostsFile=~/.ssh/amazon-vms root@"+dnsname, color))
if state == 'stopped':
print ('%s--Start | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 start-instances --instance-ids "+current_instance_id, color))
print ('%s--Create image | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 create-image --instance-id "+current_instance_id+" --name Linux-"+time.strftime("%Y%m%d-%Hh%M"), color))
if state == 'running':
print ('%s--Stop | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 stop-instances --instance-ids "+current_instance_id+" --force", color))
if (state == 'running') or (state == 'stopped'):
print ('%s--Terminate | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 terminate-instances --instance-ids "+current_instance_id, color))
if state == 'running':
print ('%s-----' % (prefix))
print ('%s--Screenshot| color=%s' % (prefix, color))
try:
console = json.loads(subprocess.check_output(aws_command+" ec2 get-console-screenshot --instance-id "+current_instance_id, shell=True))['ImageData']
print ('%s----|image="%s" | color=%s' % (prefix, console, color))
except:
print ('%s----|Unable to get a screenshot | color=%s' % (prefix, color))
if state != 'terminated':
print ('%s-----' % (prefix))
print ('%s--Serial Console Log| refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, "cat", state_dir+"/myaws-"+current_instance_id+".console.log", color))
with open(state_dir+"/myaws-"+current_instance_id+".console.log",'w') as console_file:
serial = str(subprocess.check_output(aws_command+" ec2 get-console-output --output text --instance-id "+current_instance_id, shell=True))
console_file.write(serial)
console_file.close()
if len(image_instance_list) > 0:
print ('%s---' % prefix)
print ('%sTerminate all Virtual Machines | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 terminate-instances --instance-ids "+" ".join(image_instance_list), color))
print ('%s---' % prefix)
print ('%sImage' % prefix)
print ('%s--Update | refresh=true terminal=true shell="%s" param1="%s" param2="%s" param3="%s" color=%s' % (prefix, cmd_path, "update_image", current_image_id, current_image_snapshot_id, color))
print ('%s--Rebuild | refresh=true terminal=true shell="%s" param1="%s" param2="%s" param3="%s" color=%s' % (prefix, cmd_path, "rebuild_image", current_image_id, current_image_snapshot_id, color))
if (len(images) > 1):
print ('%s--Destroy | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 deregister-image --image-id "+current_image_id + " && "+aws_command+" ec2 delete-snapshot --snapshot-id "+current_image_snapshot_id, color))
else:
print ('%s--Destroy | refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 deregister-image --image-id "+current_image_id + " --dry-run && "+aws_command+" ec2 delete-snapshot --dry-run --snapshot-id "+current_image_snapshot_id, info_color))
print ('%s--Destroy | alternate=true refresh=true terminal=true shell="%s" param1="%s" color=%s' % (prefix, aws_command, "ec2 deregister-image --image-id "+current_image_id + " --dry-run && "+aws_command+" ec2 delete-snapshot --snapshot-id "+current_image_snapshot_id, color))
prefix = ''
# -------------------
# storage menu
# -------------------
print ('---')
my_volumes = 0
my_volumes_consumption = 0
my_snapshots = 0
my_snapshots_consumption = 0
for volume in volumes:
my_volumes += 1
my_volumes_consumption += volume['Size']
for snapshot in snapshots:
my_snapshots +=1
my_snapshots_consumption += snapshot['Size']
print ('Volumes: \t\t\t %s objects, %s Gb total | color=%s' % (my_volumes, my_volumes_consumption, info_color))
print ('Snapshots:\t\t\t %s objects, %s Gb total | color=%s' % (my_snapshots, my_snapshots_consumption, info_color))
# -------------------
# cost and usage menu
# -------------------
# monthly
print ('---')
totalcost = 0
for group in monthly_cost['ResultsByTime'][0]['Groups']:
totalcost += float(group['Metrics']['BlendedCost']['Amount'])
print ('Cost this month:\t\t %s | color=%s' % (color_cost(totalcost,'','USD'),color))
for group in monthly_cost['ResultsByTime'][0]['Groups']:
if group['Keys'][0] == 'Tax':
print('-----')
print ('--%s | color=%s' % (color_cost(group['Metrics']['BlendedCost']['Amount'],group['Keys'][0],group['Metrics']['BlendedCost']['Unit']),color))
print ('-----')
print ('--%s | color=%s' % (color_cost(totalcost,'Total','USD'),color))
totalcost = 0
# daily
dailycost = 0
for day in daily_cost['ResultsByTime']:
for group in day['Groups']:
dailycost += float(group['Metrics']['BlendedCost']['Amount'])
print ('----%s : %s | color=%s' % (day['TimePeriod']['Start'],color_cost(dailycost,'','USD'),color))
for group in day['Groups']:
if group['Keys'][0] == 'Tax':
print('---------')
print ('------%s | color=%s' % (color_cost(group['Metrics']['BlendedCost']['Amount'],group['Keys'][0],group['Metrics']['BlendedCost']['Unit']),color))
print ('---------')
print ('------%s | color=%s' % (color_cost(dailycost,'Total','USD'),color))
dailycost = 0
def run_script(script):
return subprocess.Popen([script], stdout=subprocess.PIPE, shell=True).communicate()[0].strip()
if __name__ == '__main__':
main(sys.argv)