]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add pool resnames endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Tue, 30 May 2023 10:59:07 +0000 (12:59 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Jun 2023 11:20:55 +0000 (13:20 +0200)
gui/baculum/protected/API/Pages/API/PoolResNames.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/PoolResNames.php b/gui/baculum/protected/API/Pages/API/PoolResNames.php
new file mode 100644 (file)
index 0000000..44a3e45
--- /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;
+
+/**
+ * Pool resource names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @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;
+               }
+       }
+}
index 019df1de2c316f8f7087dbdf15fe167e0ef18019..400bfbeb55c182481cae7977bcf200f6f888d57c 100644 (file)
@@ -67,6 +67,7 @@
        <url ServiceParameter="VolumesInPool" pattern="api/v2/pools/{id}/volumes/" parameters.id="\d+" />
        <url ServiceParameter="PoolUpdate" pattern="api/v2/pools/{id}/update/" parameters.id="\d+" />
        <url ServiceParameter="PoolUpdateVolumes" pattern="api/v2/pools/{id}/update/volumes/" parameters.id="\d+" />
+       <url ServiceParameter="PoolResNames" pattern="api/v2/pools/resnames/" />
        <url ServiceParameter="PoolsShow" pattern="api/v2/pools/show/" />
        <url ServiceParameter="PoolShow" pattern="api/v2/pools/{id}/show/" parameters.id="\d+" />
        <!-- jobs endpoints-->
index dbf6b2845ff7179caf1f63caeb8301e78d471977..ab15479fddbbb9bfe98f06cba948448478f42b4d 100644 (file)
                                                                                "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]
                                                                                }
                                                                        }
                                                                }
                                }]
                        }
                },
+               "/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"],