From 72e9ba141f5c82d71800f502f1c40028ffafb5b6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 9 Sep 2019 11:47:27 +0200 Subject: [dnbd3] proxy view: Show cache-map when clicking percentage of image Requires up to date DNBD3-Server --- modules-available/dnbd3/inc/dnbd3rpc.inc.php | 44 +++++++++++++++++++--------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'modules-available/dnbd3/inc/dnbd3rpc.inc.php') diff --git a/modules-available/dnbd3/inc/dnbd3rpc.inc.php b/modules-available/dnbd3/inc/dnbd3rpc.inc.php index 6ed43254..6e7480c0 100644 --- a/modules-available/dnbd3/inc/dnbd3rpc.inc.php +++ b/modules-available/dnbd3/inc/dnbd3rpc.inc.php @@ -6,20 +6,7 @@ class Dnbd3Rpc { const QUERY_NOT_200 = 2; const QUERY_NOT_JSON = 3; - /** - * Query given DNBD3 server for status information. - * - * @param string $server server address - * @param int $port server port - * @param bool $stats include general stats - * @param bool $clients include client list - * @param bool $images include image list - * @param bool $diskSpace include disk space stats - * @param bool $config get config - * @param bool $altservers list of alt servers with status - * @return int|array the queried data as an array, or false on error - */ - public static function query($server, $stats, $clients, $images, $diskSpace = false, $config = false, $altservers = false) + private static function translateServer($server) { // Special case - local server if ($server === '') { @@ -36,6 +23,24 @@ class Dnbd3Rpc { $server .= ':5003'; } } + return $server; + } + + /** + * Query given DNBD3 server for status information. + * + * @param string $server server address + * @param bool $stats include general stats + * @param bool $clients include client list + * @param bool $images include image list + * @param bool $diskSpace include disk space stats + * @param bool $config get config + * @param bool $altservers list of alt servers with status + * @return int|array the queried data as an array, or false on error + */ + public static function query($server, $stats, $clients, $images, $diskSpace = false, $config = false, $altservers = false) + { + $server = self::translateServer($server); $url = 'http://' . $server . '/query?'; if ($stats) { $url .= 'q=stats&'; @@ -66,4 +71,15 @@ class Dnbd3Rpc { return $ret; } + public static function getCacheMap($server, $imgId) + { + $server = self::translateServer($server); + $str = Download::asString('http://' . $server . '/cachemap?id=' . $imgId, 3, $code); + if ($str === false) + return self::QUERY_UNREACHABLE; + if ($code !== 200) + return self::QUERY_NOT_200; + return $str; + } + } -- cgit v1.2.3-55-g7522