Skip to content

Commit

Permalink
Added the option to extend shares
Browse files Browse the repository at this point in the history
  • Loading branch information
skipworkgh committed Feb 25, 2020
1 parent c779067 commit 05a63e5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Shared/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
}
}
20 changes: 20 additions & 0 deletions src/Shared/v2/Models/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OpenStack\Shared\v2\Models;

use RuntimeException;
use DateTimeImmutable;
use OpenStack\Common\Resource\Alias;
use OpenStack\Common\Resource\OperatorResource;
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 05a63e5

Please sign in to comment.