From: Marcin Haba Date: Tue, 30 May 2023 10:59:07 +0000 (+0200) Subject: baculum: Add pool resnames endpoint X-Git-Tag: Release-13.0.4~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbe58f84ea2841b2f58ed08225329ab6df95e40d;p=thirdparty%2Fbacula.git baculum: Add pool resnames endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/PoolResNames.php b/gui/baculum/protected/API/Pages/API/PoolResNames.php new file mode 100644 index 000000000..44a3e45a0 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/PoolResNames.php @@ -0,0 +1,81 @@ + + * @category API + * @package Baculum API + */ +class PoolResNames extends BaculumAPIServer { + public function get() { + $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : 0; + $pools_cmd = ['.pool']; + + $directors = $this->getModule('bconsole')->getDirectors(); + if ($directors->exitcode != 0) { + $this->output = $directors->output; + $this->error = $directors->exitcode; + return; + } + $pools = []; + $error = false; + $error_obj = null; + for ($i = 0; $i < count($directors->output); $i++) { + $pool_list = $this->getModule('bconsole')->bconsoleCommand( + $directors->output[$i], + $pools_cmd, + null, + true + ); + if ($pool_list->exitcode != 0) { + $error_obj = $pool_list; + $error = true; + break; + } + $pools[$directors->output[$i]] = []; + for ($j = 0; $j < count($pool_list->output); $j++) { + if (empty($pool_list->output[$j])) { + continue; + } + $pools[$directors->output[$i]][] = $pool_list->output[$j]; + + // limit per director, not for entire elements + if ($limit > 0 && count($pools[$directors->output[$i]]) === $limit) { + break; + } + } + } + if ($error === true) { + $emsg = ' Output => ' . implode(PHP_EOL, $error_obj->output) . 'ExitCode => ' . $error_obj->exitcode; + $this->output = BconsoleError::MSG_ERROR_WRONG_EXITCODE . $emsg; + $this->error = BconsoleError::ERROR_WRONG_EXITCODE; + } else { + $this->output = $pools; + $this->error = BconsoleError::ERROR_NO_ERRORS; + } + } +} diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 019df1de2..400bfbeb5 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -67,6 +67,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index dbf6b2845..ab15479fd 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -3742,7 +3742,7 @@ "error": { "type": "integer", "description": "Error code", - "enum": [0, 1, 4, 5, 6, 7, 11, 1000] + "enum": [0, 1, 4, 5, 6, 7, 9, 11, 1000] } } } @@ -4021,6 +4021,44 @@ }] } }, + "/api/v2/pools/resnames": { + "get": { + "tags": ["pools"], + "summary": "Pool resource names", + "description": "Get pool resource names", + "responses": { + "200": { + "description": "List of pool resource names", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "description": "List pool resource names per director", + "type": "string" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 4, 5, 6, 7, 9, 11, 1000] + } + } + } + } + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/Limit" + } + ] + } + }, "/api/v2/pools/show": { "get": { "tags": ["pools"],