forked from marcy-terui/gs-aws-pricing-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.gs
98 lines (94 loc) · 3.7 KB
/
ec2.gs
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
function get_ec2_od_price(size, region, os, url) {
var data = eval(getPriceData(url));
var regions = data['config']['regions'];
for (var i = 0; i < regions.length; i++) {
if(regions[i]['region'] == getRiRegion(region)) {
var instypes = regions[i]['instanceTypes'];
for (var j = 0; j < instypes.length; j++) {
sizes = instypes[j]['sizes']
for (var k = 0; k < sizes.length; k++) {
if(sizes[k]['size'] == size) {
var val = sizes[k]['valueColumns'];
for (var k = 0; k < val.length; k++) {
if (val[k]['name'] == os) {
return val[k]['prices']['USD']
}
}
}
}
}
}
}
}
function get_ec2_ri_price(type, region, term, is_hourly, url, purchaseOption) {
return get_ec2_price(type, region, term, is_hourly, url, "purchaseOptions", purchaseOption);
}
function get_ec2_price(type, region, term, is_hourly, url, termType, purchaseOption) {
var data = eval(getPriceData(url));
var regions = data['config']['regions'];
for (var i = 0; i < regions.length; i++) {
if(regions[i]['region'] == getRiRegion(region)) {
var instypes = regions[i]['instanceTypes'];
for (var j = 0; j < instypes.length; j++) {
if(instypes[j]['type'] == type) {
var terms = instypes[j]['terms'];
for (var l = 0; l < terms.length; l++) {
if((terms[l]['term'] == "yrTerm1" && term == 1)
|| (terms[l]['term'] == "yrTerm3" && term == 3)) {
var purchaseOptions = terms[l][termType]
for (var k = 0; k < purchaseOptions.length; k++) {
if (purchaseOptions[k]['purchaseOption'] == purchaseOption) {
if (is_hourly == null) {
return parseFloat(purchaseOptions[k]['prices']['USD']);
}
var valueColumns = purchaseOptions[k]['valueColumns'];
for (var m = 0; m < valueColumns.length; m++) {
if (is_hourly && valueColumns[m]['name'] == "monthlyStar") {
return parseFloat(valueColumns[m]['prices']['USD']) / 730.0;
}
if (!is_hourly && valueColumns[m]['name'] == "upfront") {
return parseFloat(valueColumns[m]['prices']['USD']);
}
}
}
}
}
}
}
}
}
}
}
function get_ec2_old_ri_price(type, region, term, is_hourly, url) {
var data = eval(getPriceData(url));
var regions = data['config']['regions'];
for (var i = 0; i < regions.length; i++) {
if(regions[i]['region'] == getRiRegion(region)) {
var instypes = regions[i]['instanceTypes'];
for (var j = 0; j < instypes.length; j++) {
var sizes = instypes[j]['sizes'];
for (var k = 0; k < sizes.length; k++) {
var valueColumns = sizes[k]['valueColumns'];
var size = sizes[k]['size'];
if(size == type) {
for (var l = 0; l < valueColumns.length; l++) {
var priceName = valueColumns[l]['name'];
if(priceName == "yrTerm1" && term == 1 && !is_hourly) {
return valueColumns[l]['prices']['USD'];
}
if(priceName == "yrTerm1Hourly" && term == 1 && is_hourly) {
return valueColumns[l]['prices']['USD'];
}
if(priceName == "yrTerm3" && term == 3 && !is_hourly) {
return valueColumns[l]['prices']['USD'];
}
if(priceName == "yrTerm3Hourly" && term == 3 && is_hourly) {
return valueColumns[l]['prices']['USD'];
}
}
}
}
}
}
}
}