From: Marcin Haba Date: Fri, 15 Sep 2023 08:20:12 +0000 (+0200) Subject: baculum: Add module for delete command X-Git-Tag: Beta-15.0.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2683925ce1320f9b6224529683166fdea834160;p=thirdparty%2Fbacula.git baculum: Add module for delete command --- diff --git a/gui/baculum/protected/API/Modules/Delete.php b/gui/baculum/protected/API/Modules/Delete.php new file mode 100644 index 000000000..b9902248a --- /dev/null +++ b/gui/baculum/protected/API/Modules/Delete.php @@ -0,0 +1,136 @@ + + * @category Module + * @package Baculum API + */ +class Delete extends APIModule { + + /** + * Bacula catalog resource types. + */ + const TYPE_VOLUME = 'volume'; + const TYPE_POOL = 'pool'; + const TYPE_JOBID = 'jobid'; + const TYPE_SNAPSHOT = 'snapshot'; // not supported yet + const TYPE_CLIENT = 'client'; + const TYPE_TAG = 'tag'; // not supported yet + const TYPE_OBJECT = 'object'; + + /** + * Delete Bacula resources from the catalog. + * + * @param string $director director name + * @param string $type resource type (client, pool, object...etc.) + * @param string $value resource identify value to delete + * @return array output and error code + */ + public function delete($director, $type, $value) { + $result = [ + 'output' => [], + 'error' => BconsoleError::ERROR_NO_ERRORS + ]; + $types = $this->getTypes(); + if (!in_array($type, $types)) { + $result['output'] = BconsoleError::MSG_ERROR_INVALID_PROPERTY; + $result['error'] = BconsoleError::ERROR_INVALID_PROPERTY; + } else { + $cmd = ['delete']; + switch ($type) { + case self::TYPE_JOBID: { + $jobid = (int)$value; + $ret = $this->getModule('bconsole')->bconsoleCommand( + $director, + ['.jobs'], + null, + true + ); + $job = $this->getModule('job')->getJobById($jobid); + if ($ret->exitcode === 0) { + if (is_object($job) && in_array($job->name, $ret->output)) { + $cmd[] = "{$type}=\"{$value}\""; + } else { + $result['output'] = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; + $result['error'] = JobError::ERROR_JOB_DOES_NOT_EXISTS; + } + } else { + $result['output'] = $ret->output; + $result['error'] = $ret->exitcode; + } + break; + } + case self::TYPE_VOLUME: + case self::TYPE_POOL: + case self::TYPE_CLIENT: { + $cmd[] = "{$type}=\"{$value}\""; + break; + } + case self::TYPE_OBJECT: { + $cmd[] = "{$type} objectid=\"{$value}\""; + break; + } + /** Deleting snapshots and tags is not supported by the API so far. **/ + /*case self::TYPE_SNAPSHOT: + case self::TYPE_TAG: { + break; + }*/ + } + if (count($cmd) > 1 && $result['error'] === 0) { + $cmd[] = 'yes'; + $ret = $this->getModule('bconsole')->bconsoleCommand( + $director, + $cmd + ); + $result['output'] = $ret->output; + $result['error'] = $ret->exitcode; + } else { + $result['output'] = BconsoleError::MSG_ERROR_INVALID_PROPERTY; + $result['error'] = BconsoleError::ERROR_INVALID_PROPERTY; + } + } + return $result; + } + + public function getTypes() { + return [ + self::TYPE_VOLUME, + self::TYPE_POOL, + self::TYPE_JOBID, + self::TYPE_SNAPSHOT, + self::TYPE_CLIENT, + self::TYPE_TAG, + self::TYPE_OBJECT + ]; + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/config.xml b/gui/baculum/protected/API/Pages/API/config.xml index 3971e0136..a37b9b0eb 100644 --- a/gui/baculum/protected/API/Pages/API/config.xml +++ b/gui/baculum/protected/API/Pages/API/config.xml @@ -56,6 +56,7 @@ +