diff options
author | Simon Rettberg | 2019-05-23 10:42:25 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-05-23 10:42:25 +0200 |
commit | 3dc6e2162eac1836f4d0a23e480b08cd50a961c7 (patch) | |
tree | ac31cfa3a5fc49ba36b197dbf930c019185e1e9b | |
parent | [locations] subnet inputs: disabled -> readonly; disable save button (diff) | |
download | slx-admin-3dc6e2162eac1836f4d0a23e480b08cd50a961c7.tar.gz slx-admin-3dc6e2162eac1836f4d0a23e480b08cd50a961c7.tar.xz slx-admin-3dc6e2162eac1836f4d0a23e480b08cd50a961c7.zip |
[dnbd3] Put proxies from other locations into SLX_DNBD3_FALLBACK
-rw-r--r-- | modules-available/dnbd3/baseconfig/getconfig.inc.php | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/modules-available/dnbd3/baseconfig/getconfig.inc.php b/modules-available/dnbd3/baseconfig/getconfig.inc.php index fe1bef17..6f484fc5 100644 --- a/modules-available/dnbd3/baseconfig/getconfig.inc.php +++ b/modules-available/dnbd3/baseconfig/getconfig.inc.php @@ -21,12 +21,12 @@ if ($locations === false) { $res = Database::simpleQuery('SELECT s.fixedip, m.clientip, sxl.locationid FROM dnbd3_server s LEFT JOIN machine m USING (machineuuid) - LEFT JOIN dnbd3_server_x_location sxl USING (serverid) - WHERE sxl.locationid IS NULL OR sxl.locationid IN (:lids)', array('lids' => $locationIds)); + LEFT JOIN dnbd3_server_x_location sxl USING (serverid)'); // Lookup of priority - first index (0) will be closest location in chain // low value is higher priority $locationsAssoc = array_flip($locationIds); $servers = array(); +$fallback = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { if ($row['fixedip'] === '<self>') { $row['fixedip'] = Property::getServerIp(); @@ -35,7 +35,14 @@ while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $defPrio = 1000; } $ip = $row['fixedip'] ? $row['fixedip'] : $row['clientip']; + // See if this server is meant for the client at all + if (!is_null($row['locationid']) && !isset($locationsAssoc[$row['locationid']])) { + $fallback[$ip] = true; + continue; + } + // Server allowed for client if ($defPrio === 1000 && is_null($row['locationid'])) { + // Server is not assigned to this location, try to guess it by its IP address $serverLoc = Location::getFromIp($ip); if ($serverLoc !== false) { $row['locationid'] = $serverLoc; @@ -43,12 +50,17 @@ while ($row = $res->fetch(PDO::FETCH_ASSOC)) { } $old = isset($servers[$ip]) ? $servers[$ip] : $defPrio; if (is_null($row['locationid']) || !isset($locationsAssoc[$row['locationid']])) { - $servers[$ip] = min($defPrio, $old) . '.' . mt_rand(); + $servers[$ip] = min($defPrio . '.' . mt_rand(), $old); } else { - $servers[$ip] = min($locationsAssoc[$row['locationid']], $old) . '.' . mt_rand(); + $servers[$ip] = min($locationsAssoc[$row['locationid']] . '.' . mt_rand(), $old); } } +foreach ($servers as $k => $v) { + unset($fallback[$k]); +} + asort($servers, SORT_NUMERIC | SORT_ASC); ConfigHolder::add('SLX_DNBD3_SERVERS', implode(' ', array_keys($servers))); +ConfigHolder::add('SLX_DNBD3_FALLBACK', implode(' ', array_keys($fallback))); ConfigHolder::add('SLX_VM_DNBD3', 'yes'); |