]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add storage resnames endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Tue, 30 May 2023 10:40:25 +0000 (12:40 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Jun 2023 11:20:55 +0000 (13:20 +0200)
gui/baculum/protected/API/Pages/API/StorageResNames.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

diff --git a/gui/baculum/protected/API/Pages/API/StorageResNames.php b/gui/baculum/protected/API/Pages/API/StorageResNames.php
new file mode 100644 (file)
index 0000000..34ea655
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\BconsoleError;
+
+/**
+ * Storage resource names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @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;
+               }
+       }
+}
index e923977d06835fb04197de9acc84f079829cc84b..019df1de2c316f8f7087dbdf15fe167e0ef18019 100644 (file)
@@ -30,6 +30,7 @@
        <!-- storages (storage daemons) endpoints -->
        <url ServiceParameter="Storages" pattern="api/v2/storages/" />
        <url ServiceParameter="Storage" pattern="api/v2/storages/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="StorageResNames" pattern="api/v2/storages/resnames/" />
        <url ServiceParameter="StoragesShow" pattern="api/v2/storages/show/" />
        <url ServiceParameter="StorageShow" pattern="api/v2/storages/{id}/show/" parameters.id="\d+" />
        <url ServiceParameter="StorageStatus" pattern="api/v2/storages/{id}/status/" parameters.id="\d+" />
index 44ece156585a11361cfb66f2d654bc45c442b6e4..dbf6b2845ff7179caf1f63caeb8301e78d471977 100644 (file)
                                ]
                        }
                },
+               "/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"],