diff --git a/src/Shared/v2/Api.php b/src/Shared/v2/Api.php index dda53032..ab0f9732 100644 --- a/src/Shared/v2/Api.php +++ b/src/Shared/v2/Api.php @@ -226,4 +226,24 @@ public function deleteShareAccessRule(): array ], ]; } + /** + * @link https://docs.openstack.org/api-ref/shared-file-system/?expanded=extend-share-detail#extend-share + * @return array + */ + public function extendShare(): array + { + return [ + 'method' => 'POST', + 'path' => 'shares/{id}/action', + 'jsonKey' => 'extend', + 'params' => [ + 'id' => $this->params->shareIdPath(), + 'new_size' => $this->params->size(), + ], + 'headers' => [ + 'Vary' => 'X-OpenStack-Manila-API-Version', + 'X-Openstack-Manila-Api-Version' => '2.42', + ], + ]; + } } diff --git a/src/Shared/v2/Models/Share.php b/src/Shared/v2/Models/Share.php index 85933114..91d8d882 100644 --- a/src/Shared/v2/Models/Share.php +++ b/src/Shared/v2/Models/Share.php @@ -4,6 +4,7 @@ namespace OpenStack\Shared\v2\Models; +use RuntimeException; use DateTimeImmutable; use OpenStack\Common\Resource\Alias; use OpenStack\Common\Resource\OperatorResource; @@ -159,6 +160,25 @@ public function delete() { $this->executeWithState($this->api->deleteShare()); } + + /** + * @param int $new_size + */ + public function extend(int $new_size) + { + if (is_null($this->size)) { + $this->retrieve(); + } + + if ($new_size < $this->size) { + throw new RuntimeException(sprintf('The new size of the share must be larger than the current size of the share. Current size: %sGB. Requested new size: %sGB', $this->size, $new_size)); + } + + $this->execute($this->api->extendShare(), [ + 'id' => $this->id, + 'new_size' => $new_size, + ]); + } /** * @return array */