X-Git-Url: https://git.openstreetmap.org/dns.git/blobdiff_plain/e32ab0cf0f3494dee6121cfe7335b56250b84dcc..e8d2cbde2ca6c6fb1a2867342132c5d7b93a5bd9:/bin/mkgeo diff --git a/bin/mkgeo b/bin/mkgeo index 33a05b0..4dceb1d 100755 --- a/bin/mkgeo +++ b/bin/mkgeo @@ -105,11 +105,22 @@ if ($ENV{PINGDOM_USERNAME} && $ENV{PINGDOM_PASSWORD}) } } +# Create target origins object +my $targetorigins = {}; + # Initialise cluster details while (my($name,$cluster) = each %$clusters) { $cluster->{bandwidth_limit} = $cluster->{bandwidth} * 1024 * 1024; $cluster->{bandwidth_used} = 0; + + $targetorigins->{$cluster->{name}} = { + code => $cluster->{name}, + name => $cluster->{name}, + lat => $cluster->{lat}, + lon => $cluster->{lon}, + bandwidth => 0 + }; } my @mappings = (); @@ -162,9 +173,6 @@ while (grep { !exists($_->{cluster}) } values %$origins) # Create JSON collection object my @json; -# Create target origins object -my $targetorigins = {}; - # Open output files my $zonefile = IO::File->new("> data/${zone}") || die "$!"; my $jsonfile = IO::File->new("> json/${zone}.json") || die "$!"; @@ -203,17 +211,6 @@ foreach my $origin (values %$origins) } }; - unless (exists($targetorigins->{$cluster->{name}})) - { - $targetorigins->{$cluster->{name}} = { - code => $cluster->{name}, - name => $cluster->{name}, - lat => $cluster->{lat}, - lon => $cluster->{lon}, - bandwidth => 0 - }; - } - $targetorigins->{$cluster->{name}}->{bandwidth} += $origin->{bandwidth}; } @@ -225,11 +222,11 @@ while (my($name,$cluster) = each %$clusters) { if (my $default = $cluster->{default}) { - $zonefile->print("C${default}.${zone}:${name}.${zone}:600\n"); + output_server($zonefile, "${default}.${zone}", $cluster); } elsif (exists($cluster->{default})) { - $zonefile->print("C${zone}:${name}.${zone}:600\n"); + output_server($zonefile, "${zone}", $cluster); } } @@ -239,18 +236,7 @@ $zonefile->print("# Servers\n"); # Output A records for each cluster while (my($name,$cluster) = each %$clusters) { - foreach my $server (@{$cluster->{servers}}) - { - if ($server->{status} eq "up") - { - $zonefile->print("+${name}.${zone}:$server->{ipv4}:600\n"); - - if ($server->{ipv6}) - { -# $zonefile->print("3${name}.${zone}:$server->{ipv6}:600\n"); - } - } - } + output_server($zonefile, "${name}.${zone}", $cluster); } # Output the GeoJSON text @@ -394,3 +380,28 @@ sub compare_bandwidth return $a_used <=> $b_used; } + +# +# Output DNS records for a server +# +sub output_server +{ + my $zonefile = shift; + my $name = shift; + my $cluster = shift; + + foreach my $server (@{$cluster->{servers}}) + { + if ($server->{status} eq "up") + { + $zonefile->print("+${name}:$server->{ipv4}:3600\n"); + + if ($server->{ipv6}) + { +# $zonefile->print("3${name}:$server->{ipv6}:3600\n"); + } + } + } + + return; +}