From: Marcin Haba Date: Tue, 30 May 2023 10:40:25 +0000 (+0200) Subject: baculum: Add storage resnames endpoint X-Git-Tag: Release-13.0.4~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8ffa226126f21eedb2748291e1c9f6d3075308e;p=thirdparty%2Fbacula.git baculum: Add storage resnames endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/StorageResNames.php b/gui/baculum/protected/API/Pages/API/StorageResNames.php new file mode 100644 index 000000000..34ea6556c --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/StorageResNames.php @@ -0,0 +1,81 @@ + + * @category API + * @package Baculum API + */ +class StorageResNames extends BaculumAPIServer { + public function get() { + $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : 0; + $storages_cmd = ['.storage']; + + $directors = $this->getModule('bconsole')->getDirectors(); + if ($directors->exitcode != 0) { + $this->output = $directors->output; + $this->error = $directors->exitcode; + return; + } + $storages = []; + $error = false; + $error_obj = null; + for ($i = 0; $i < count($directors->output); $i++) { + $storage_list = $this->getModule('bconsole')->bconsoleCommand( + $directors->output[$i], + $storages_cmd, + null, + true + ); + if ($storage_list->exitcode != 0) { + $error_obj = $storage_list; + $error = true; + break; + } + $storages[$directors->output[$i]] = []; + for ($j = 0; $j < count($storage_list->output); $j++) { + if (empty($storage_list->output[$j])) { + continue; + } + $storages[$directors->output[$i]][] = $storage_list->output[$j]; + + // limit per director, not for entire elements + if ($limit > 0 && count($storages[$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 = $storages; + $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 e923977d0..019df1de2 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -30,6 +30,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 44ece1565..dbf6b2845 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -3719,6 +3719,44 @@ ] } }, + "/api/v2/storages/resnames": { + "get": { + "tags": ["storages"], + "summary": "Storage resource names", + "description": "Get storage resource names", + "responses": { + "200": { + "description": "List of storage resource names", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "description": "List storage resource names per director", + "type": "string" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 4, 5, 6, 7, 11, 1000] + } + } + } + } + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/Limit" + } + ] + } + }, "/api/v2/storages/show": { "get": { "tags": ["storages"],