]> git.openstreetmap.org Git - dns.git/commitdiff
Generate DNS configuration for weighted geodns
authorTom Hughes <tom@compton.nu>
Thu, 5 Dec 2019 22:52:15 +0000 (22:52 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 5 Dec 2019 22:52:15 +0000 (22:52 +0000)
bin/mkgeo

index 873fbf830d834ab89527b9476045fc9afff922b0..6868af07ac7b1b00a04758dc89e892a0b2d9fd3a 100755 (executable)
--- 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);
             }
         }
     }