Skip to content

Commit

Permalink
Merge pull request #30 from Cyclenerd/del-if-no-costs
Browse files Browse the repository at this point in the history
delete instances without price
  • Loading branch information
Cyclenerd authored Sep 21, 2024
2 parents 14aefa7 + e098b70 commit ea7fa4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
36 changes: 11 additions & 25 deletions build/06_add_costs.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl

# Copyright 2022-2023 Nils Knieling. All Rights Reserved.
# 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.
Expand Down Expand Up @@ -146,46 +146,32 @@
###############################################################################
print "\nTest\n";

# Check regions
# Check regions without location
my $sth = $db->prepare("SELECT region FROM instances WHERE regionLocation LIKE '' GROUP BY region");
$sth->execute;
$sth->bind_columns (\my ($region));
my $without_location = 0;
while ($sth->fetch) {
print "ERROR: Location of region '$region' missing!\n";
$without_location++;
}
if ($without_location) {
print "\n";
print "ERROR: Location of region missing! Maybe there is a new region?\n";
print " Please update pricing.yml in Cyclenerd/google-cloud-pricing-cost-calculator.\n";
die "ERROR: Location of region missing!\n";
print "WARNING: Location of region '$region' missing!\n";
my $deleteLocation = "DELETE FROM instances WHERE region LIKE '$region'";
$db->do($deleteLocation) or die "ERROR: Cannot delete instances in unknown location $DBI::errstr\n";
}

# Check costs
# Disks
# Check disks without price
$sth = $db->prepare("SELECT name, region FROM disks WHERE monthGb <= 0");
$sth->execute;
$sth->bind_columns (\my ($name, $region));
while ($sth->fetch) {
print "WARNING: Costs per month missing for disk type '$name' in region '$region'.\n";
}
# Instances

# Chech instances without price
$sth = $db->prepare("SELECT name, region FROM instances WHERE hour <= 0");
$sth->execute;
$sth->bind_columns (\my ($name, $region));
my $without_costs = 0;
while ($sth->fetch) {
print "ERROR: Costs per hour missing for machine type '$name' in region '$region'.\n";
$without_costs++;
print "WARNING: Costs per hour missing for machine type '$name' in region '$region'.\n";
my $deleteInstance = "DELETE FROM instances WHERE name LIKE '$name' AND region LIKE '$region'";
$db->do($deleteInstance) or die "ERROR: Cannot delete instance without price $DBI::errstr\n";
}
# Error
if ($without_costs) {
print "\n";
print "ERROR: Costs missing! Maybe there is a new machine type, disk type or region.\n";
print " Please update pricing.yml in Cyclenerd/google-cloud-pricing-cost-calculator.\n";
die "ERROR: Costs missing!\n";
}


print "DONE\n";
4 changes: 0 additions & 4 deletions instances/clean_up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ DELETE FROM machinetypes WHERE name LIKE 'ct5p-%';

DELETE FROM machinetypes WHERE name LIKE 'x4-%';

/* https://github.com/Cyclenerd/google-cloud-compute-machine-types/issues/27 */
DELETE FROM machinetypes WHERE name LIKE 'a3-megagpu-%' AND region LIKE 'us-central1';
DELETE FROM machinetypes WHERE name LIKE 'a3-megagpu-%' AND region LIKE 'us-west1';

/*
* Delete not yet official 100% finished regions
*/
Expand Down

0 comments on commit ea7fa4c

Please sign in to comment.