From b48fd7e9ca7ecb07dc1d1dd75da28278e2101d67 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sun, 27 Jun 2021 18:05:52 +0200 Subject: [PATCH] baculum: Add to API deleting volume from the catalog --- .../protected/API/Pages/API/Volume.php | 25 +++++++++++++ .../protected/API/openapi_baculum.json | 36 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/gui/baculum/protected/API/Pages/API/Volume.php b/gui/baculum/protected/API/Pages/API/Volume.php index bc00c62bc..5ce86db50 100644 --- a/gui/baculum/protected/API/Pages/API/Volume.php +++ b/gui/baculum/protected/API/Pages/API/Volume.php @@ -89,6 +89,31 @@ class Volume extends BaculumAPIServer { $this->error = VolumeError::ERROR_VOLUME_DOES_NOT_EXISTS; } } + + public function remove() { + $mediaid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; + $volume = $this->getModule('volume')->getVolumeById($mediaid); + if (is_object($volume)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + [ + 'delete', + 'volume="' . $volume->volumename . '"', + 'yes' + ] + ); + if ($result->exitcode === 0) { + $this->output = $result->output; + $this->error = VolumeError::ERROR_NO_ERRORS; + } else { + $this->output = $result->output; + $this->error = VolumeError::ERROR_WRONG_EXITCODE; + } + } else { + $this->output = VolumeError::MSG_ERROR_VOLUME_DOES_NOT_EXISTS; + $this->error = VolumeError::ERROR_VOLUME_DOES_NOT_EXISTS; + } + } } ?> diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index ba18c4195..7b66e6867 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -2723,6 +2723,42 @@ } } ] + }, + "delete": { + "tags": ["volumes"], + "summary": "Delete volume by MediaId", + "description": "Delete volume from the Catalog by specific Volume/Media identifier.", + "responses": { + "200": { + "description": "Volume delete output", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "type": "string", + "description": "Delete volume output" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 2, 3, 4, 5, 6, 7, 11, 30, 1000] + } + } + } + } + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/MediaId" + } + ] } }, "/api/v2/volumes/{mediaid}/prune": { -- 2.47.3