Skip to content

Commit 5284cec

Browse files
committed
QuotaSet Storage v2 api
1 parent 47a9b54 commit 5284cec

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

src/BlockStorage/v2/Api.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,48 @@ public function putSnapshotMetadata(): array
254254
],
255255
];
256256
}
257+
258+
public function getQuotaSet(): array
259+
{
260+
return [
261+
'method' => 'GET',
262+
'path' => 'os-quota-sets/{tenantId}',
263+
'params' => [
264+
'tenantId' => $this->params->idPath('quota-sets')
265+
]
266+
];
267+
}
268+
269+
public function deleteQuotaSet(): array
270+
{
271+
return [
272+
'method' => 'DELETE',
273+
'path' => 'os-quota-sets/{tenantId}',
274+
'jsonKey' => 'quota_set',
275+
'params' => [
276+
'tenantId' => $this->params->idPath('quota-sets')
277+
]
278+
];
279+
}
280+
281+
public function putQuotaSet(): array
282+
{
283+
return [
284+
'method' => 'PUT',
285+
'path' => 'os-quota-sets/{tenantId}',
286+
'jsonKey' => 'quota_set',
287+
'params' => [
288+
'tenantId' => $this->params->idPath(),
289+
'backupGigabytes' => $this->params->quotaSetBackupGigabytes(),
290+
'backups' => $this->params->quotaSetBackups(),
291+
'gigabytes' => $this->params->quotaSetGigabytes(),
292+
'gigabytesIscsi' => $this->params->quotaSetGigabytesIscsi(),
293+
'perVolumeGigabytes' => $this->params->quotaSetPerVolumeGigabytes(),
294+
'snapshots' => $this->params->quotaSetSnapshots(),
295+
'snapshotsIscsi' => $this->params->quotaSetSnapshotsIscsi(),
296+
'volumes' => $this->params->quotaSetVolumes(),
297+
'volumesIscsi' => $this->params->quotaSetVolumesIscsi(),
298+
]
299+
];
300+
}
257301
}

src/BlockStorage/v2/Params.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,69 @@ public function snapshotName(): array
159159
'location' => self::JSON,
160160
];
161161
}
162+
163+
protected function quotaSetLimit($sentAs, $description): array
164+
{
165+
return [
166+
'type' => self::INT_TYPE,
167+
'location' => self::JSON,
168+
'sentAs' => $sentAs,
169+
'description' => $description,
170+
];
171+
}
172+
173+
public function quotaSetLimitInstances(): array
174+
{
175+
return $this->quotaSetLimit('instances', 'The number of allowed instances for each tenant.');
176+
}
177+
178+
public function quotaSetBackupGigabytes(): array
179+
{
180+
return $this->quotaSetLimit('backup_gigabytes', 'Total size of back-up storage (GiB)');
181+
}
182+
183+
public function quotaSetBackups(): array
184+
{
185+
return $this->quotaSetLimit('backups', 'The number of allowed back-ups');
186+
}
187+
188+
public function quotaSetGigabytes(): array
189+
{
190+
return $this->quotaSetLimit('gigabytes', 'Total Size of Volumes and Snapshots (GiB)');
191+
}
192+
193+
public function quotaSetGigabytesIscsi(): array
194+
{
195+
return $this->quotaSetLimit('gigabytes_iscsi', 'Total Size of Volumes and Snapshots iscsi (GiB)');
196+
}
197+
198+
public function quotaSetTenantId(): array
199+
{
200+
return $this->quotaSetLimit('id', 'Tenant Id');
201+
}
202+
203+
public function quotaSetPerVolumeGigabytes(): array
204+
{
205+
return $this->quotaSetLimit('per_volume_gigabytes', 'Allowed size per Volume (GiB)');
206+
}
207+
208+
public function quotaSetSnapshots(): array
209+
{
210+
return $this->quotaSetLimit('snapshots', 'The number of allowed snapshots');
211+
}
212+
213+
public function quotaSetSnapshotsIscsi(): array
214+
{
215+
return $this->quotaSetLimit('snapshots_iscsi', 'The number of allowed snapshots iscsi');
216+
}
217+
218+
public function quotaSetVolumes(): array
219+
{
220+
return $this->quotaSetLimit('volumes', 'The number of allowed volumes');
221+
}
222+
223+
public function quotaSetVolumesIscsi(): array
224+
{
225+
return $this->quotaSetLimit('volumes_iscsi', 'The number of allowed volumes iscsi');
226+
}
162227
}

src/BlockStorage/v2/Service.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenStack\BlockStorage\v2;
44

5+
use OpenStack\BlockStorage\v2\Models\QuotaSet;
56
use OpenStack\BlockStorage\v2\Models\Snapshot;
67
use OpenStack\BlockStorage\v2\Models\Volume;
78
use OpenStack\BlockStorage\v2\Models\VolumeType;
@@ -111,4 +112,19 @@ public function getSnapshot(string $snapshotId): Snapshot
111112
$snapshot->populateFromArray(['id' => $snapshotId]);
112113
return $snapshot;
113114
}
114-
}
115+
116+
/**
117+
* Shows A Quota for a tenant
118+
*
119+
* @param string $tenantId
120+
*
121+
* @return QuotaSet
122+
*/
123+
public function getQuotaSet(string $tenantId): QuotaSet
124+
{
125+
$quotaSet = $this->model(QuotaSet::class);
126+
$quotaSet->populateFromResponse($this->execute($this->api->getQuotaSet(), ['tenantId' => $tenantId]));
127+
128+
return $quotaSet;
129+
}
130+
}

0 commit comments

Comments
 (0)