From 31e52e8d9f285ff10977199ee8dfd7ee8d6ad62d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 5 Dec 2019 22:52:15 +0000 Subject: [PATCH] Generate DNS configuration for weighted geodns --- bin/mkgeo | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/mkgeo b/bin/mkgeo index 873fbf8..6868af0 100755 --- a/bin/mkgeo +++ b/bin/mkgeo @@ -1,5 +1,7 @@ #!/usr/bin/perl +use v5.12; + use strict; use warnings; @@ -269,6 +271,11 @@ foreach my $cluster (sort { $a->{name} cmp $b->{name} } values %$clusters) my $name = $cluster->{name}; output_server($zonefile, "${name}.${zone}", $cluster); + + if (@{$cluster->{servers}} > 1) + { + output_server($zonefile, "${name}-%02d.${zone}", $cluster); + } } # Output the GeoJSON text @@ -283,6 +290,7 @@ if (defined($gdnsname)) { my $gdnsmapfile = IO::File->new("> gdns/${gdnsname}.map") || die "$!"; my $gdnsresourcefile = IO::File->new("> gdns/${gdnsname}.resource") || die "$!"; + my $gdnsweightedfile = IO::File->new("> gdns/${gdnsname}.weighted") || die "$!"; my $continent = ""; $gdnsmapfile->print("${gdnsname} => {\n"); @@ -323,12 +331,28 @@ if (defined($gdnsname)) { my $name = $cluster->{name}; - $gdnsresourcefile->print(" ${name} => ${name}.tile.openstreetmap.org.\n"); + $gdnsresourcefile->print(" ${name} => ${name}.${zone}.\n"); + + if (@{$cluster->{servers}} > 1) + { + $gdnsweightedfile->print("${name} => {\n"); + + while (my($index,$server) = each @{$cluster->{servers}}) + { + my $number = sprintf("%02d", $index + 1); + my $bandwidth = $server->{bandwidth}; + + $gdnsweightedfile->print(" ${name}-${number} = [ ${name}-${number}.${zone}., ${bandwidth} ]\n"); + } + + $gdnsweightedfile->print("}\n"); + } } $gdnsresourcefile->print(" }\n"); $gdnsresourcefile->print("}\n"); + $gdnsweightedfile->close(); $gdnsresourcefile->close(); $gdnsmapfile->close(); } @@ -489,15 +513,15 @@ sub output_server my $name = shift; my $cluster = shift; - foreach my $server (@{$cluster->{servers}}) + while (my($index,$server) = each @{$cluster->{servers}}) { if ($server->{status} eq "up") { - $zonefile->print("+${name}:$server->{ipv4}:600\n"); + $zonefile->printf("+${name}:$server->{ipv4}:600\n", $index + 1); if ($server->{ipv6}) { -# $zonefile->print("3${name}:$server->{ipv6}:600\n"); +# $zonefile->printf("3${name}:$server->{ipv6}:600\n", $index + 1); } } } -- 2.39.5