From e098b70015294dfd97bf8079b15135f65da0717b Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 21 Sep 2024 13:12:32 +0200 Subject: [PATCH] delete instances without price --- build/06_add_costs.pl | 36 +++++++++++------------------------- instances/clean_up.sql | 4 ---- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/build/06_add_costs.pl b/build/06_add_costs.pl index 356101737..fd5d33315 100644 --- a/build/06_add_costs.pl +++ b/build/06_add_costs.pl @@ -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. @@ -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"; diff --git a/instances/clean_up.sql b/instances/clean_up.sql index 5e14d052a..16cd8ba0c 100644 --- a/instances/clean_up.sql +++ b/instances/clean_up.sql @@ -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 */