#!/usr/bin/perl
+use v5.12;
+
use strict;
use warnings;
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
{
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");
- $gdnsmapfile->print(" geoip2_db => /var/lib/GeoIP/GeoLite2-Country.mmdb\n");
+ $gdnsmapfile->print(" geoip2_db => /usr/share/GeoIP/GeoLite2-Country.mmdb\n");
$gdnsmapfile->print(" datacenters => [" . join(",", sort(keys(%$clusters))) . "]\n");
$gdnsmapfile->print(" map => {\n");
$gdnsmapfile->print(" default => [" . join(",", sort(map { $_->{name} } grep { $_->{default} } values(%$clusters))) . "]\n");
{
my $name = $cluster->{name};
- $gdnsresourcefile->print(" ${name} => ${name}.tile.openstreetmap.org.\n");
+ if (@{$cluster->{servers}} > 1)
+ {
+ $gdnsweightedfile->print("${name} => {\n");
+
+ while (my($index,$server) = each @{$cluster->{servers}})
+ {
+ if ($server->{status} eq "up")
+ {
+ my $number = sprintf("%02d", $index + 1);
+ my $bandwidth = $server->{bandwidth};
+
+ $gdnsweightedfile->print(" ${name}-${number} = [ ${name}-${number}.${zone}., ${bandwidth} ]\n");
+ }
+ }
+
+ $gdnsweightedfile->print("}\n");
+
+ $gdnsresourcefile->print(" ${name} => %weighted!${name}\n");
+ }
+ else
+ {
+ $gdnsresourcefile->print(" ${name} => ${name}.${zone}.\n");
+ }
}
$gdnsresourcefile->print(" }\n");
$gdnsresourcefile->print("}\n");
+ $gdnsweightedfile->close();
$gdnsresourcefile->close();
$gdnsmapfile->close();
}
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);
}
}
}