summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3/inc/dnbd3.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/dnbd3/inc/dnbd3.inc.php')
-rw-r--r--modules-available/dnbd3/inc/dnbd3.inc.php44
1 files changed, 33 insertions, 11 deletions
diff --git a/modules-available/dnbd3/inc/dnbd3.inc.php b/modules-available/dnbd3/inc/dnbd3.inc.php
index 9607c544..def4e062 100644
--- a/modules-available/dnbd3/inc/dnbd3.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3.inc.php
@@ -4,35 +4,57 @@ class Dnbd3 {
const PROP_ENABLED = 'dnbd3.enabled';
const PROP_NFS_FALLBACK = 'dnbd3.nfs-fallback';
+ const PROP_PREFER_LOCAL = 'dnbd3.prefer-local';
- public static function isEnabled()
+ public static function isEnabled(): bool
{
- return Property::get(self::PROP_ENABLED, 0) ? true : false;
+ return (bool)Property::get(self::PROP_ENABLED, 0);
}
public static function setEnabled($bool)
{
Property::set(self::PROP_ENABLED, $bool ? 1 : 0);
- $task = Taskmanager::submit('Systemctl', array(
- 'operation' => ($bool ? 'start' : 'stop'),
- 'service' => 'dnbd3-server'
- ));
- return $task;
+ Trigger::mount(false, true);
}
- public static function hasNfsFallback()
+ public static function hasNfsFallback(): bool
{
- return Property::get(self::PROP_NFS_FALLBACK, 0) ? true : false;
+ return (bool)Property::get(self::PROP_NFS_FALLBACK, 0);
}
public static function setNfsFallback($bool)
{
Property::set(self::PROP_NFS_FALLBACK, $bool ? 1 : 0);
}
+ public static function preferLocal(): bool
+ {
+ return (bool)Property::get(self::PROP_PREFER_LOCAL, 0);
+ }
- public static function getLocalStatus()
+ public static function setPreferLocal($bool)
{
+ Property::set(self::PROP_PREFER_LOCAL, $bool ? 1 : 0);
+ }
+ public static function getActiveServers(): array
+ {
+ $res = Database::simpleQuery('SELECT s.serverid, m.clientip, s.fixedip
+ FROM dnbd3_server s
+ LEFT JOIN machine m ON (s.machineuuid = m.machineuuid)
+ WHERE s.lastseen > :cutoff', ['cutoff' => CONFIG_DEBUG ? 0 : time() - 310]);
+ $lookup = [];
+ foreach ($res as $row) {
+ $lookup[$row['fixedip'] ?? $row['clientip'] ?? ''] = $row['serverid'];
+ }
+ return $lookup;
+ }
+
+ public static function getServer(string $serverId)
+ {
+ return Database::queryFirst('SELECT s.serverid, IFNULL(s.fixedip, m.clientip) AS clientip
+ FROM dnbd3_server s
+ LEFT JOIN machine m ON (s.machineuuid = m.machineuuid)
+ WHERE s.serverid = :id', ['id' => $serverId]);
}
-} \ No newline at end of file
+}