-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
pricing.pl
1868 lines (1781 loc) · 79 KB
/
pricing.pl
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# Copyright 2022-2024 Nils Knieling. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generate the YAML file with the Google Cloud Platform pricing information
#
BEGIN {
$VERSION = "2.2.1";
}
use strict;
use DBI;
use YAML::XS qw(LoadFile Dump);
use App::Options (
option => {
sku => {
required => 1,
default => 'skus.db',
type => '/^[a-z0-9_]+\.db$/',
description => "SQLite DB file with SKUs and mapping information (read)"
},
gcp => {
required => 1,
default => 'gcp.yml',
type => '/^[a-z0-9_]+\.yml$/',
description => "YAML file with GCP information (read)"
},
export => {
required => 1,
default => 'pricing.yml',
type => '/^[a-z0-9_]+\.yml$/',
description => "YAML file for pricing information export (write)"
},
details => {
required => 0,
default => 0,
type => 'boolean',
description => "Export mapping details"
},
region => {
required => 0,
description => "Export only this region [DEFAULT: All regions]"
},
hours => {
required => 1,
default => '730',
type => '/^\d{1,3}$/',
description => "Hours per month [DEFAULT: 730, same as Google Cloud Pricing Calculator]"
},
sud => {
required => 1,
default => 1,
type => 'boolean',
description => "Add Sustained Use Discount (SUD) [DEFAULT: 1 = yes]"
},
},
);
# Configuration
my $hours_month = $App::options{hours};
my $add_sud = $App::options{sud};
my $export_details = $App::options{details};
# Open YAML file with GCP information for import (gcp.yml)
my $yml_import = $App::options{gcp};
unless (-r "$yml_import") { # read
die "ERROR: Cannot open YAML file '$yml_import' for GCP information import!\n";
}
my $gcp = LoadFile("$yml_import");
# Open YAML file for pricing export (pricing.yml)
my $yml_export = $App::options{export};
open my $fh, q{>}, "$yml_export" or die "ERROR: Cannot open YAML file '$yml_export' for export!\n";
###############################################################################
# HELPER
###############################################################################
sub print_line {
print "-"x80 . "\n";
}
sub print_header {
my ($header) = @_;
&print_line();
print uc($header) . "\n";
&print_line();
}
###############################################################################
# SKUS
###############################################################################
# Open DB file with SKU information for import (skus.db)
my $skus_db = $App::options{sku};
my $dbh = DBI->connect("dbi:SQLite:dbname=$skus_db", "", "") or die "ERROR: Cannot connect to DB $DBI::errstr\n";
###############################################################################
# SEARCH MAPPING
###############################################################################
my $sql_mapping = qq ~
SELECT
NANOS,
UNITS,
UNIT_DESCRIPTION,
SKU_ID,
SKU_DESCRIPTION,
REGIONS
FROM skus
WHERE MAPPING = ?
AND REGIONS LIKE ?
~;
my $sth = $dbh->prepare($sql_mapping);
$sth->bind_columns (\my ($nanos, $units, $unit_description, $sku_id, $sku_description, $regions));
# &mapping_found($mapping, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description)
sub mapping_found {
my ($mapping, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description) = @_;
print "OK: Mapping '$mapping' found in region '$region' found:\n";
print " - regions = '$regions'\n";
print " - value = '$value'\n";
print " - nanos = '$nanos'\n";
print " - units = '$units'\n";
print " - sku_id = '$sku_id'\n";
print " - unit_description = '$unit_description'\n";
print " - sku_description = '$sku_description'\n";
}
# &check_region($region, $regions);
sub check_region {
my ($region, $regions) = @_;
if ($regions =~ /$region$/) {
print "OK: Region '$region' in regions '$regions' found\n";
return 1;
} elsif ($regions =~ /$region,/) {
print "OK: Region '$region' in regions '$regions' found\n";
return 1;
} else {
print "NEXT: '$region' in regions '$regions' not found\n";
return 0;
}
}
# &calc_cost($value, $units, $nanos)
sub calc_cost {
my ($value, $units, $nanos) = @_;
if ($nanos =~ /\,/) {
my @bulk_nanos = split(',', $nanos);
print "INFO: Bulk nanos!\n";
foreach my $i (@bulk_nanos) {
print " * $i\n";
}
$nanos = $bulk_nanos[-1]; # last
}
if ($units =~ /\,/) {
my @bulk_units = split(',', $units);
print "INFO: Bulk units!\n";
foreach my $i (@bulk_units) {
print " * $i\n";
}
$units = $bulk_units[-1]; # last
}
my $cost = $value * ( $units+($nanos*0.000000001) );
print "CALC: cost = $cost, value = $value, units = $units, nanos = $nanos\n";
return $cost;
}
###############################################################################
# REGIONS
###############################################################################
my @regions = keys %{ $gcp->{'region'} };
my @dual_regions = keys %{ $gcp->{'dual-region'} };
my @multi_regions = keys %{ $gcp->{'multi-region'} };
# Export only one region
my $filter_region = $App::options{region} || '';
@regions = ( "$filter_region" ) if ($filter_region);
###############################################################################
# STACKDRIVER MONITORING
###############################################################################
# &add_gcp_monitoring_data_add_cost($usage, $region, $cost)
sub add_gcp_monitoring_data_add_cost {
my ($usage, $region, $cost) = @_;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$usage}->{$region}->{'month'} = $cost;
}
# &add_gcp_monitoring_data_add_details($region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description)
sub add_gcp_monitoring_data_add_details {
my ($region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description) = @_;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'sku'} = $sku_id;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'value'} = $value;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'nanos'} = $nanos;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'units'} = $units;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'unit'} = $unit_description;
$gcp->{'monitoring'}->{'data'}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'description'} = $sku_description;
}
&print_header("Monitoring");
foreach my $region (@regions) {
my $value = 1; # per 1 mebibyte not GB
# Monitoring data
# https://cloud.google.com/monitoring#pricing
my $mapping = 'monitoring.data';
print "MAPPING: '$mapping' in region '$region'\n";
$sth->execute($mapping, 'global'); # Search SKU(s)
if ($sth->fetch) {
&mapping_found($mapping, 'global', $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Bulk price:
# free : 0-150 MiB IGNORED
# $0.2580/MiB: 150–100,000 MiB
# $0.1510/MiB: 100,000–250,000 MiB
# $0.0610/MiB: >250,000 MiB
my @bulk_nanos = split(',', $nanos);
my @bulk_units = split(',', $units);
# last price
my $cost_250000n = &calc_cost($value, $bulk_units[-1], $bulk_nanos[-1]);
my $cost_100000_250000 = $cost_250000n;
my $cost_0_100000 = $cost_250000n;
# overwrite
$cost_100000_250000 = &calc_cost($value, $bulk_units[-2], $bulk_nanos[-2]) if $bulk_nanos[-2];
$cost_0_100000 = &calc_cost($value, $bulk_units[-3], $bulk_nanos[-3]) if $bulk_nanos[-3];
&add_gcp_monitoring_data_add_cost('0-100000', $region, $cost_0_100000);
&add_gcp_monitoring_data_add_cost('100000-250000', $region, $cost_100000_250000);
&add_gcp_monitoring_data_add_cost('250000n', $region, $cost_250000n);
&add_gcp_monitoring_data_add_details(
$region,
$mapping,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
} else {
die "ERROR: '$mapping' (GLOBAL) not found for region '$region'!\n";
}
$sth->finish;
}
###############################################################################
# BUCKET STORAGE GB PER MONTH
###############################################################################
# &add_gcp_storage_bucket_cost($what, $bucket, $region, $cost)
sub add_gcp_storage_bucket_cost {
my ($what, $bucket, $region, $cost) = @_;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{$what} = $cost;
}
# &add_gcp_storage_bucket_details($bucket, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description)
sub add_gcp_storage_bucket_details {
my ($bucket, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description) = @_;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'sku'} = $sku_id;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'value'} = $value;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'nanos'} = $nanos;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'units'} = $units;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'unit'} = $unit_description;
$gcp->{'storage'}->{'bucket'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'description'} = $sku_description;
}
&print_header("Bucket Storage");
foreach my $bucket (keys %{ $gcp->{'storage'}->{'bucket'} }) {
my $value = 1; # 1 GB per month
my @bucket_regions;
# Mapping
# https://cloud.google.com/storage/docs/storage-classes#available_storage_classes
my $mapping;
if ($bucket eq 'standard') { $mapping = 'storage.standard'; @bucket_regions = @regions; }
elsif ($bucket eq 'standard-dual') { $mapping = 'storage.standard.dual'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'standard-multi') { $mapping = 'storage.standard.multi'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'nearline') { $mapping = 'storage.nearline'; @bucket_regions = @regions; }
elsif ($bucket eq 'nearline-dual') { $mapping = 'storage.nearline.dual'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'nearline-multi') { $mapping = 'storage.nearline.multi'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'coldline') { $mapping = 'storage.coldline'; @bucket_regions = @regions; }
elsif ($bucket eq 'coldline-dual') { $mapping = 'storage.coldline.dual'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'coldline-multi') { $mapping = 'storage.coldline.multi'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'archiv') { $mapping = 'storage.archive'; @bucket_regions = @regions; }
elsif ($bucket eq 'archiv-dual') { $mapping = 'storage.archive.dual'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'archiv-multi') { $mapping = 'storage.archive.multi'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'dra') { $mapping = 'storage.dra'; @bucket_regions = @regions; }
elsif ($bucket eq 'dra-dual') { $mapping = 'storage.dra.dual'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'dra-multi') { $mapping = 'storage.dra'; @bucket_regions = @multi_regions; } # Multi and region are the same SKU
# Unknown storage type
else { die "ERROR: No mapping for storage bucket '$bucket'!\n"; }
foreach my $region (@bucket_regions) {
print "Bucket: $bucket\n";
print "MAPPING: '$mapping' in region '$region'\n";
$sth->execute("$mapping", '%'."$region".'%'); # Search SKU(s)
my $found = 0;
while ($sth->fetch) {
if (&check_region($region, $regions)) {
&mapping_found($mapping, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($found) {
die "ERROR: Duplicate entry. Already found price for this mapping '$mapping' in region '$region'!\n"
} else {
$found = 1;
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_storage_bucket_cost('month', $bucket, $region, $cost);
&add_gcp_storage_bucket_details(
$bucket,
$region,
$mapping,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
}
$sth->finish;
unless ($found) {
warn "WARNING: '$mapping' not found in region '$region'!\n";
}
}
}
###############################################################################
# BUCKET DATA RETRIEVAL GB PER MONTH
###############################################################################
# &add_gcp_storage_retrieval_cost($what, $bucket, $region, $cost)
sub add_gcp_storage_retrieval_cost {
my ($what, $bucket, $region, $cost) = @_;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{$what} = $cost;
}
# &add_gcp_storage_retrieval_details($bucket, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description)
sub add_gcp_storage_retrieval_details {
my ($bucket, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description) = @_;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'sku'} = $sku_id;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'value'} = $value;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'nanos'} = $nanos;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'units'} = $units;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'unit'} = $unit_description;
$gcp->{'storage'}->{'retrieval'}->{$bucket}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'description'} = $sku_description;
}
&print_header("Bucket Storage Data Retrieval Fee");
foreach my $bucket (keys %{ $gcp->{'storage'}->{'bucket'} }) {
my $value = 1; # 1 GB per month
my @bucket_regions;
# Mapping
# https://cloud.google.com/storage/docs/storage-classes#available_storage_classes
my $mapping;
if ($bucket eq 'nearline') { $mapping = 'storage.nearline.retrieval'; @bucket_regions = @regions; }
elsif ($bucket eq 'nearline-dual') { $mapping = 'storage.nearline.retrieval'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'nearline-multi') { $mapping = 'storage.nearline.retrieval'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'coldline') { $mapping = 'storage.coldline.retrieval'; @bucket_regions = @regions; }
elsif ($bucket eq 'coldline-dual') { $mapping = 'storage.coldline.retrieval'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'coldline-multi') { $mapping = 'storage.coldline.retrieval'; @bucket_regions = @multi_regions; }
elsif ($bucket eq 'archiv') { $mapping = 'storage.archive.retrieval'; @bucket_regions = @regions; }
elsif ($bucket eq 'archiv-dual') { $mapping = 'storage.archive.retrieval'; @bucket_regions = @dual_regions; }
elsif ($bucket eq 'archiv-multi') { $mapping = 'storage.archive.retrieval'; @bucket_regions = @multi_regions; }
foreach my $region (@bucket_regions) {
print "Bucket: $bucket\n";
print "MAPPING: '$mapping' in region '$region'\n";
$sth->execute($mapping, 'global'); # Search SKU(s)
my $found = 0;
while ($sth->fetch) {
&mapping_found($mapping, 'global', $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($found) {
die "ERROR: Duplicate entry. Already found price for this mapping '$mapping' in region '$region'!\n"
} else {
$found = 1;
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_storage_retrieval_cost('month', $bucket, $region, $cost);
&add_gcp_storage_retrieval_details(
$bucket,
$region,
$mapping,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
$sth->finish;
unless ($found) {
warn "WARNING: '$mapping' not found in region '$region'!\n";
}
}
}
###############################################################################
# DISK STORAGE GB PER MONTH
###############################################################################
# &add_gcp_compute_storage_cost($what, $disk, $region, $cost)
sub add_gcp_compute_storage_cost {
my ($what, $disk, $region, $cost) = @_;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{$what} = $cost;
}
# &add_gcp_compute_storage_details($disk, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description)
sub add_gcp_compute_storage_details {
my ($disk, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description) = @_;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'sku'} = $sku_id;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'value'} = $value;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'nanos'} = $nanos;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'units'} = $units;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'unit'} = $unit_description;
$gcp->{'compute'}->{'storage'}->{$disk}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'description'} = $sku_description;
}
&print_header("Disk Storage");
foreach my $disk (keys %{ $gcp->{'compute'}->{'storage'} }) {
my $value = 1; # 1 GB per month
my @storage_regions = @regions;
# Snapshots can be region or multi region
if ($disk eq 'snapshot') {
push @storage_regions, @multi_regions;
}
foreach my $region (@storage_regions) {
print "Disk: $disk\n";
# Mapping
my $mapping;
# Local SSDs
if ($disk eq 'local') { $mapping = 'gce.storage.ssd.local'; }
# Zonal standard PD
elsif ($disk eq 'hdd') { $mapping = 'gce.storage.hdd'; }
# Zonal SSD PD
elsif ($disk eq 'ssd') { $mapping = 'gce.storage.ssd'; }
# Zonal balanced PD
elsif ($disk eq 'balanced') { $mapping = 'gce.storage.ssd.balanced'; }
# Zonal extreme PD
elsif ($disk eq 'extreme') { $mapping = 'gce.storage.ssd.extreme'; }
# Hyperdisk Extreme
elsif ($disk eq 'hyperdisk-extreme') { $mapping = 'gce.storage.hyperdisk.extreme'; }
# Regional standard PD
elsif ($disk eq 'hdd-replicated') { $mapping = 'gce.storage.hdd.replicated'; }
# Regional SSD PD
elsif ($disk eq 'ssd-replicated') { $mapping = 'gce.storage.ssd.replicated'; }
# Regional balanced PD
elsif ($disk eq 'balanced-replicated') { $mapping = 'gce.storage.ssd.balanced.replicated'; }
# Snapshot
elsif ($disk eq 'snapshot') { $mapping = 'gce.storage.snapshot'; }
# Unknown storage type
else { die "ERROR: No mapping for disk '$disk'!\n"; }
print "MAPPING: '$mapping' in region '$region'\n";
$sth->execute("$mapping", '%'."$region".'%'); # Search SKU(s)
my $found = 0;
while ($sth->fetch) {
if (&check_region($region, $regions)) {
&mapping_found($mapping, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($found) {
die "ERROR: Duplicate entry. Already found price for this mapping '$mapping' in region '$region'!\n";
} else {
$found = 1;
# Bulk price in some regions
# I.e.: 'Storage PD Snapshot'
# https://cloud.google.com/skus/?currency=USD&filter=817F-F5A3-514E
# 0-5 GB = free
# >5 GB = 0.026 USD
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_compute_storage_cost('month', $disk, $region, $cost);
&add_gcp_compute_storage_details(
$disk,
$region,
$mapping,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
}
$sth->finish;
if ($found) {
print "Check 1 Year Commitment:\n";
my $commitment_1y_found = 0;
my $mapping_1y = "$mapping".'.1y';
$sth->execute($mapping_1y, '%'."$region".'%'); # Search SKU(s)
while ($sth->fetch) {
if (&check_region($region, $regions)) {
&mapping_found($mapping_1y, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($commitment_1y_found) {
die "ERROR: Duplicate entry. Already found price for this mapping '$mapping_1y' in region '$region'!\n"
} else {
$commitment_1y_found = 1;
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_compute_storage_cost('month_1y', $disk, $region, $cost);
&add_gcp_compute_storage_details(
$disk,
$region,
$mapping_1y,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
}
$sth->finish;
print "Check 3 Year Commitment:\n";
my $commitment_3y_found = 0;
my $mapping_3y = "$mapping".'.3y';
$sth->execute($mapping_3y, '%'."$region".'%'); # Search SKU(s)
while ($sth->fetch) {
if (&check_region($region, $regions)) {
&mapping_found($mapping_3y, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($commitment_3y_found) {
die "ERROR: Duplicate entry. Already found price for this mapping '$mapping_3y' in region '$region'!\n"
} else {
$commitment_3y_found = 1;
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_compute_storage_cost('month_3y', $disk, $region, $cost);
&add_gcp_compute_storage_details(
$disk,
$region,
$mapping_3y,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
}
$sth->finish;
print "Check Spot:\n";
my $spot_found = 0;
my $mapping_spot = "$mapping".'.spot';
$sth->execute($mapping_spot, '%'."$region".'%'); # Search SKU(s)
while ($sth->fetch) {
if (&check_region($region, $regions)) {
&mapping_found($mapping_spot, $region, $regions, $value, $nanos, $units, $unit_description, $sku_id, $sku_description);
# Check duplicate entries for mapping and region
if ($spot_found) {
die "ERROR: Duplicate entry. Already found spot price for this mapping '$mapping_spot' in region '$region'!\n"
} else {
$mapping_spot = 1;
my $cost = &calc_cost($value, $units, $nanos);
&add_gcp_compute_storage_cost('month_spot', $disk, $region, $cost);
&add_gcp_compute_storage_details(
$disk,
$region,
$mapping_spot,
$sku_id,
$value,
$nanos,
$units,
$unit_description,
$sku_description
) if ($export_details);
}
}
}
$sth->finish;
} else {
warn "WARNING: '$mapping' not found in region '$region'!\n";
}
}
}
###############################################################################
# INSTANCES
###############################################################################
# &add_gcp_compute_instance_cost($what, $machine, $region, $cost)
sub add_gcp_compute_instance_cost {
my ($what, $machine, $region, $cost) = @_;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{$what} = $cost;
}
# &add_gcp_compute_instance_details($machine, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description)
sub add_gcp_compute_instance_details {
my ($machine, $region, $mapping, $sku_id, $value, $nanos, $units, $unit_description, $sku_description) = @_;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'sku'} = $sku_id;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'value'} = $value;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'nanos'} = $nanos;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'units'} = $units;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'unit'} = $unit_description;
$gcp->{'compute'}->{'instance'}->{$machine}->{'cost'}->{$region}->{'mapping'}->{$mapping}->{'description'} = $sku_description;
}
&print_header("Instances");
foreach my $region (@regions) {
foreach my $machine (keys %{ $gcp->{'compute'}->{'instance'} }) {
# Type
my $type = '';
my @machine_name = split('-', $machine);
$type = $machine_name[0];
# Custom Type
if ($gcp->{'compute'}->{'instance'}->{$machine}->{'type'}) {
$type = $gcp->{'compute'}->{'instance'}->{$machine}->{'type'};
}
# CPU and RAM
my $cpu = $gcp->{'compute'}->{'instance'}->{$machine}->{'cpu'} || '0';
my $ram = $gcp->{'compute'}->{'instance'}->{$machine}->{'ram'} || '0';
my $local_ssd = $gcp->{'compute'}->{'instance'}->{$machine}->{'local-ssd'} || '0';
my $a100 = $gcp->{'compute'}->{'instance'}->{$machine}->{'a100'} || '0';
my $a100_80gb = $gcp->{'compute'}->{'instance'}->{$machine}->{'a100-80gb'} || '0';
my $h100_80gb = $gcp->{'compute'}->{'instance'}->{$machine}->{'h100-80gb'} || '0';
my $l4 = $gcp->{'compute'}->{'instance'}->{$machine}->{'l4'} || '0';
print "Machine: $machine\n";
print "Type: $type\n";
# Sustained Use Discount
# https://cloud.google.com/compute/docs/sustained-use-discounts
my %sustained_use_discount = (
1 => 1, # 0%–25%
2 => 1, # 25%–50%
3 => 1, # 50%–75%
4 => 1, # 75%–100%
);
my %sustained_use_discount_n1 = (
1 => 1, # 0%–25% = 100% of base rate
2 => 0.8, # 25%–50% = 80% of base rate
3 => 0.6, # 50%–75% = 60% of base rate
4 => 0.4, # 75%–100% = 40% of base rate
);
my %sustained_use_discount_n2 = (
1 => 1, # 0%–25% = 100% of base rate
2 => 0.8678, # 25%–50% = 86.78% of base rate
3 => 0.733, # 50%–75% = 73.3% of base rate
4 => 0.6, # 75%–100% = 60% of base rate
);
# Mapping
my %mappings;
# Mapping for commitments
# https://cloud.google.com/compute/docs/instances/signing-up-committed-use-discounts#commitment_types
my %mappings_1y;
my %mappings_3y;
# Mapping for Spot VMs
my %mappings_spot;
# Mapping for upgrades without commitments like M2 upgrade but with sustained use discount
my %mapping_upgrades;
# E2 Predefined
if ($type eq 'e2') {
$mappings{ 'gce.compute.cpu.e2'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.e2.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.e2.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.e2.spot'} = $cpu;
$mappings{ 'gce.compute.ram.e2'} = $ram;
$mappings_1y{ 'gce.compute.ram.e2.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.e2.3y'} = $ram;
$mappings_spot{'gce.compute.ram.e2.spot'} = $ram;
}
# F1 Predefined
elsif ($type eq 'f1') {
$mappings{ 'gce.compute.cpu.f1'} = $cpu;
$mappings_spot{'gce.compute.cpu.f1.spot'} = $cpu;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
# RAM incl.
}
# G1 Predefined
elsif ($type eq 'g1') {
$mappings{ 'gce.compute.cpu.g1'} = $cpu;
$mappings_spot{'gce.compute.cpu.g1.spot'} = $cpu;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
# RAM incl.
}
# N1 Predefined
elsif ($type eq 'n1') {
$mappings{ 'gce.compute.cpu.n1'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n1.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n1.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n1.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n1'} = $ram;
$mappings_1y{ 'gce.compute.ram.n1.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n1.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n1.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
}
# N1 Custom
elsif ($type eq 'n1-custom') {
$mappings{ 'gce.compute.cpu.n1.custom'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n1.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n1.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n1.custom.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n1.custom'} = $ram;
$mappings_1y{ 'gce.compute.ram.n1.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n1.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n1.custom.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
}
# N2 Predefined
elsif ($type eq 'n2') {
$mappings{ 'gce.compute.cpu.n2'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n2.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n2.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n2.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n2'} = $ram;
$mappings_1y{ 'gce.compute.ram.n2.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n2.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n2.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n2 if $add_sud;
}
# N2 Custom
elsif ($type eq 'n2-custom') {
$mappings{ 'gce.compute.cpu.n2.custom'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n2.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n2.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n2.custom.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n2.custom'} = $ram;
$mappings_1y{ 'gce.compute.ram.n2.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n2.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n2.custom.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n2 if $add_sud;
}
# N2D Predefined
elsif ($type eq 'n2d') {
$mappings{ 'gce.compute.cpu.n2d'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n2d.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n2d.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n2d.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n2d'} = $ram;
$mappings_1y{ 'gce.compute.ram.n2d.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n2d.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n2d.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n2 if $add_sud;
}
# N2D Custom
elsif ($type eq 'n2d-custom') {
$mappings{ 'gce.compute.cpu.n2d.custom'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n2d.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n2d.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n2d.custom.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n2d.custom'} = $ram;
$mappings_1y{ 'gce.compute.ram.n2d.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n2d.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n2d.custom.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n2 if $add_sud;
}
# N4 Predefined
elsif ($type eq 'n4') {
$mappings{ 'gce.compute.cpu.n4'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n4.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n4.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n4.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n4'} = $ram;
$mappings_1y{ 'gce.compute.ram.n4.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n4.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n4.spot'} = $ram;
}
# N4 Custom
elsif ($type eq 'n4-custom') {
$mappings{ 'gce.compute.cpu.n4.custom'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.n4.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.n4.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.n4.custom.spot'} = $cpu;
$mappings{ 'gce.compute.ram.n4.custom'} = $ram;
$mappings_1y{ 'gce.compute.ram.n4.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.n4.3y'} = $ram;
$mappings_spot{'gce.compute.ram.n4.custom.spot'} = $ram;
}
# T2D Predefined
elsif ($type eq 't2d') {
$mappings{ 'gce.compute.cpu.t2d'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.t2d.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.t2d.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.t2d.spot'} = $cpu;
$mappings{ 'gce.compute.ram.t2d'} = $ram;
$mappings_1y{ 'gce.compute.ram.t2d.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.t2d.3y'} = $ram;
$mappings_spot{'gce.compute.ram.t2d.spot'} = $ram;
}
# T2A Predefined
# The Tau T2A machine series does not support: Committed and Sustained-use discounts
elsif ($type eq 't2a') {
$mappings{ 'gce.compute.cpu.t2a'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.t2a.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.t2a.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.t2a.spot'} = $cpu;
$mappings{ 'gce.compute.ram.t2a'} = $ram;
$mappings_1y{ 'gce.compute.ram.t2a.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.t2a.3y'} = $ram;
$mappings_spot{'gce.compute.ram.t2a.spot'} = $ram;
}
# C2
elsif ($type eq 'c2') {
$mappings{ 'gce.compute.cpu.compute.optimized'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.compute.optimized.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.compute.optimized.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.compute.optimized.spot'} = $cpu;
$mappings{ 'gce.compute.ram.compute.optimized'} = $ram;
$mappings_1y{ 'gce.compute.ram.compute.optimized.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.compute.optimized.3y'} = $ram;
$mappings_spot{'gce.compute.ram.compute.optimized.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n2 if $add_sud;
}
# C2D
elsif ($type eq 'c2d') {
$mappings{ 'gce.compute.cpu.c2d'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.c2d.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.c2d.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.c2d.spot'} = $cpu;
$mappings{ 'gce.compute.ram.c2d'} = $ram;
$mappings_1y{ 'gce.compute.ram.c2d.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.c2d.3y'} = $ram;
$mappings_spot{'gce.compute.ram.c2d.spot'} = $ram;
}
# C3
elsif ($type eq 'c3') {
$mappings{ 'gce.compute.cpu.c3'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.c3.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.c3.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.c3.spot'} = $cpu;
$mappings{ 'gce.compute.ram.c3'} = $ram;
$mappings_1y{ 'gce.compute.ram.c3.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.c3.3y'} = $ram;
$mappings_spot{'gce.compute.ram.c3.spot'} = $ram;
}
# C3D
elsif ($type eq 'c3d') {
$mappings{ 'gce.compute.cpu.c3d'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.c3d.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.c3d.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.c3d.spot'} = $cpu;
$mappings{ 'gce.compute.ram.c3d'} = $ram;
$mappings_1y{ 'gce.compute.ram.c3d.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.c3d.3y'} = $ram;
$mappings_spot{'gce.compute.ram.c3d.spot'} = $ram;
}
# H3
elsif ($type eq 'h3') {
$mappings{ 'gce.compute.cpu.h3'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.h3.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.h3.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.h3.spot'} = $cpu;
$mappings{ 'gce.compute.ram.h3'} = $ram;
$mappings_1y{ 'gce.compute.ram.h3.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.h3.3y'} = $ram;
$mappings_spot{'gce.compute.ram.h3.spot'} = $ram;
}
# Z3
elsif ($type eq 'z3') {
$mappings{ 'gce.compute.cpu.z3'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.z3.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.z3.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.z3.spot'} = $cpu;
$mappings{ 'gce.compute.ram.z3'} = $ram;
$mappings_1y{ 'gce.compute.ram.z3.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.z3.3y'} = $ram;
$mappings_spot{'gce.compute.ram.z3.spot'} = $ram;
}
# M1
elsif ($type eq 'm1') {
$mappings{ 'gce.compute.cpu.memory.optimized'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.memory.optimized.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.memory.optimized.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.memory.optimized.spot'} = $cpu;
$mappings{ 'gce.compute.ram.memory.optimized'} = $ram;
$mappings_1y{ 'gce.compute.ram.memory.optimized.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.memory.optimized.3y'} = $ram;
$mappings_spot{'gce.compute.ram.memory.optimized.spot'} = $ram;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
}
# M2
elsif ($type eq 'm2') {
$mappings{ 'gce.compute.cpu.memory.optimized'} = $cpu;
$mappings_1y{'gce.compute.cpu.memory.optimized.1y'} = $cpu;
$mappings_3y{'gce.compute.cpu.memory.optimized.3y'} = $cpu;
# no spot provisioning mode (Spot VM)
$mappings{ 'gce.compute.ram.memory.optimized'} = $ram;
$mappings_1y{'gce.compute.ram.memory.optimized.1y'} = $ram;
$mappings_3y{'gce.compute.ram.memory.optimized.3y'} = $ram;
# M2 upgrade
$mapping_upgrades{'gce.compute.cpu.memory.optimized.premium.upgrade'} = $cpu;
$mapping_upgrades{'gce.compute.ram.memory.optimized.premium.upgrade'} = $ram;
%sustained_use_discount = %sustained_use_discount_n1 if $add_sud;
}
# M3
elsif ($type eq 'm3') {
$mappings{ 'gce.compute.cpu.m3'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.m3.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.m3.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.m3.spot'} = $cpu;
$mappings{ 'gce.compute.ram.m3'} = $ram;
$mappings_1y{ 'gce.compute.ram.m3.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.m3.3y'} = $ram;
$mappings_spot{'gce.compute.ram.m3.spot'} = $ram;
# M3 machine types do not offer sustained use discounts.
}
# A2
elsif ($type eq 'a2') {
$mappings{ 'gce.compute.cpu.a2'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.a2.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.a2.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.a2.spot'} = $cpu;
$mappings{ 'gce.compute.ram.a2'} = $ram;
$mappings_1y{ 'gce.compute.ram.a2.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.a2.3y'} = $ram;
$mappings_spot{'gce.compute.ram.a2.spot'} = $ram;
# NVIDIA's Ampere A100 40GB GPUs
$mappings{ 'gce.compute.gpu.a100'} = $a100;
$mappings_1y{ 'gce.compute.gpu.a100.1y'} = $a100;
$mappings_3y{ 'gce.compute.gpu.a100.3y'} = $a100;
$mappings_spot{'gce.compute.gpu.a100.spot'} = $a100;
# NVIDIA's Ampere A100 80GB HBM2e GPUs
$mappings{ 'gce.compute.gpu.a100.80gb'} = $a100_80gb;
$mappings_1y{ 'gce.compute.gpu.a100.80gb.1y'} = $a100_80gb;
$mappings_3y{ 'gce.compute.gpu.a100.80gb.3y'} = $a100_80gb;
$mappings_spot{'gce.compute.gpu.a100.80gb.spot'} = $a100_80gb;
}
# A3
elsif ($type eq 'a3') {
$mappings{ 'gce.compute.cpu.a3'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.a3.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.a3.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.a3.spot'} = $cpu;
$mappings{ 'gce.compute.ram.a3'} = $ram;
$mappings_1y{ 'gce.compute.ram.a3.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.a3.3y'} = $ram;
$mappings_spot{'gce.compute.ram.a3.spot'} = $ram;
# NVIDIA's H100 80GB GPUs
$mappings{ 'gce.compute.gpu.h100.80gb'} = $h100_80gb;
$mappings_1y{ 'gce.compute.gpu.h100.80gb.1y'} = $h100_80gb;
$mappings_3y{ 'gce.compute.gpu.h100.80gb.3y'} = $h100_80gb;
$mappings_spot{'gce.compute.gpu.h100.80gb.spot'} = $h100_80gb;
}
# G2
elsif ($type eq 'g2') {
$mappings{ 'gce.compute.cpu.g2'} = $cpu;
$mappings_1y{ 'gce.compute.cpu.g2.1y'} = $cpu;
$mappings_3y{ 'gce.compute.cpu.g2.3y'} = $cpu;
$mappings_spot{'gce.compute.cpu.g2.spot'} = $cpu;
$mappings{ 'gce.compute.ram.g2'} = $ram;
$mappings_1y{ 'gce.compute.ram.g2.1y'} = $ram;
$mappings_3y{ 'gce.compute.ram.g2.3y'} = $ram;
$mappings_spot{'gce.compute.ram.g2.spot'} = $ram;
# NVIDIA's L4 GPUs
$mappings{ 'gce.compute.gpu.l4'} = $l4;
$mappings_1y{ 'gce.compute.gpu.l4.1y'} = $l4;
$mappings_3y{ 'gce.compute.gpu.l4.3y'} = $l4;
$mappings_spot{'gce.compute.gpu.l4.spot'} = $l4;
}
# Unknown family
else {
die "ERROR: No mapping for machine family '$type'!"
}
# Add price for bundled local SSD (local-ssd)
my $costs_local_ssd_month = $gcp->{'compute'}->{'storage'}->{'local'}->{'cost'}->{$region}->{'month'} * $local_ssd || 0;
my $costs_local_ssd_month_1y = $gcp->{'compute'}->{'storage'}->{'local'}->{'cost'}->{$region}->{'month_1y'} * $local_ssd || 0;
my $costs_local_ssd_month_3y = $gcp->{'compute'}->{'storage'}->{'local'}->{'cost'}->{$region}->{'month_3y'} * $local_ssd || 0;
my $costs_local_ssd_month_spot = $gcp->{'compute'}->{'storage'}->{'local'}->{'cost'}->{$region}->{'month_spot'} * $local_ssd || 0;
my $costs_local_ssd_hour = $costs_local_ssd_month / $hours_month || 0;
my $costs_local_ssd_hour_spot = $costs_local_ssd_month_spot / $hours_month || 0;
my $costs = 0;
foreach my $mapping (keys %mappings) {
print "MAPPING: '$mapping' in region '$region'\n";
my $value = $mappings{$mapping} || '0';
$sth->execute("$mapping", '%'."$region".'%'); # Search SKU(s)
my $found = 0;
while ($sth->fetch) {
# asia-northeast1
# Skip SKU for 'Memory-optimized Instance Ram running in Japan', use Tokyo
next if ($sku_id eq '757F-6F9E-CCEC');
# Skip SKU for 'Memory-optimized Instance Core running in Japan', use Tokyo
next if ($sku_id eq '255E-0C41-3813');
# asia-southeast1
# Skip cheaper SKU for 'Memory-optimized Instance Ram running in Singapore'
next if ($sku_id eq '71A5-A7E8-C37C');
# Skip cheaper SKU for 'Memory-optimized Instance Core running in Singapore'
next if ($sku_id eq 'B428-ABC6-FFED');