]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add API endpoint to set job bandwidth limit
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 15 Aug 2019 15:55:21 +0000 (17:55 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:58 +0000 (15:55 +0100)
gui/baculum/protected/API/Pages/API/JobBandwidthLimit.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/JobBandwidthLimit.php b/gui/baculum/protected/API/Pages/API/JobBandwidthLimit.php
new file mode 100644 (file)
index 0000000..a3ed590
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 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.
+ */
+
+class JobBandwidthLimit extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $job = null;
+               if ($id > 0) {
+                       $job = $this->getModule('job')->getJobById($id);
+               }
+
+               $jobid = null;
+               $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
+               if ($result->exitcode === 0) {
+                       array_shift($result->output);
+                       if(is_object($job) && in_array($job->name, $result->output)) {
+                               $jobid = $job->jobid;
+                       }
+               }
+               if (is_null($jobid)) {
+                       $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
+                       $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+                       return;
+               }
+
+               $limit = property_exists($params, 'limit') && $this->getModule('misc')->isValidInteger($params->limit) ? $params->limit : 0;
+
+               $cmd = array('setbandwidth', 'jobid="' . $jobid . '"', 'limit="' . $limit . '"');
+               $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd);
+               $this->output = $result->output;
+               if ($result->exitcode === 0) {
+                       $this->error = GenericError::ERROR_NO_ERRORS;
+               } else {
+                       $this->error = $result->exitcode;
+               }
+       }
+}
+?>
index 426f066efa073b65afad458db0ddda8a7abc51e6..3a56d361f62869466644a04b2cdc714a79433ae9 100644 (file)
@@ -58,6 +58,7 @@
        <url ServiceParameter="JobResNames" pattern="api/v1/jobs/resnames/" />
        <url ServiceParameter="JobsShow" pattern="api/v1/jobs/show/" />
        <url ServiceParameter="JobShow" pattern="api/v1/jobs/{id}/show/" parameters.id="\d+" />
+       <url ServiceParameter="JobBandwidthLimit" pattern="api/v1/jobs/{id}/bandwidth/" parameters.id="\d+" />
        <url ServiceParameter="JobsRecent" pattern="api/v1/jobs/recent/{name}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="JobEstimate" pattern="api/v1/jobs/estimate/" />
        <url ServiceParameter="JobRun" pattern="api/v1/jobs/run/" />
index 2a9ff4e2f3cfa6a3e0c31f49da6b29ad66e72780..2c4d237c8a0c2e28e91196ab42b7811a5862e4a4 100644 (file)
                        "put": {
                                "tags": ["clients"],
                                "summary": "Set Client bandwidth limit",
-                               "description": "Set Client bandwidth limit in bytesh",
+                               "description": "Set Client bandwidth limit in bytes",
                                "responses": {
                                        "200": {
                                                "description": "Set bandwidth limit output",
                                ]
                        }
                },
+               "/api/v1/jobs/{jobid}/bandwidth": {
+                       "put": {
+                               "tags": ["jobs"],
+                               "summary": "Set Job bandwidth limit",
+                               "description": "Set Job bandwidth limit in bytes",
+                               "responses": {
+                                       "200": {
+                                               "description": "Set bandwidth limit output",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Bandwidth limit setting output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 11, 50, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/JobId"
+                                       },
+                                       {
+                                               "name": "limit",
+                                               "in": "body",
+                                               "required": false,
+                                               "default": 0,
+                                               "description": "Bandwidth limit in bytes",
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       }
+                               ]
+                       }
+               },
                "/api/v1/jobs/resnames": {
                        "get": {
                                "tags": ["jobs"],