From: Marcin Haba Date: Thu, 15 Aug 2019 15:55:21 +0000 (+0200) Subject: baculum: Add API endpoint to set job bandwidth limit X-Git-Tag: Release-9.6.0~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f767fd7b483a0cd20760810e36a0e13f7abcb13;p=thirdparty%2Fbacula.git baculum: Add API endpoint to set job bandwidth limit --- diff --git a/gui/baculum/protected/API/Pages/API/JobBandwidthLimit.php b/gui/baculum/protected/API/Pages/API/JobBandwidthLimit.php new file mode 100644 index 000000000..a3ed590d4 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/JobBandwidthLimit.php @@ -0,0 +1,57 @@ + 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; + } + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 426f066ef..3a56d361f 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -58,6 +58,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 2a9ff4e2f..2c4d237c8 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -592,7 +592,7 @@ "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", @@ -941,6 +941,54 @@ ] } }, + "/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"],