-
Notifications
You must be signed in to change notification settings - Fork 7
/
volume_info.go
390 lines (343 loc) · 9.04 KB
/
volume_info.go
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
package main
import (
"fmt"
"log"
"strconv"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/pricing/types"
)
type volumeInfo struct {
name string
minSizeGB int32
maxSizeTB int32
minDurability float64
maxIOPS int32
maxIOPSPerGB int32
maxThroughput int32
Pricing volumePricing
throughputPerMBs float64
throughputFree int32
minIOPS int32
baselineIOPSPerGB int32
iopsBurst int32
bootable bool
}
type piopsPrice struct {
beginRange, endRange int32
pricePerPIOPS float64
}
type tputPrice struct {
beginRange, endRange int32
tputPricePerMBps float64
}
type regionalPricing struct {
piopsPrices []piopsPrice
tputPrices []tputPrice
pricePerGB float64
}
type volumePricing map[string]regionalPricing
var ebsInfo = map[string]volumeInfo{
"gp2": {
name: "gp2",
minSizeGB: 1,
maxSizeTB: 16,
minDurability: 99.8,
maxIOPS: 16000,
maxThroughput: 250,
Pricing: make(volumePricing),
minIOPS: 100,
baselineIOPSPerGB: 3,
iopsBurst: 3000,
bootable: true,
},
"gp3": {
name: "gp3",
minSizeGB: 1,
maxSizeTB: 16,
minDurability: 99.8,
maxIOPS: 16000,
maxThroughput: 1000,
Pricing: make(volumePricing),
throughputPerMBs: 0.04,
throughputFree: 125,
bootable: true,
},
"io1": {
name: "io1",
minSizeGB: 4,
maxSizeTB: 16,
minDurability: 99.8,
maxIOPS: 64000,
maxIOPSPerGB: 50,
maxThroughput: 1000,
Pricing: make(volumePricing),
bootable: true,
},
"io2": {
name: "io2",
minSizeGB: 4,
maxSizeTB: 16,
minDurability: 99.999,
maxIOPS: 64000,
maxIOPSPerGB: 500,
maxThroughput: 1000,
Pricing: make(volumePricing),
bootable: true,
},
"st1": {
name: "st1",
minSizeGB: 125,
maxSizeTB: 16,
minDurability: 99.8,
maxIOPS: 500,
maxThroughput: 250,
Pricing: make(volumePricing),
minIOPS: 100,
baselineIOPSPerGB: 3,
iopsBurst: 3000,
},
"sc1": {
name: "sc1",
minSizeGB: 125,
maxSizeTB: 16,
minDurability: 99.8,
maxIOPS: 250,
maxThroughput: 250,
Pricing: make(volumePricing),
minIOPS: 0,
},
"standard": {
name: "standard",
minSizeGB: 1,
maxSizeTB: 1,
minDurability: 99.8,
maxIOPS: 200,
maxThroughput: 90,
Pricing: make(volumePricing),
minIOPS: 0,
},
}
func populateEBSPricing() error {
log.Println("Fetching EBS pricing data...")
log.Println("Fetching EBS Storage pricing data for all volume types...")
err := populateStoragePricing()
if err != nil {
log.Fatalf("failed to get storage pricing information: %v", err)
}
log.Println("Fetching GP3 pIOPS pricing data...")
err = populateGP3PIOPSPricing()
if err != nil {
log.Fatalf("failed to get GP3 PIOPS pricing information: %v", err)
}
log.Println("Fetching GP3 Throughput pricing data...")
err = populateGP3PThroughputPricing()
if err != nil {
log.Fatalf("failed to get GP3 Throughput pricing information: %v", err)
}
log.Println("Fetching IO1 pIOPS pricing data...")
err = populateIO1IOPSPricing()
if err != nil {
log.Fatalf("failed to get IO1 PIOPS pricing information: %v", err)
}
log.Println("Fetching IO2 pIOPS pricing data...")
err = populateIO2IOPSPricing()
if err != nil {
log.Fatalf("failed to get IO2 PIOPS pricing information: %v", err)
}
return err
}
func populateStoragePricing() error {
var f = []types.Filter{
{
Field: aws.String("ServiceCode"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("AmazonEC2"),
},
{
Field: aws.String("productFamily"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("Storage"),
},
}
pd, err := getPricingData(f)
if err != nil {
return err
}
for _, v := range pd {
volumeType := v.Product.Attributes.VolumeAPIName
region := getRegion(v.Product.Attributes.Location)
pricePerGBStr := v.Terms.OnDemand.SKU.PriceDimensions.Dimension.PricePerUnit.USD
pricePerGB, err := strconv.ParseFloat(pricePerGBStr, 64)
if err != nil {
fmt.Printf("failed to convert %s to float", pricePerGBStr)
}
debug.Printf("%s: %s costs %f \n %#v\n\n", volumeType, region, pricePerGB, v)
ebsInfo[volumeType].Pricing[region] = regionalPricing{
pricePerGB: pricePerGB,
}
}
return nil
}
func populateGP3PIOPSPricing() error {
var f = []types.Filter{
{
Field: aws.String("volumeApiName"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("gp3"),
},
{
Field: aws.String("productFamily"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("System Operation"),
},
}
pd, err := getPricingData(f)
if err != nil {
return err
}
for _, v := range pd {
volumeType := v.Product.Attributes.VolumeAPIName
region := getRegion(v.Product.Attributes.Location)
priceStr := v.Terms.OnDemand.SKU.PriceDimensions.Dimension.PricePerUnit.USD
price, err := strconv.ParseFloat(priceStr, 64)
if err != nil {
fmt.Printf("failed to convert %s to float", priceStr)
}
debug.Printf("%s: %s PIOPS costs %f \n %#v\n\n", volumeType, region, price, v)
pl := ebsInfo[volumeType].Pricing[region]
pl.piopsPrices = append(
pl.piopsPrices, piopsPrice{
beginRange: 3000,
endRange: 16000,
pricePerPIOPS: price,
})
ebsInfo[volumeType].Pricing[region] = pl
}
return nil
}
func populateGP3PThroughputPricing() error {
var f = []types.Filter{
{
Field: aws.String("volumeApiName"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("gp3"),
},
{
Field: aws.String("productFamily"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("Provisioned Throughput"),
},
}
pd, err := getPricingData(f)
if err != nil {
return err
}
for _, v := range pd {
volumeType := v.Product.Attributes.VolumeAPIName
region := getRegion(v.Product.Attributes.Location)
priceStr := v.Terms.OnDemand.SKU.PriceDimensions.Dimension.PricePerUnit.USD
price, err := strconv.ParseFloat(priceStr, 64)
price = price / 1024 // the API returns the value in GBps
if err != nil {
fmt.Printf("failed to convert %s to float", priceStr)
}
debug.Printf("%s: %s Throughput costs %f \n %#v\n\n", volumeType, region, price, v)
pl := ebsInfo[volumeType].Pricing[region]
pl.tputPrices = append(
pl.tputPrices, tputPrice{
beginRange: 125,
endRange: 1000,
tputPricePerMBps: price,
})
ebsInfo[volumeType].Pricing[region] = pl
}
return nil
}
func populateIO1IOPSPricing() error {
var f = []types.Filter{
{
Field: aws.String("volumeApiName"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("io1"),
},
{
Field: aws.String("productFamily"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("System Operation"),
},
}
pd, err := getPricingData(f)
if err != nil {
return err
}
for _, v := range pd {
volumeType := v.Product.Attributes.VolumeAPIName
region := getRegion(v.Product.Attributes.Location)
priceStr := v.Terms.OnDemand.SKU.PriceDimensions.Dimension.PricePerUnit.USD
price, err := strconv.ParseFloat(priceStr, 64)
if err != nil {
fmt.Printf("failed to convert %s to float", priceStr)
}
debug.Printf("%s: %s PIOPS costs %f \n %#v\n\n", volumeType, region, price, v)
pl := ebsInfo[volumeType].Pricing[region]
pl.piopsPrices = append(
pl.piopsPrices, piopsPrice{
beginRange: 0,
endRange: 64000,
pricePerPIOPS: price,
})
ebsInfo[volumeType].Pricing[region] = pl
}
return nil
}
func populateIO2IOPSPricing() error {
var f = []types.Filter{
{
Field: aws.String("volumeApiName"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("io2"),
},
{
Field: aws.String("productFamily"),
Type: types.FilterType("TERM_MATCH"),
Value: aws.String("System Operation"),
},
}
pd, err := getPricingData(f)
if err != nil {
return err
}
for _, v := range pd {
var beginRange, endRange int32
volumeType := v.Product.Attributes.VolumeAPIName
region := getRegion(v.Product.Attributes.Location)
priceStr := v.Terms.OnDemand.SKU.PriceDimensions.Dimension.PricePerUnit.USD
price, err := strconv.ParseFloat(priceStr, 64)
group := v.Product.Attributes.Group
if err != nil {
fmt.Printf("failed to convert %s to float", priceStr)
}
debug.Printf("Processing pricing info for %s in %s PIOPS costs %f \n\n", volumeType, region, price)
debug.Println(v)
pl := ebsInfo[volumeType].Pricing[region]
if group == "EBS IOPS Tier 3" {
beginRange = 64001
endRange = 256000
} else if group == "EBS IOPS Tier 2" {
beginRange = 32001
endRange = 64000
} else if group == "EBS IOPS" {
endRange = 32000
}
p := piopsPrice{
beginRange: beginRange,
endRange: endRange,
pricePerPIOPS: price,
}
debug.Printf("Adding IO2 PIOPS configuration %#+v\n", p)
pl.piopsPrices = append(
pl.piopsPrices, p)
ebsInfo[volumeType].Pricing[region] = pl
}
return nil
}